1 use ExtUtils::MakeMaker;
5 our $VERSION = "1.111";
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 # With the -dM option, gcc outputs every #define it finds
32 unless(open(FH,"$Config{cc} -E -dM $Config{cppflags} $file |")) {
33 warn "Cannot open '$file'";
37 unless(open(FH,"< $file")) {
38 # This file could be a temporary file created by cppstdin
39 # so only warn under -w, and return
40 warn "Cannot open '$file'" if $^W;
48 if /^\s*#\s*define\s+(E\w+)\s+(\d+)/;
53 if /^\s*#\s*define\s+(E\w+)\s+/;
62 unless (defined $cppstdin) {
64 $cppstdin = $Config{cppstdin};
65 my $upup_cppstdin = File::Spec->catfile(File::Spec->updir,
68 my $cppstdin_is_wrapper =
69 ($cppstdin eq 'cppstdin'
71 and -x $upup_cppstdin);
72 $cppstdin = $upup_cppstdin if $cppstdin_is_wrapper;
74 return "$cppstdin $Config{cppflags} $Config{cppminus}";
79 # VMS keeps its include files in system libraries (well, except for Gcc)
81 if ($Config{vms_cc_type} eq 'decc') {
82 $file{'Sys$Library:DECC$RTLDEF.TLB'} = 1;
83 } elsif ($Config{vms_cc_type} eq 'vaxc') {
84 $file{'Sys$Library:vaxcdef.tlb'} = 1;
85 } elsif ($Config{vms_cc_type} eq 'gcc') {
86 $file{'gnu_cc_include:[000000]errno.h'} = 1;
88 } elsif ($^O eq 'os390') {
89 # OS/390 C compiler doesn't generate #file or #line directives
90 $file{'/usr/include/errno.h'} = 1;
91 } elsif ($^O eq 'vmesa') {
92 # OS/390 C compiler doesn't generate #file or #line directives
93 $file{'../../vmesa/errno.h'} = 1;
94 } elsif ($Config{archname} eq 'epoc') {
95 # Watch out for cross compiling for EPOC (usually done on linux)
96 $file{'/usr/local/epoc/include/libc/sys/errno.h'} = 1;
97 } elsif ($^O eq 'linux') {
98 # Some Linuxes have weird errno.hs which generate
99 # no #file or #line directives
100 $file{'/usr/include/errno.h'} = 1;
101 } elsif ($^O eq 'MacOS') {
102 # note that we are only getting the GUSI errno's here ...
103 # we might miss out on compiler-specific ones
104 $file{"$ENV{GUSI}include:sys:errno.h"} = 1;
107 open(CPPI,"> errno.c") or
108 die "Cannot open errno.c";
110 if ($^O eq 'NetWare') {
111 print CPPI "#include <nwerrno.h>\n";
113 print CPPI "#include <errno.h>\n";
118 # invoke CPP and read the output
119 if ($^O eq 'MSWin32' || $^O eq 'NetWare') {
120 open(CPPO,"$Config{cpprun} $Config{cppflags} errno.c |") or
121 die "Cannot run '$Config{cpprun} $Config{cppflags} errno.c'";
123 my $cpp = default_cpp();
124 open(CPPO,"$cpp < errno.c |") or
125 die "Cannot exec $cpp";
129 if (($^O eq 'MSWin32' || $^O eq 'NetWare') and $Config{cc} =~ /^bcc/i) {
130 $pat = '^/\*\s+(.+)\s+\d+\s*:\s+\*/';
133 $pat = '^#\s*(?:line)?\s*\d+\s+"([^"]+)"';
136 if ($^O eq 'os2' or $^O eq 'MSWin32' or $^O eq 'NetWare') {
144 $file{$1} = 1 if /$pat/o;
157 die "No error definitions found" unless keys %err;
159 # create the CPP input
161 open(CPPI,"> errno.c") or
162 die "Cannot open errno.c";
164 if ($^O eq 'NetWare') {
165 print CPPI "#include <nwerrno.h>\n";
167 print CPPI "#include <errno.h>\n";
170 foreach $err (keys %err) {
171 print CPPI '"',$err,'" [[',$err,']]',"\n";
176 unless ($^O eq 'MacOS') { # trust what we have
177 # invoke CPP and read the output
180 my $cpp = "$Config{cppstdin} $Config{cppflags} $Config{cppminus}";
181 $cpp =~ s/sys\$input//i;
182 open(CPPO,"$cpp errno.c |") or
183 die "Cannot exec $Config{cppstdin}";
184 } elsif ($^O eq 'MSWin32' || $^O eq 'NetWare') {
185 open(CPPO,"$Config{cpprun} $Config{cppflags} errno.c |") or
186 die "Cannot run '$Config{cpprun} $Config{cppflags} errno.c'";
188 my $cpp = default_cpp();
189 open(CPPO,"$cpp < errno.c |")
190 or die "Cannot exec $cpp";
197 next unless ($name, $expr) = /"(.*?)"\s*\[\s*\[\s*(.*?)\s*\]\s*\]/;
198 next if $name eq $expr;
199 $err{$name} = eval $expr;
208 # This file is auto-generated. ***ANY*** changes here will be lost
212 our (\@EXPORT_OK,\%EXPORT_TAGS,\@ISA,\$VERSION,\%errno,\$AUTOLOAD);
217 "\$Config{'archname'}-\$Config{'osvers'}" eq
218 "$Config{'archname'}-$Config{'osvers'}" or
219 die "Errno architecture ($Config{'archname'}-$Config{'osvers'}) does not match executable architecture (\$Config{'archname'}-\$Config{'osvers'})";
221 \$VERSION = "$VERSION";
222 \@ISA = qw(Exporter);
227 my @err = sort { $err{$a} <=> $err{$b} } keys %err;
228 map { $len = length if length > $len } @err;
230 my $j = "\@EXPORT_OK = qw(" . join(" ",keys %err) . ");\n";
231 $j =~ s/(.{50,70})\s/$1\n\t/g;
239 my $k = join(" ", grep { exists $err{$_} }
240 qw(E2BIG EACCES EADDRINUSE EADDRNOTAVAIL EAFNOSUPPORT
241 EAGAIN EALREADY EBADF EBUSY ECHILD ECONNABORTED
242 ECONNREFUSED ECONNRESET EDEADLK EDESTADDRREQ EDOM EDQUOT
243 EEXIST EFAULT EFBIG EHOSTDOWN EHOSTUNREACH EINPROGRESS
244 EINTR EINVAL EIO EISCONN EISDIR ELOOP EMFILE EMLINK
245 EMSGSIZE ENAMETOOLONG ENETDOWN ENETRESET ENETUNREACH
246 ENFILE ENOBUFS ENODEV ENOENT ENOEXEC ENOLCK ENOMEM
247 ENOPROTOOPT ENOSPC ENOSYS ENOTBLK ENOTCONN ENOTDIR
248 ENOTEMPTY ENOTSOCK ENOTTY ENXIO EOPNOTSUPP EPERM
249 EPFNOSUPPORT EPIPE EPROCLIM EPROTONOSUPPORT EPROTOTYPE
250 ERANGE EREMOTE ERESTART EROFS ESHUTDOWN ESOCKTNOSUPPORT
251 ESPIPE ESRCH ESTALE ETIMEDOUT ETOOMANYREFS ETXTBSY
252 EUSERS EWOULDBLOCK EXDEV));
254 $k =~ s/(.{50,70})\s/$1\n\t/g;
255 print "\t",$k,"\n )]\n);\n\n";
257 foreach $err (@err) {
258 printf "sub %s () { %d }\n",,$err,$err{$err};
263 sub TIEHASH { bless [] }
266 my ($self, $errname) = @_;
267 my $proto = prototype("Errno::$errname");
269 if (defined($proto) && $proto eq "") {
272 $errno = 0 unless $! == $errno;
279 Carp::confess("ERRNO hash is read only!");
287 while(($k,$v) = each %Errno::) {
288 my $proto = prototype("Errno::$k");
289 last if (defined($proto) && $proto eq "");
295 my $s = scalar keys %Errno::; # initialize iterator
300 my ($self, $errname) = @_;
301 my $proto = prototype($errname);
302 defined($proto) && $proto eq "";
312 Errno - System errno constants
316 use Errno qw(EINTR EIO :POSIX);
320 C<Errno> defines and conditionally exports all the error constants
321 defined in your system C<errno.h> include file. It has a single export
322 tag, C<:POSIX>, which will export all POSIX defined error numbers.
324 C<Errno> also makes C<%!> magic such that each element of C<%!> has a
325 non-zero value only if C<$!> is set to that value. For example:
329 unless (open(FH, "/fangorn/spouse")) {
331 warn "Get a wife!\n";
333 warn "This path is barred: $!";
337 If a specified constant C<EFOO> does not exist on the system, C<$!{EFOO}>
338 returns C<"">. You may use C<exists $!{EFOO}> to check whether the
339 constant is available on the system.
343 Importing a particular constant may not be very portable, because the
344 import will fail on platforms that do not have that constant. A more
345 portable way to set C<$!> to a valid value is to use:
347 if (exists &Errno::EFOO) {
353 Graham Barr <gbarr@pobox.com>
357 Copyright (c) 1997-8 Graham Barr. All rights reserved.
358 This program is free software; you can redistribute it and/or modify it
359 under the same terms as Perl itself.