1 use ExtUtils::MakeMaker;
5 our $VERSION = "1.09_00";
10 unlink "Errno.pm" if -f "Errno.pm";
11 open OUT, ">Errno.pm" or die "Cannot open Errno.pm: $!";
14 foreach $file (get_files()) {
18 unlink "errno.c" if -f "errno.c";
23 return unless defined $file and -f $file;
24 # warn "Processing $file\n";
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'";
32 } elsif ($Config{gccversion} ne ''
33 # OpenSTEP has gcc 2.7.2.1 which recognizes but
34 # doesn't implement the -dM flag.
35 && $^O ne 'openstep' && $^O ne 'next' && $^O ne 'darwin'
37 # With the -dM option, gcc outputs every #define it finds
38 unless(open(FH,"$Config{cc} -E -dM $Config{cppflags} $file |")) {
39 warn "Cannot open '$file'";
43 unless(open(FH,"< $file")) {
44 # This file could be a temporary file created by cppstdin
45 # so only warn under -w, and return
46 warn "Cannot open '$file'" if $^W;
54 if /^\s*#\s*define\s+(E\w+)\s+(\d+)/;
59 if /^\s*#\s*define\s+(E\w+)\s+/;
60 if ($^O eq 'MSWin32') {
62 if /^\s*#\s*define\s+WSA(E\w+)\s+/;
72 unless (defined $cppstdin) {
74 $cppstdin = $Config{cppstdin};
75 my $upup_cppstdin = File::Spec->catfile(File::Spec->updir,
78 my $cppstdin_is_wrapper =
79 ($cppstdin eq 'cppstdin'
81 and -x $upup_cppstdin);
82 $cppstdin = $upup_cppstdin if $cppstdin_is_wrapper;
84 return "$cppstdin $Config{cppflags} $Config{cppminus}";
89 # VMS keeps its include files in system libraries (well, except for Gcc)
91 if ($Config{vms_cc_type} eq 'decc') {
92 $file{'Sys$Library:DECC$RTLDEF.TLB'} = 1;
93 } elsif ($Config{vms_cc_type} eq 'vaxc') {
94 $file{'Sys$Library:vaxcdef.tlb'} = 1;
95 } elsif ($Config{vms_cc_type} eq 'gcc') {
96 $file{'gnu_cc_include:[000000]errno.h'} = 1;
98 } elsif ($^O eq 'os390') {
99 # OS/390 C compiler doesn't generate #file or #line directives
100 $file{'/usr/include/errno.h'} = 1;
101 } elsif ($^O eq 'vmesa') {
102 # OS/390 C compiler doesn't generate #file or #line directives
103 $file{'../../vmesa/errno.h'} = 1;
104 } elsif ($Config{archname} eq 'epoc') {
105 # Watch out for cross compiling for EPOC (usually done on linux)
106 $file{'/usr/local/epocemx/epocsdk/include/libc/sys/errno.h'} = 1;
107 } elsif ($^O eq 'linux' &&
108 $Config{gccversion} ne '' # might be using, say, Intel's icc
110 # Some Linuxes have weird errno.hs which generate
111 # no #file or #line directives
112 my $linux_errno_h = -e '/usr/include/errno.h' ?
113 '/usr/include/errno.h' : '/usr/local/include/errno.h';
114 $file{$linux_errno_h} = 1;
115 } elsif ($^O eq 'MacOS') {
116 # note that we are only getting the GUSI errno's here ...
117 # we might miss out on compiler-specific ones
118 $file{"$ENV{GUSI}include:sys:errno.h"} = 1;
120 } elsif ($^O eq 'beos') {
121 # hidden in a special place
122 $file{'/boot/develop/headers/posix/errno.h'} = 1;
124 } elsif ($^O eq 'vos') {
125 # avoid problem where cpp returns non-POSIX pathnames
126 $file{'/system/include_library/errno.h'} = 1;
128 open(CPPI,"> errno.c") or
129 die "Cannot open errno.c";
131 if ($^O eq 'NetWare') {
132 print CPPI "#include <nwerrno.h>\n";
134 print CPPI "#include <errno.h>\n";
135 if ($^O eq 'MSWin32') {
136 print CPPI "#define _WINSOCKAPI_\n"; # don't drag in everything
137 print CPPI "#include <winsock.h>\n";
143 # invoke CPP and read the output
144 if ($^O eq 'MSWin32' || $^O eq 'NetWare') {
145 open(CPPO,"$Config{cpprun} $Config{cppflags} errno.c |") or
146 die "Cannot run '$Config{cpprun} $Config{cppflags} errno.c'";
148 my $cpp = default_cpp();
149 open(CPPO,"$cpp < errno.c |") or
150 die "Cannot exec $cpp";
154 if (($^O eq 'MSWin32' || $^O eq 'NetWare') and $Config{cc} =~ /^bcc/i) {
155 $pat = '^/\*\s+(.+)\s+\d+\s*:\s+\*/';
158 $pat = '^#\s*(?:line)?\s*\d+\s+"([^"]+)"';
161 if ($^O eq 'os2' or $^O eq 'MSWin32' or $^O eq 'NetWare') {
169 $file{$1} = 1 if /$pat/o;
182 die "No error definitions found" unless keys %err;
184 # create the CPP input
186 open(CPPI,"> errno.c") or
187 die "Cannot open errno.c";
189 if ($^O eq 'NetWare') {
190 print CPPI "#include <nwerrno.h>\n";
193 print CPPI "#include <errno.h>\n";
195 if ($^O eq 'MSWin32') {
196 print CPPI "#include <winsock.h>\n";
197 foreach $err (keys %wsa) {
198 print CPPI "#ifndef $err\n";
199 print CPPI "#define $err WSA$err\n";
200 print CPPI "#endif\n";
205 foreach $err (keys %err) {
206 print CPPI '"',$err,'" [[',$err,']]',"\n";
211 unless ($^O eq 'MacOS' || $^O eq 'beos') { # trust what we have / get later
212 # invoke CPP and read the output
215 my $cpp = "$Config{cppstdin} $Config{cppflags} $Config{cppminus}";
216 $cpp =~ s/sys\$input//i;
217 open(CPPO,"$cpp errno.c |") or
218 die "Cannot exec $Config{cppstdin}";
219 } elsif ($^O eq 'MSWin32' || $^O eq 'NetWare') {
220 open(CPPO,"$Config{cpprun} $Config{cppflags} errno.c |") or
221 die "Cannot run '$Config{cpprun} $Config{cppflags} errno.c'";
223 my $cpp = default_cpp();
224 open(CPPO,"$cpp < errno.c |")
225 or die "Cannot exec $cpp";
232 next unless ($name, $expr) = /"(.*?)"\s*\[\s*\[\s*(.*?)\s*\]\s*\]/;
233 next if $name eq $expr;
234 $expr =~ s/\(?\(\w+\)([^\)]*)\)?/$1/; # ((type)0xcafebabe) at alia
235 $expr =~ s/((?:0x)?[0-9a-fA-F]+)[LU]+\b/$1/g; # 2147483647L et alia
236 next if $expr =~ m/^[a-zA-Z]+$/; # skip some Win32 functions
237 if($expr =~ m/^0[xX]/) {
238 $err{$name} = hex $expr;
241 $err{$name} = eval $expr;
243 delete $err{$name} unless defined $err{$name};
248 # Many of the E constants (including ENOENT, which is being
249 # used in the Perl test suite a lot), are available only as
250 # enums in BeOS, so compiling and executing some code is about
251 # only way to find out what the numeric Evalues are. In fact above, we
252 # didn't even bother to get the values of the ones that have numeric
253 # values, since we can get all of them here, anyway.
256 if (open(C, ">errno.c")) {
257 my @allerrs = keys %err;
264 print C qq[printf("$_ %d\n", $_);]
268 system("cc -o errno errno.c");
270 if (open(C, "./errno|")) {
272 if (/^(\w+) (-?\d+)$/) { $err{$1} = $2 }
276 die "failed to execute ./errno: $!\n";
280 die "failed to create errno.c: $!\n";
288 # This file is auto-generated. ***ANY*** changes here will be lost
292 our (\@EXPORT_OK,\%EXPORT_TAGS,\@ISA,\$VERSION,\%errno,\$AUTOLOAD);
297 "\$Config{'archname'}-\$Config{'osvers'}" eq
298 "$Config{'archname'}-$Config{'osvers'}" or
299 die "Errno architecture ($Config{'archname'}-$Config{'osvers'}) does not match executable architecture (\$Config{'archname'}-\$Config{'osvers'})";
301 \$VERSION = "$VERSION";
302 \$VERSION = eval \$VERSION;
303 \@ISA = qw(Exporter);
308 my @err = sort { $err{$a} <=> $err{$b} } keys %err;
309 map { $len = length if length > $len } @err;
311 my $j = "\@EXPORT_OK = qw(" . join(" ",keys %err) . ");\n";
312 $j =~ s/(.{50,70})\s/$1\n\t/g;
320 my $k = join(" ", grep { exists $err{$_} }
321 qw(E2BIG EACCES EADDRINUSE EADDRNOTAVAIL EAFNOSUPPORT
322 EAGAIN EALREADY EBADF EBUSY ECHILD ECONNABORTED
323 ECONNREFUSED ECONNRESET EDEADLK EDESTADDRREQ EDOM EDQUOT
324 EEXIST EFAULT EFBIG EHOSTDOWN EHOSTUNREACH EINPROGRESS
325 EINTR EINVAL EIO EISCONN EISDIR ELOOP EMFILE EMLINK
326 EMSGSIZE ENAMETOOLONG ENETDOWN ENETRESET ENETUNREACH
327 ENFILE ENOBUFS ENODEV ENOENT ENOEXEC ENOLCK ENOMEM
328 ENOPROTOOPT ENOSPC ENOSYS ENOTBLK ENOTCONN ENOTDIR
329 ENOTEMPTY ENOTSOCK ENOTTY ENXIO EOPNOTSUPP EPERM
330 EPFNOSUPPORT EPIPE EPROCLIM EPROTONOSUPPORT EPROTOTYPE
331 ERANGE EREMOTE ERESTART EROFS ESHUTDOWN ESOCKTNOSUPPORT
332 ESPIPE ESRCH ESTALE ETIMEDOUT ETOOMANYREFS ETXTBSY
333 EUSERS EWOULDBLOCK EXDEV));
335 $k =~ s/(.{50,70})\s/$1\n\t/g;
336 print "\t",$k,"\n )]\n);\n\n";
338 foreach $err (@err) {
339 printf "sub %s () { %d }\n",,$err,$err{$err};
344 sub TIEHASH { bless [] }
347 my ($self, $errname) = @_;
348 my $proto = prototype("Errno::$errname");
350 if (defined($proto) && $proto eq "") {
353 $errno = 0 unless $! == $errno;
360 Carp::confess("ERRNO hash is read only!");
368 while(($k,$v) = each %Errno::) {
369 my $proto = prototype("Errno::$k");
370 last if (defined($proto) && $proto eq "");
376 my $s = scalar keys %Errno::; # initialize iterator
381 my ($self, $errname) = @_;
382 my $r = ref $errname;
383 my $proto = !$r || $r eq 'CODE' ? prototype($errname) : undef;
384 defined($proto) && $proto eq "";
394 Errno - System errno constants
398 use Errno qw(EINTR EIO :POSIX);
402 C<Errno> defines and conditionally exports all the error constants
403 defined in your system C<errno.h> include file. It has a single export
404 tag, C<:POSIX>, which will export all POSIX defined error numbers.
406 C<Errno> also makes C<%!> magic such that each element of C<%!> has a
407 non-zero value only if C<$!> is set to that value. For example:
411 unless (open(FH, "/fangorn/spouse")) {
413 warn "Get a wife!\n";
415 warn "This path is barred: $!";
419 If a specified constant C<EFOO> does not exist on the system, C<$!{EFOO}>
420 returns C<"">. You may use C<exists $!{EFOO}> to check whether the
421 constant is available on the system.
425 Importing a particular constant may not be very portable, because the
426 import will fail on platforms that do not have that constant. A more
427 portable way to set C<$!> to a valid value is to use:
429 if (exists &Errno::EFOO) {
435 Graham Barr <gbarr@pobox.com>
439 Copyright (c) 1997-8 Graham Barr. All rights reserved.
440 This program is free software; you can redistribute it and/or modify it
441 under the same terms as Perl itself.