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()) {
16 if ($^O eq 'MSWin32') {
17 $file =~ s/errno/winsock/;
22 unlink "errno.c" if -f "errno.c";
27 return unless defined $file and -f $file;
28 # warn "Processing $file\n";
31 if (($^O eq 'VMS') && ($Config{vms_cc_type} ne 'gnuc')) {
32 unless(open(FH," LIBRARY/EXTRACT=ERRNO/OUTPUT=SYS\$OUTPUT $file |")) {
33 warn "Cannot open '$file'";
36 } elsif ($Config{gccversion} ne ''
37 # OpenSTEP has gcc 2.7.2.1 which recognizes but
38 # doesn't implement the -dM flag.
39 && $^O ne 'openstep' && $^O ne 'next' && $^O ne 'darwin'
41 # With the -dM option, gcc outputs every #define it finds
42 unless(open(FH,"$Config{cc} -E -dM $Config{cppflags} $file |")) {
43 warn "Cannot open '$file'";
47 unless(open(FH,"< $file")) {
48 # This file could be a temporary file created by cppstdin
49 # so only warn under -w, and return
50 warn "Cannot open '$file'" if $^W;
58 if /^\s*#\s*define\s+(E\w+)\s+(\d+)/;
63 if /^\s*#\s*define\s+(E\w+)\s+/;
64 if ($^O eq 'MSWin32') {
66 if /^\s*#\s*define\s+WSA(E\w+)\s+/;
76 unless (defined $cppstdin) {
78 $cppstdin = $Config{cppstdin};
79 my $upup_cppstdin = File::Spec->catfile(File::Spec->updir,
82 my $cppstdin_is_wrapper =
83 ($cppstdin eq 'cppstdin'
85 and -x $upup_cppstdin);
86 $cppstdin = $upup_cppstdin if $cppstdin_is_wrapper;
88 return "$cppstdin $Config{cppflags} $Config{cppminus}";
93 # VMS keeps its include files in system libraries (well, except for Gcc)
95 if ($Config{vms_cc_type} eq 'decc') {
96 $file{'Sys$Library:DECC$RTLDEF.TLB'} = 1;
97 } elsif ($Config{vms_cc_type} eq 'vaxc') {
98 $file{'Sys$Library:vaxcdef.tlb'} = 1;
99 } elsif ($Config{vms_cc_type} eq 'gcc') {
100 $file{'gnu_cc_include:[000000]errno.h'} = 1;
102 } elsif ($^O eq 'os390') {
103 # OS/390 C compiler doesn't generate #file or #line directives
104 $file{'/usr/include/errno.h'} = 1;
105 } elsif ($^O eq 'vmesa') {
106 # OS/390 C compiler doesn't generate #file or #line directives
107 $file{'../../vmesa/errno.h'} = 1;
108 } elsif ($Config{archname} eq 'epoc') {
109 # Watch out for cross compiling for EPOC (usually done on linux)
110 $file{'/usr/local/epocemx/epocsdk/include/libc/sys/errno.h'} = 1;
111 } elsif ($^O eq 'linux' &&
112 $Config{gccversion} ne '' # might be using, say, Intel's icc
114 # Some Linuxes have weird errno.hs which generate
115 # no #file or #line directives
116 $file{'/usr/include/errno.h'} = 1;
117 } elsif ($^O eq 'MacOS') {
118 # note that we are only getting the GUSI errno's here ...
119 # we might miss out on compiler-specific ones
120 $file{"$ENV{GUSI}include:sys:errno.h"} = 1;
122 } elsif ($^O eq 'beos') {
123 # hidden in a special place
124 $file{'/boot/develop/headers/posix/errno.h'} = 1;
127 open(CPPI,"> errno.c") or
128 die "Cannot open errno.c";
130 if ($^O eq 'NetWare') {
131 print CPPI "#include <nwerrno.h>\n";
133 print CPPI "#include <errno.h>\n";
138 # invoke CPP and read the output
139 if ($^O eq 'MSWin32' || $^O eq 'NetWare') {
140 open(CPPO,"$Config{cpprun} $Config{cppflags} errno.c |") or
141 die "Cannot run '$Config{cpprun} $Config{cppflags} errno.c'";
143 my $cpp = default_cpp();
144 open(CPPO,"$cpp < errno.c |") or
145 die "Cannot exec $cpp";
149 if (($^O eq 'MSWin32' || $^O eq 'NetWare') and $Config{cc} =~ /^bcc/i) {
150 $pat = '^/\*\s+(.+)\s+\d+\s*:\s+\*/';
153 $pat = '^#\s*(?:line)?\s*\d+\s+"([^"]+)"';
156 if ($^O eq 'os2' or $^O eq 'MSWin32' or $^O eq 'NetWare') {
164 $file{$1} = 1 if /$pat/o;
177 die "No error definitions found" unless keys %err;
179 # create the CPP input
181 open(CPPI,"> errno.c") or
182 die "Cannot open errno.c";
184 if ($^O eq 'NetWare') {
185 print CPPI "#include <nwerrno.h>\n";
188 print CPPI "#include <errno.h>\n";
190 if ($^O eq 'MSWin32') {
191 print CPPI "#include <winsock.h>\n";
192 foreach $err (keys %wsa) {
193 print CPPI "#ifndef $err\n";
194 print CPPI "#define $err WSA$err\n";
195 print CPPI "#endif\n";
200 foreach $err (keys %err) {
201 print CPPI '"',$err,'" [[',$err,']]',"\n";
206 unless ($^O eq 'MacOS') { # trust what we have
207 # invoke CPP and read the output
210 my $cpp = "$Config{cppstdin} $Config{cppflags} $Config{cppminus}";
211 $cpp =~ s/sys\$input//i;
212 open(CPPO,"$cpp errno.c |") or
213 die "Cannot exec $Config{cppstdin}";
214 } elsif ($^O eq 'MSWin32' || $^O eq 'NetWare') {
215 open(CPPO,"$Config{cpprun} $Config{cppflags} errno.c |") or
216 die "Cannot run '$Config{cpprun} $Config{cppflags} errno.c'";
218 my $cpp = default_cpp();
219 open(CPPO,"$cpp < errno.c |")
220 or die "Cannot exec $cpp";
227 next unless ($name, $expr) = /"(.*?)"\s*\[\s*\[\s*(.*?)\s*\]\s*\]/;
228 next if $name eq $expr;
229 $expr =~ s/(\d+)[LU]+\b/$1/g; # 2147483647L et alia
230 $err{$name} = eval $expr;
235 # Many of the E constants (including ENOENT, which is being
236 # used in the Perl test suite a lot), are available only as
237 # enums in BeOS, so compiling and executing some code is about
238 # only way to find out what the numeric Evalues are.
241 if (open(C, ">errno.c")) {
242 my @zero = grep { !$err{$_} } keys %err;
249 print C qq[printf("$_ %d\n", $_);]
253 system("cc -o errno errno.c");
255 if (open(C, "./errno|")) {
257 if (/^(\w+) (-?\d+)$/) { $err{$1} = $2 }
261 die "failed to execute ./errno: $!\n";
265 die "failed to create errno.c: $!\n";
273 # This file is auto-generated. ***ANY*** changes here will be lost
277 our (\@EXPORT_OK,\%EXPORT_TAGS,\@ISA,\$VERSION,\%errno,\$AUTOLOAD);
282 "\$Config{'archname'}-\$Config{'osvers'}" eq
283 "$Config{'archname'}-$Config{'osvers'}" or
284 die "Errno architecture ($Config{'archname'}-$Config{'osvers'}) does not match executable architecture (\$Config{'archname'}-\$Config{'osvers'})";
286 \$VERSION = "$VERSION";
287 \@ISA = qw(Exporter);
292 my @err = sort { $err{$a} <=> $err{$b} } keys %err;
293 map { $len = length if length > $len } @err;
295 my $j = "\@EXPORT_OK = qw(" . join(" ",keys %err) . ");\n";
296 $j =~ s/(.{50,70})\s/$1\n\t/g;
304 my $k = join(" ", grep { exists $err{$_} }
305 qw(E2BIG EACCES EADDRINUSE EADDRNOTAVAIL EAFNOSUPPORT
306 EAGAIN EALREADY EBADF EBUSY ECHILD ECONNABORTED
307 ECONNREFUSED ECONNRESET EDEADLK EDESTADDRREQ EDOM EDQUOT
308 EEXIST EFAULT EFBIG EHOSTDOWN EHOSTUNREACH EINPROGRESS
309 EINTR EINVAL EIO EISCONN EISDIR ELOOP EMFILE EMLINK
310 EMSGSIZE ENAMETOOLONG ENETDOWN ENETRESET ENETUNREACH
311 ENFILE ENOBUFS ENODEV ENOENT ENOEXEC ENOLCK ENOMEM
312 ENOPROTOOPT ENOSPC ENOSYS ENOTBLK ENOTCONN ENOTDIR
313 ENOTEMPTY ENOTSOCK ENOTTY ENXIO EOPNOTSUPP EPERM
314 EPFNOSUPPORT EPIPE EPROCLIM EPROTONOSUPPORT EPROTOTYPE
315 ERANGE EREMOTE ERESTART EROFS ESHUTDOWN ESOCKTNOSUPPORT
316 ESPIPE ESRCH ESTALE ETIMEDOUT ETOOMANYREFS ETXTBSY
317 EUSERS EWOULDBLOCK EXDEV));
319 $k =~ s/(.{50,70})\s/$1\n\t/g;
320 print "\t",$k,"\n )]\n);\n\n";
322 foreach $err (@err) {
323 printf "sub %s () { %d }\n",,$err,$err{$err};
328 sub TIEHASH { bless [] }
331 my ($self, $errname) = @_;
332 my $proto = prototype("Errno::$errname");
334 if (defined($proto) && $proto eq "") {
337 $errno = 0 unless $! == $errno;
344 Carp::confess("ERRNO hash is read only!");
352 while(($k,$v) = each %Errno::) {
353 my $proto = prototype("Errno::$k");
354 last if (defined($proto) && $proto eq "");
360 my $s = scalar keys %Errno::; # initialize iterator
365 my ($self, $errname) = @_;
366 my $proto = prototype($errname);
367 defined($proto) && $proto eq "";
377 Errno - System errno constants
381 use Errno qw(EINTR EIO :POSIX);
385 C<Errno> defines and conditionally exports all the error constants
386 defined in your system C<errno.h> include file. It has a single export
387 tag, C<:POSIX>, which will export all POSIX defined error numbers.
389 C<Errno> also makes C<%!> magic such that each element of C<%!> has a
390 non-zero value only if C<$!> is set to that value. For example:
394 unless (open(FH, "/fangorn/spouse")) {
396 warn "Get a wife!\n";
398 warn "This path is barred: $!";
402 If a specified constant C<EFOO> does not exist on the system, C<$!{EFOO}>
403 returns C<"">. You may use C<exists $!{EFOO}> to check whether the
404 constant is available on the system.
408 Importing a particular constant may not be very portable, because the
409 import will fail on platforms that do not have that constant. A more
410 portable way to set C<$!> to a valid value is to use:
412 if (exists &Errno::EFOO) {
418 Graham Barr <gbarr@pobox.com>
422 Copyright (c) 1997-8 Graham Barr. All rights reserved.
423 This program is free software; you can redistribute it and/or modify it
424 under the same terms as Perl itself.