1 use ExtUtils::MakeMaker;
10 # Symbian cross-compiling environment.
11 my $IsSymbian = exists $ENV{SDK} && -d "$ENV{SDK}\\epoc32";
13 my $IsMSWin32 = $^O eq 'MSWin32' && !$IsSymbian;
15 unlink "Errno.pm" if -f "Errno.pm";
16 unlink "Errno.tmp" if -f "Errno.tmp";
17 open OUT, ">Errno.tmp" or die "Cannot open Errno.tmp: $!";
20 my @files = get_files();
21 if ($Config{gccversion} ne '' && $^O eq 'MSWin32') {
22 # MinGW complains "warning: #pragma system_header ignored outside include
23 # file" if the header files are processed individually, so include them
24 # all in .c file and process that instead.
25 open INCS, '>includes.c' or
26 die "Cannot open includes.c";
27 foreach $file (@files) {
28 next if $file eq 'errno.c';
30 print INCS qq[#include "$file"\n];
33 process_file('includes.c');
37 foreach $file (@files) {
42 unlink "errno.c" if -f "errno.c";
43 close OUT or die "Error closing Errno.tmp: $!";
45 rename "Errno.tmp", "Errno.pm" or die "Cannot rename Errno.tmp to Errno.pm: $!";
50 # for win32 perl under cygwin, we need to get a windows pathname
51 if ($^O eq 'MSWin32' && $Config{cc} =~ /\B-mno-cygwin\b/ &&
52 defined($file) && !-f $file) {
53 chomp($file = `cygpath -w "$file"`);
56 return unless defined $file and -f $file;
57 # warn "Processing $file\n";
60 if (($^O eq 'VMS') && ($Config{vms_cc_type} ne 'gnuc')) {
61 unless(open(FH," LIBRARY/EXTRACT=ERRNO/OUTPUT=SYS\$OUTPUT $file |")) {
62 warn "Cannot open '$file'";
65 } elsif ($Config{gccversion} ne ''
66 # OpenSTEP has gcc 2.7.2.1 which recognizes but
67 # doesn't implement the -dM flag.
68 && $^O ne 'openstep' && $^O ne 'next' && $^O ne 'darwin'
70 # With the -dM option, gcc outputs every #define it finds
71 unless(open(FH,"$Config{cc} -E -dM $Config{cppflags} $file |")) {
72 warn "Cannot open '$file'";
76 unless(open(FH,"< $file")) {
77 # This file could be a temporary file created by cppstdin
78 # so only warn under -w, and return
79 warn "Cannot open '$file'" if $^W;
87 if /^\s*#\s*define\s+(E\w+)\s+(\d+)/;
92 if /^\s*#\s*define\s+(E\w+)\s+/;
95 if /^\s*#\s*define\s+WSA(E\w+)\s+/;
106 unless (defined $cppstdin) {
108 $cppstdin = $Config{cppstdin};
109 my $upup_cppstdin = File::Spec->catfile(File::Spec->updir,
112 my $cppstdin_is_wrapper =
113 ($cppstdin eq 'cppstdin'
114 and -f $upup_cppstdin
115 and -x $upup_cppstdin);
116 $cppstdin = $upup_cppstdin if $cppstdin_is_wrapper;
118 return "$cppstdin $Config{cppflags} $Config{cppminus}";
123 # VMS keeps its include files in system libraries (well, except for Gcc)
125 if ($Config{vms_cc_type} eq 'decc') {
126 $file{'Sys$Library:DECC$RTLDEF.TLB'} = 1;
127 } elsif ($Config{vms_cc_type} eq 'vaxc') {
128 $file{'Sys$Library:vaxcdef.tlb'} = 1;
129 } elsif ($Config{vms_cc_type} eq 'gcc') {
130 $file{'gnu_cc_include:[000000]errno.h'} = 1;
132 } elsif ($^O eq 'os390') {
133 # OS/390 C compiler doesn't generate #file or #line directives
134 $file{'/usr/include/errno.h'} = 1;
135 } elsif ($^O eq 'vmesa') {
136 # OS/390 C compiler doesn't generate #file or #line directives
137 $file{'../../vmesa/errno.h'} = 1;
138 } elsif ($Config{archname} eq 'epoc') {
139 # Watch out for cross compiling for EPOC (usually done on linux)
140 $file{'/usr/local/epocemx/epocsdk/include/libc/sys/errno.h'} = 1;
141 } elsif ($Config{archname} eq 'arm-riscos') {
142 # Watch out for cross compiling for RISC OS
143 my $dep = `echo "#include <errno.h>" | gcc -E -M -`;
144 if ($dep =~ /(\S+errno\.h)/) {
147 } elsif ($^O eq 'linux' &&
148 $Config{gccversion} ne '' &&
149 $Config{gccversion} !~ /intel/i
150 # might be using, say, Intel's icc
152 # Some Linuxes have weird errno.hs which generate
153 # no #file or #line directives
154 my $linux_errno_h = -e '/usr/include/errno.h' ?
155 '/usr/include/errno.h' : '/usr/local/include/errno.h';
156 $file{$linux_errno_h} = 1;
157 } elsif ($^O eq 'MacOS') {
158 # note that we are only getting the GUSI errno's here ...
159 # we might miss out on compiler-specific ones
160 $file{"$ENV{GUSI}include:sys:errno.h"} = 1;
162 } elsif ($^O eq 'beos' || $^O eq 'haiku') {
163 # hidden in a special place
164 $file{'/boot/develop/headers/posix/errno.h'} = 1;
166 } elsif ($^O eq 'vos') {
167 # avoid problem where cpp returns non-POSIX pathnames
168 $file{'/system/include_library/errno.h'} = 1;
169 } elsif ($IsSymbian) {
172 $file{"$SDK/epoc32/include/libc/sys/errno.h"} = 1;
174 open(CPPI,"> errno.c") or
175 die "Cannot open errno.c";
177 if ($^O eq 'NetWare') {
178 print CPPI "#include <nwerrno.h>\n";
180 print CPPI "#include <errno.h>\n";
182 print CPPI "#define _WINSOCKAPI_\n"; # don't drag in everything
183 print CPPI "#include <winsock.h>\n";
189 # invoke CPP and read the output
190 if ($IsMSWin32 || $^O eq 'NetWare') {
191 open(CPPO,"$Config{cpprun} $Config{cppflags} errno.c |") or
192 die "Cannot run '$Config{cpprun} $Config{cppflags} errno.c'";
194 my $cpp = default_cpp();
195 open(CPPO,"$cpp < errno.c |") or
196 die "Cannot exec $cpp";
200 if (($IsMSWin32 || $^O eq 'NetWare') and $Config{cc} =~ /^bcc/i) {
201 $pat = '^/\*\s+(.+)\s+\d+\s*:\s+\*/';
204 $pat = '^#\s*(?:line)?\s*\d+\s+"([^"]+)"';
207 if ($^O eq 'os2' or $IsMSWin32 or $^O eq 'NetWare') {
215 $file{$1} = 1 if /$pat/o;
228 die "No error definitions found" unless keys %err;
230 # create the CPP input
232 open(CPPI,"> errno.c") or
233 die "Cannot open errno.c";
235 if ($^O eq 'NetWare') {
236 print CPPI "#include <nwerrno.h>\n";
239 print CPPI "#include <errno.h>\n";
242 print CPPI "#include <winsock.h>\n";
243 foreach $err (keys %wsa) {
244 print CPPI "#ifndef $err\n";
245 print CPPI "#define $err WSA$err\n";
246 print CPPI "#endif\n";
251 foreach $err (keys %err) {
252 print CPPI '"',$err,'" [[',$err,']]',"\n";
257 unless ($^O eq 'MacOS' || $^O eq 'beos') { # trust what we have / get later
258 # invoke CPP and read the output
261 my $cpp = "$Config{cppstdin} $Config{cppflags} $Config{cppminus}";
262 $cpp =~ s/sys\$input//i;
263 open(CPPO,"$cpp errno.c |") or
264 die "Cannot exec $Config{cppstdin}";
265 } elsif ($IsMSWin32 || $^O eq 'NetWare') {
266 open(CPPO,"$Config{cpprun} $Config{cppflags} errno.c |") or
267 die "Cannot run '$Config{cpprun} $Config{cppflags} errno.c'";
268 } elsif ($IsSymbian) {
269 my $cpp = "gcc -E -I$ENV{SDK}\\epoc32\\include\\libc -";
270 open(CPPO,"$cpp < errno.c |")
271 or die "Cannot exec $cpp";
273 my $cpp = default_cpp();
274 open(CPPO,"$cpp < errno.c |")
275 or die "Cannot exec $cpp";
282 next unless ($name, $expr) = /"(.*?)"\s*\[\s*\[\s*(.*?)\s*\]\s*\]/;
283 next if $name eq $expr;
284 $expr =~ s/\(?\([a-z_]\w*\)([^\)]*)\)?/$1/i; # ((type)0xcafebabe) at alia
285 $expr =~ s/((?:0x)?[0-9a-fA-F]+)[LU]+\b/$1/g; # 2147483647L et alia
286 next if $expr =~ m/^[a-zA-Z]+$/; # skip some Win32 functions
287 if($expr =~ m/^0[xX]/) {
288 $err{$name} = hex $expr;
291 $err{$name} = eval $expr;
293 delete $err{$name} unless defined $err{$name};
298 # Many of the E constants (including ENOENT, which is being
299 # used in the Perl test suite a lot), are available only as
300 # enums in BeOS, so compiling and executing some code is about
301 # only way to find out what the numeric Evalues are. In fact above, we
302 # didn't even bother to get the values of the ones that have numeric
303 # values, since we can get all of them here, anyway.
306 if (open(C, ">errno.c")) {
307 my @allerrs = keys %err;
314 print C qq[printf("$_ %d\n", $_);]
318 system("cc -o errno errno.c");
320 if (open(C, "./errno|")) {
322 if (/^(\w+) (-?\d+)$/) { $err{$1} = $2 }
326 die "failed to execute ./errno: $!\n";
330 die "failed to create errno.c: $!\n";
338 # This file is auto-generated. ***ANY*** changes here will be lost
342 our (\@EXPORT_OK,\%EXPORT_TAGS,\@ISA,\$VERSION,\%errno,\$AUTOLOAD);
347 "\$Config{'archname'}-\$Config{'osvers'}" eq
348 "$Config{'archname'}-$Config{'osvers'}" or
349 die "Errno architecture ($Config{'archname'}-$Config{'osvers'}) does not match executable architecture (\$Config{'archname'}-\$Config{'osvers'})";
351 \$VERSION = "$VERSION";
352 \$VERSION = eval \$VERSION;
353 \@ISA = qw(Exporter);
358 my @err = sort { $err{$a} <=> $err{$b} } keys %err;
359 map { $len = length if length > $len } @err;
361 my $j = "\@EXPORT_OK = qw(" . join(" ",keys %err) . ");\n";
362 $j =~ s/(.{50,70})\s/$1\n\t/g;
370 my $k = join(" ", grep { exists $err{$_} }
371 qw(E2BIG EACCES EADDRINUSE EADDRNOTAVAIL EAFNOSUPPORT
372 EAGAIN EALREADY EBADF EBUSY ECHILD ECONNABORTED
373 ECONNREFUSED ECONNRESET EDEADLK EDESTADDRREQ EDOM EDQUOT
374 EEXIST EFAULT EFBIG EHOSTDOWN EHOSTUNREACH EINPROGRESS
375 EINTR EINVAL EIO EISCONN EISDIR ELOOP EMFILE EMLINK
376 EMSGSIZE ENAMETOOLONG ENETDOWN ENETRESET ENETUNREACH
377 ENFILE ENOBUFS ENODEV ENOENT ENOEXEC ENOLCK ENOMEM
378 ENOPROTOOPT ENOSPC ENOSYS ENOTBLK ENOTCONN ENOTDIR
379 ENOTEMPTY ENOTSOCK ENOTTY ENXIO EOPNOTSUPP EPERM
380 EPFNOSUPPORT EPIPE EPROCLIM EPROTONOSUPPORT EPROTOTYPE
381 ERANGE EREMOTE ERESTART EROFS ESHUTDOWN ESOCKTNOSUPPORT
382 ESPIPE ESRCH ESTALE ETIMEDOUT ETOOMANYREFS ETXTBSY
383 EUSERS EWOULDBLOCK EXDEV));
385 $k =~ s/(.{50,70})\s/$1\n\t/g;
386 print "\t",$k,"\n )]\n);\n\n";
388 foreach $err (@err) {
389 printf "sub %s () { %d }\n",,$err,$err{$err};
394 sub TIEHASH { bless [] }
397 my ($self, $errname) = @_;
398 my $proto = prototype("Errno::$errname");
400 if (defined($proto) && $proto eq "") {
403 $errno = 0 unless $! == $errno;
410 Carp::confess("ERRNO hash is read only!");
418 while(($k,$v) = each %Errno::) {
419 my $proto = prototype("Errno::$k");
420 last if (defined($proto) && $proto eq "");
426 my $s = scalar keys %Errno::; # initialize iterator
431 my ($self, $errname) = @_;
432 my $r = ref $errname;
433 my $proto = !$r || $r eq 'CODE' ? prototype($errname) : undef;
434 defined($proto) && $proto eq "";
444 Errno - System errno constants
448 use Errno qw(EINTR EIO :POSIX);
452 C<Errno> defines and conditionally exports all the error constants
453 defined in your system C<errno.h> include file. It has a single export
454 tag, C<:POSIX>, which will export all POSIX defined error numbers.
456 C<Errno> also makes C<%!> magic such that each element of C<%!> has a
457 non-zero value only if C<$!> is set to that value. For example:
461 unless (open(FH, "/fangorn/spouse")) {
463 warn "Get a wife!\n";
465 warn "This path is barred: $!";
469 If a specified constant C<EFOO> does not exist on the system, C<$!{EFOO}>
470 returns C<"">. You may use C<exists $!{EFOO}> to check whether the
471 constant is available on the system.
475 Importing a particular constant may not be very portable, because the
476 import will fail on platforms that do not have that constant. A more
477 portable way to set C<$!> to a valid value is to use:
479 if (exists &Errno::EFOO) {
485 Graham Barr <gbarr@pobox.com>
489 Copyright (c) 1997-8 Graham Barr. All rights reserved.
490 This program is free software; you can redistribute it and/or modify it
491 under the same terms as Perl itself.