1 use ExtUtils::MakeMaker;
11 unlink "Errno.pm" if -f "Errno.pm";
12 open OUT, ">Errno.pm" or die "Cannot open Errno.pm: $!";
15 foreach $file (get_files()) {
19 unlink "errno.c" if -f "errno.c";
24 return unless defined $file;
27 if (($^O eq 'VMS') && ($Config{vms_cc_type} ne 'gnuc')) {
28 unless(open(FH," LIBRARY/EXTRACT=ERRNO/OUTPUT=SYS\$OUTPUT $file |")) {
29 warn "Cannot open '$file'";
33 unless(open(FH,"< $file")) {
34 # This file could be a temporay file created by cppstdin
35 # so only warn under -w, and return
36 warn "Cannot open '$file'" if $^W;
42 if /^\s*#\s*define\s+(E\w+)\s+/;
49 # VMS keeps its include files in system libraries (well, except for Gcc)
51 if ($Config{vms_cc_type} eq 'decc') {
52 $file{'Sys$Library:DECC$RTLDEF.TLB'} = 1;
53 } elsif ($Config{vms_cc_type} eq 'vaxc') {
54 $file{'Sys$Library:vaxcdef.tlb'} = 1;
55 } elsif ($Config{vms_cc_type} eq 'gcc') {
56 $file{'gnu_cc_include:[000000]errno.h'} = 1;
58 } elsif ($^O eq 'os390') {
59 # OS/390 C compiler doesn't generate #file or #line directives
60 $file{'/usr/include/errno.h'} = 1;
61 } elsif ($^O eq 'vmesa') {
62 # OS/390 C compiler doesn't generate #file or #line directives
63 $file{'../../vmesa/errno.h'} = 1;
65 open(CPPI,"> errno.c") or
66 die "Cannot open errno.c";
68 print CPPI "#include <errno.h>\n";
72 # invoke CPP and read the output
73 if ($^O eq 'MSWin32') {
74 open(CPPO,"$Config{cpprun} $Config{cppflags} errno.c |") or
75 die "Cannot run '$Config{cpprun} $Config{cppflags} errno.c'";
77 my $cpp = "$Config{cppstdin} $Config{cppflags} $Config{cppminus}";
78 open(CPPO,"$cpp < errno.c |") or
79 die "Cannot exec $cpp";
83 if ($^O eq 'MSWin32' and $Config{cc} =~ /^bcc/i) {
84 $pat = '^/\*\s+(.+)\s+\d+\s*:\s+\*/';
87 $pat = '^#(?:line)?\s*\d+\s+"([^"]+)"';
98 $file{$1} = 1 if /$pat/o;
109 # create the CPP input
111 open(CPPI,"> errno.c") or
112 die "Cannot open errno.c";
114 print CPPI "#include <errno.h>\n";
116 foreach $err (keys %err) {
117 print CPPI '"',$err,'" [[',$err,']]',"\n";
122 # invoke CPP and read the output
125 my $cpp = "$Config{cppstdin} $Config{cppflags} $Config{cppminus}";
126 $cpp =~ s/sys\$input//i;
127 open(CPPO,"$cpp errno.c |") or
128 die "Cannot exec $Config{cppstdin}";
129 } elsif ($^O eq 'MSWin32') {
130 open(CPPO,"$Config{cpprun} $Config{cppflags} errno.c |") or
131 die "Cannot run '$Config{cpprun} $Config{cppflags} errno.c'";
133 my $cpp = "$Config{cppstdin} $Config{cppflags} $Config{cppminus}";
134 open(CPPO,"$cpp < errno.c |")
135 or die "Cannot exec $cpp";
142 next unless ($name, $expr) = /"(.*?)"\s*\[\s*\[\s*(.*?)\s*\]\s*\]/;
143 next if $name eq $expr;
144 $err{$name} = eval $expr;
152 # This file is auto-generated. ***ANY*** changes here will be lost
156 use vars qw(\@EXPORT_OK \%EXPORT_TAGS \@ISA \$VERSION \%errno \$AUTOLOAD);
161 \$Config{'myarchname'} eq "$Config{'myarchname'}" or
162 die "Errno architecture ($Config{'myarchname'}) does not match executable architecture (\$Config{'myarchname'})";
164 \$VERSION = "$VERSION";
165 \@ISA = qw(Exporter);
170 my @err = sort { $err{$a} <=> $err{$b} } keys %err;
171 map { $len = length if length > $len } @err;
173 my $j = "\@EXPORT_OK = qw(" . join(" ",keys %err) . ");\n";
174 $j =~ s/(.{50,70})\s/$1\n\t/g;
182 my $k = join(" ", grep { exists $err{$_} }
183 qw(E2BIG EACCES EADDRINUSE EADDRNOTAVAIL EAFNOSUPPORT
184 EAGAIN EALREADY EBADF EBUSY ECHILD ECONNABORTED
185 ECONNREFUSED ECONNRESET EDEADLK EDESTADDRREQ EDOM EDQUOT
186 EEXIST EFAULT EFBIG EHOSTDOWN EHOSTUNREACH EINPROGRESS
187 EINTR EINVAL EIO EISCONN EISDIR ELOOP EMFILE EMLINK
188 EMSGSIZE ENAMETOOLONG ENETDOWN ENETRESET ENETUNREACH
189 ENFILE ENOBUFS ENODEV ENOENT ENOEXEC ENOLCK ENOMEM
190 ENOPROTOOPT ENOSPC ENOSYS ENOTBLK ENOTCONN ENOTDIR
191 ENOTEMPTY ENOTSOCK ENOTTY ENXIO EOPNOTSUPP EPERM
192 EPFNOSUPPORT EPIPE EPROCLIM EPROTONOSUPPORT EPROTOTYPE
193 ERANGE EREMOTE ERESTART EROFS ESHUTDOWN ESOCKTNOSUPPORT
194 ESPIPE ESRCH ESTALE ETIMEDOUT ETOOMANYREFS ETXTBSY
195 EUSERS EWOULDBLOCK EXDEV));
197 $k =~ s/(.{50,70})\s/$1\n\t/g;
198 print "\t",$k,"\n )]\n);\n\n";
200 foreach $err (@err) {
201 printf "sub %s () { %d }\n",,$err,$err{$err};
206 sub TIEHASH { bless [] }
209 my ($self, $errname) = @_;
210 my $proto = prototype("Errno::$errname");
211 if (defined($proto) && $proto eq "") {
213 return $! == &$errname;
216 Carp::confess("No errno $errname");
221 Carp::confess("ERRNO hash is read only!");
229 while(($k,$v) = each %Errno::) {
230 my $proto = prototype("Errno::$k");
231 last if (defined($proto) && $proto eq "");
238 my $s = scalar keys %Errno::;
243 my ($self, $errname) = @_;
244 my $proto = prototype($errname);
245 defined($proto) && $proto eq "";
255 Errno - System errno constants
259 use Errno qw(EINTR EIO :POSIX);
263 C<Errno> defines and conditionally exports all the error constants
264 defined in your system C<errno.h> include file. It has a single export
265 tag, C<:POSIX>, which will export all POSIX defined error numbers.
267 C<Errno> also makes C<%!> magic such that each element of C<%!> has a non-zero
268 value only if C<$!> is set to that value, eg
272 unless (open(FH, "/fangorn/spouse")) {
274 warn "Get a wife!\n";
276 warn "This path is barred: $!";
282 Graham Barr <gbarr@pobox.com>
286 Copyright (c) 1997-8 Graham Barr. All rights reserved.
287 This program is free software; you can redistribute it and/or modify it
288 under the same terms as Perl itself.