1 use ExtUtils::MakeMaker;
5 our $VERSION = "1.09_00";
9 unlink "Errno.pm" if -f "Errno.pm";
10 open OUT, ">Errno.pm" or die "Cannot open Errno.pm: $!";
13 foreach $file (get_files()) {
17 unlink "errno.c" if -f "errno.c";
22 return unless defined $file and -f $file;
25 if (($^O eq 'VMS') && ($Config{vms_cc_type} ne 'gnuc')) {
26 unless(open(FH," LIBRARY/EXTRACT=ERRNO/OUTPUT=SYS\$OUTPUT $file |")) {
27 warn "Cannot open '$file'";
30 } elsif ($Config{gccversion} ne ''
31 # OpenSTEP has gcc 2.7.2.1 which recognizes but
32 # doesn't implement the -dM flag.
33 && $^O ne 'openstep' && $^O ne 'next' && $^O ne 'darwin'
35 # With the -dM option, gcc outputs every #define it finds
36 unless(open(FH,"$Config{cc} -E -dM $Config{cppflags} $file |")) {
37 warn "Cannot open '$file'";
41 unless(open(FH,"< $file")) {
42 # This file could be a temporary file created by cppstdin
43 # so only warn under -w, and return
44 warn "Cannot open '$file'" if $^W;
52 if /^\s*#\s*define\s+(E\w+)\s+(\d+)/;
57 if /^\s*#\s*define\s+(E\w+)\s+/;
66 unless (defined $cppstdin) {
68 $cppstdin = $Config{cppstdin};
69 my $upup_cppstdin = File::Spec->catfile(File::Spec->updir,
72 my $cppstdin_is_wrapper =
73 ($cppstdin eq 'cppstdin'
75 and -x $upup_cppstdin);
76 $cppstdin = $upup_cppstdin if $cppstdin_is_wrapper;
78 return "$cppstdin $Config{cppflags} $Config{cppminus}";
83 # VMS keeps its include files in system libraries (well, except for Gcc)
85 if ($Config{vms_cc_type} eq 'decc') {
86 $file{'Sys$Library:DECC$RTLDEF.TLB'} = 1;
87 } elsif ($Config{vms_cc_type} eq 'vaxc') {
88 $file{'Sys$Library:vaxcdef.tlb'} = 1;
89 } elsif ($Config{vms_cc_type} eq 'gcc') {
90 $file{'gnu_cc_include:[000000]errno.h'} = 1;
92 } elsif ($^O eq 'os390') {
93 # OS/390 C compiler doesn't generate #file or #line directives
94 $file{'/usr/include/errno.h'} = 1;
95 } elsif ($^O eq 'vmesa') {
96 # OS/390 C compiler doesn't generate #file or #line directives
97 $file{'../../vmesa/errno.h'} = 1;
98 } elsif ($Config{archname} eq 'epoc') {
99 # Watch out for cross compiling for EPOC (usually done on linux)
100 $file{'/usr/local/epoc/include/libc/sys/errno.h'} = 1;
101 } elsif ($^O eq 'linux' &&
102 $Config{gccversion} ne '' # might be using, say, Intel's icc
104 # Some Linuxes have weird errno.hs which generate
105 # no #file or #line directives
106 $file{'/usr/include/errno.h'} = 1;
107 } elsif ($^O eq 'MacOS') {
108 # note that we are only getting the GUSI errno's here ...
109 # we might miss out on compiler-specific ones
110 $file{"$ENV{GUSI}include:sys:errno.h"} = 1;
112 } elsif ($^O eq 'beos') {
113 # hidden in a special place
114 $file{'/boot/develop/headers/posix/errno.h'} = 1;
117 open(CPPI,"> errno.c") or
118 die "Cannot open errno.c";
120 if ($^O eq 'NetWare') {
121 print CPPI "#include <nwerrno.h>\n";
123 print CPPI "#include <errno.h>\n";
128 # invoke CPP and read the output
129 if ($^O eq 'MSWin32' || $^O eq 'NetWare') {
130 open(CPPO,"$Config{cpprun} $Config{cppflags} errno.c |") or
131 die "Cannot run '$Config{cpprun} $Config{cppflags} errno.c'";
133 my $cpp = default_cpp();
134 open(CPPO,"$cpp < errno.c |") or
135 die "Cannot exec $cpp";
139 if (($^O eq 'MSWin32' || $^O eq 'NetWare') and $Config{cc} =~ /^bcc/i) {
140 $pat = '^/\*\s+(.+)\s+\d+\s*:\s+\*/';
143 $pat = '^#\s*(?:line)?\s*\d+\s+"([^"]+)"';
146 if ($^O eq 'os2' or $^O eq 'MSWin32' or $^O eq 'NetWare') {
154 $file{$1} = 1 if /$pat/o;
167 die "No error definitions found" unless keys %err;
169 # create the CPP input
171 open(CPPI,"> errno.c") or
172 die "Cannot open errno.c";
174 if ($^O eq 'NetWare') {
175 print CPPI "#include <nwerrno.h>\n";
177 print CPPI "#include <errno.h>\n";
180 foreach $err (keys %err) {
181 print CPPI '"',$err,'" [[',$err,']]',"\n";
186 unless ($^O eq 'MacOS') { # trust what we have
187 # invoke CPP and read the output
190 my $cpp = "$Config{cppstdin} $Config{cppflags} $Config{cppminus}";
191 $cpp =~ s/sys\$input//i;
192 open(CPPO,"$cpp errno.c |") or
193 die "Cannot exec $Config{cppstdin}";
194 } elsif ($^O eq 'MSWin32' || $^O eq 'NetWare') {
195 open(CPPO,"$Config{cpprun} $Config{cppflags} errno.c |") or
196 die "Cannot run '$Config{cpprun} $Config{cppflags} errno.c'";
198 my $cpp = default_cpp();
199 open(CPPO,"$cpp < errno.c |")
200 or die "Cannot exec $cpp";
207 next unless ($name, $expr) = /"(.*?)"\s*\[\s*\[\s*(.*?)\s*\]\s*\]/;
208 next if $name eq $expr;
209 $expr =~ s/(\d+)[LU]+\b/$1/g; # 2147483647L et alia
210 $err{$name} = eval $expr;
215 # Many of the E constants (including ENOENT, which is being
216 # used in the Perl test suite a lot), are available only as
217 # enums in BeOS, so compiling and executing some code is about
218 # only way to find out what the numeric Evalues are.
221 if (open(C, ">errno.c")) {
222 my @zero = grep { !$err{$_} } keys %err;
229 print C qq[printf("$_ %d\n", $_);]
233 system("cc -o errno errno.c");
235 if (open(C, "./errno|")) {
237 if (/^(\w+) (-?\d+)$/) { $err{$1} = $2 }
241 die "failed to execute ./errno: $!\n";
245 die "failed to create errno.c: $!\n";
253 # This file is auto-generated. ***ANY*** changes here will be lost
257 our (\@EXPORT_OK,\%EXPORT_TAGS,\@ISA,\$VERSION,\%errno,\$AUTOLOAD);
262 "\$Config{'archname'}-\$Config{'osvers'}" eq
263 "$Config{'archname'}-$Config{'osvers'}" or
264 die "Errno architecture ($Config{'archname'}-$Config{'osvers'}) does not match executable architecture (\$Config{'archname'}-\$Config{'osvers'})";
266 \$VERSION = "$VERSION";
267 \@ISA = qw(Exporter);
272 my @err = sort { $err{$a} <=> $err{$b} } keys %err;
273 map { $len = length if length > $len } @err;
275 my $j = "\@EXPORT_OK = qw(" . join(" ",keys %err) . ");\n";
276 $j =~ s/(.{50,70})\s/$1\n\t/g;
284 my $k = join(" ", grep { exists $err{$_} }
285 qw(E2BIG EACCES EADDRINUSE EADDRNOTAVAIL EAFNOSUPPORT
286 EAGAIN EALREADY EBADF EBUSY ECHILD ECONNABORTED
287 ECONNREFUSED ECONNRESET EDEADLK EDESTADDRREQ EDOM EDQUOT
288 EEXIST EFAULT EFBIG EHOSTDOWN EHOSTUNREACH EINPROGRESS
289 EINTR EINVAL EIO EISCONN EISDIR ELOOP EMFILE EMLINK
290 EMSGSIZE ENAMETOOLONG ENETDOWN ENETRESET ENETUNREACH
291 ENFILE ENOBUFS ENODEV ENOENT ENOEXEC ENOLCK ENOMEM
292 ENOPROTOOPT ENOSPC ENOSYS ENOTBLK ENOTCONN ENOTDIR
293 ENOTEMPTY ENOTSOCK ENOTTY ENXIO EOPNOTSUPP EPERM
294 EPFNOSUPPORT EPIPE EPROCLIM EPROTONOSUPPORT EPROTOTYPE
295 ERANGE EREMOTE ERESTART EROFS ESHUTDOWN ESOCKTNOSUPPORT
296 ESPIPE ESRCH ESTALE ETIMEDOUT ETOOMANYREFS ETXTBSY
297 EUSERS EWOULDBLOCK EXDEV));
299 $k =~ s/(.{50,70})\s/$1\n\t/g;
300 print "\t",$k,"\n )]\n);\n\n";
302 foreach $err (@err) {
303 printf "sub %s () { %d }\n",,$err,$err{$err};
308 sub TIEHASH { bless [] }
311 my ($self, $errname) = @_;
312 my $proto = prototype("Errno::$errname");
314 if (defined($proto) && $proto eq "") {
317 $errno = 0 unless $! == $errno;
324 Carp::confess("ERRNO hash is read only!");
332 while(($k,$v) = each %Errno::) {
333 my $proto = prototype("Errno::$k");
334 last if (defined($proto) && $proto eq "");
340 my $s = scalar keys %Errno::; # initialize iterator
345 my ($self, $errname) = @_;
346 my $proto = prototype($errname);
347 defined($proto) && $proto eq "";
357 Errno - System errno constants
361 use Errno qw(EINTR EIO :POSIX);
365 C<Errno> defines and conditionally exports all the error constants
366 defined in your system C<errno.h> include file. It has a single export
367 tag, C<:POSIX>, which will export all POSIX defined error numbers.
369 C<Errno> also makes C<%!> magic such that each element of C<%!> has a
370 non-zero value only if C<$!> is set to that value. For example:
374 unless (open(FH, "/fangorn/spouse")) {
376 warn "Get a wife!\n";
378 warn "This path is barred: $!";
382 If a specified constant C<EFOO> does not exist on the system, C<$!{EFOO}>
383 returns C<"">. You may use C<exists $!{EFOO}> to check whether the
384 constant is available on the system.
388 Importing a particular constant may not be very portable, because the
389 import will fail on platforms that do not have that constant. A more
390 portable way to set C<$!> to a valid value is to use:
392 if (exists &Errno::EFOO) {
398 Graham Barr <gbarr@pobox.com>
402 Copyright (c) 1997-8 Graham Barr. All rights reserved.
403 This program is free software; you can redistribute it and/or modify it
404 under the same terms as Perl itself.