1 use ExtUtils::MakeMaker;
11 unlink "Errno.pm" if -f "Errno.pm";
12 open OUT, ">Errno.pm" or die "Cannot open Errno.pm: $!";
15 foreach $file (get_files()) {
19 unlink "errno.c" if -f "errno.c";
24 return unless defined $file and -f $file;
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 # With the -dM option, gcc outputs every #define it finds
34 unless(open(FH,"$Config{cc} -E -dM $file |")) {
35 warn "Cannot open '$file'";
39 unless(open(FH,"< $file")) {
40 # This file could be a temporary file created by cppstdin
41 # so only warn under -w, and return
42 warn "Cannot open '$file'" if $^W;
48 if /^\s*#\s*define\s+(E\w+)\s+/;
56 unless (defined $cppstdin) {
58 $cppstdin = $Config{cppstdin};
59 my $upup_cppstdin = File::Spec->catfile(File::Spec->updir,
62 my $cppstdin_is_wrapper =
63 ($cppstdin eq 'cppstdin'
65 and -x $upup_cppstdin);
66 $cppstdin = $upup_cppstdin if $cppstdin_is_wrapper;
68 return "$cppstdin $Config{cppflags} $Config{cppminus}";
73 # VMS keeps its include files in system libraries (well, except for Gcc)
75 if ($Config{vms_cc_type} eq 'decc') {
76 $file{'Sys$Library:DECC$RTLDEF.TLB'} = 1;
77 } elsif ($Config{vms_cc_type} eq 'vaxc') {
78 $file{'Sys$Library:vaxcdef.tlb'} = 1;
79 } elsif ($Config{vms_cc_type} eq 'gcc') {
80 $file{'gnu_cc_include:[000000]errno.h'} = 1;
82 } elsif ($^O eq 'os390') {
83 # OS/390 C compiler doesn't generate #file or #line directives
84 $file{'/usr/include/errno.h'} = 1;
85 } elsif ($^O eq 'vmesa') {
86 # OS/390 C compiler doesn't generate #file or #line directives
87 $file{'../../vmesa/errno.h'} = 1;
88 } elsif ($^O eq 'linux') {
89 # Some Linuxes have weird errno.hs which generate
90 # no #file or #line directives
91 $file{'/usr/include/errno.h'} = 1;
93 open(CPPI,"> errno.c") or
94 die "Cannot open errno.c";
96 print CPPI "#include <errno.h>\n";
100 # invoke CPP and read the output
101 if ($^O eq 'MSWin32') {
102 open(CPPO,"$Config{cpprun} $Config{cppflags} errno.c |") or
103 die "Cannot run '$Config{cpprun} $Config{cppflags} errno.c'";
105 my $cpp = default_cpp();
106 open(CPPO,"$cpp < errno.c |") or
107 die "Cannot exec $cpp";
111 if ($^O eq 'MSWin32' and $Config{cc} =~ /^bcc/i) {
112 $pat = '^/\*\s+(.+)\s+\d+\s*:\s+\*/';
115 $pat = '^#\s*(?:line)?\s*\d+\s+"([^"]+)"';
118 if ($^O eq 'os2' or $^O eq 'MSWin32') {
126 $file{$1} = 1 if /$pat/o;
139 die "No error definitions found" unless keys %err;
141 # create the CPP input
143 open(CPPI,"> errno.c") or
144 die "Cannot open errno.c";
146 print CPPI "#include <errno.h>\n";
148 foreach $err (keys %err) {
149 print CPPI '"',$err,'" [[',$err,']]',"\n";
154 # invoke CPP and read the output
157 my $cpp = "$Config{cppstdin} $Config{cppflags} $Config{cppminus}";
158 $cpp =~ s/sys\$input//i;
159 open(CPPO,"$cpp errno.c |") or
160 die "Cannot exec $Config{cppstdin}";
161 } elsif ($^O eq 'MSWin32') {
162 open(CPPO,"$Config{cpprun} $Config{cppflags} errno.c |") or
163 die "Cannot run '$Config{cpprun} $Config{cppflags} errno.c'";
165 my $cpp = default_cpp();
166 open(CPPO,"$cpp < errno.c |")
167 or die "Cannot exec $cpp";
174 next unless ($name, $expr) = /"(.*?)"\s*\[\s*\[\s*(.*?)\s*\]\s*\]/;
175 next if $name eq $expr;
176 $err{$name} = eval $expr;
184 # This file is auto-generated. ***ANY*** changes here will be lost
188 use vars qw(\@EXPORT_OK \%EXPORT_TAGS \@ISA \$VERSION \%errno \$AUTOLOAD);
193 "\$Config{'archname'}-\$Config{'osvers'}" eq
194 "$Config{'archname'}-$Config{'osvers'}" or
195 die "Errno architecture ($Config{'archname'}-$Config{'osvers'}) does not match executable architecture (\$Config{'archname'}-\$Config{'osvers'})";
197 \$VERSION = "$VERSION";
198 \@ISA = qw(Exporter);
203 my @err = sort { $err{$a} <=> $err{$b} } keys %err;
204 map { $len = length if length > $len } @err;
206 my $j = "\@EXPORT_OK = qw(" . join(" ",keys %err) . ");\n";
207 $j =~ s/(.{50,70})\s/$1\n\t/g;
215 my $k = join(" ", grep { exists $err{$_} }
216 qw(E2BIG EACCES EADDRINUSE EADDRNOTAVAIL EAFNOSUPPORT
217 EAGAIN EALREADY EBADF EBUSY ECHILD ECONNABORTED
218 ECONNREFUSED ECONNRESET EDEADLK EDESTADDRREQ EDOM EDQUOT
219 EEXIST EFAULT EFBIG EHOSTDOWN EHOSTUNREACH EINPROGRESS
220 EINTR EINVAL EIO EISCONN EISDIR ELOOP EMFILE EMLINK
221 EMSGSIZE ENAMETOOLONG ENETDOWN ENETRESET ENETUNREACH
222 ENFILE ENOBUFS ENODEV ENOENT ENOEXEC ENOLCK ENOMEM
223 ENOPROTOOPT ENOSPC ENOSYS ENOTBLK ENOTCONN ENOTDIR
224 ENOTEMPTY ENOTSOCK ENOTTY ENXIO EOPNOTSUPP EPERM
225 EPFNOSUPPORT EPIPE EPROCLIM EPROTONOSUPPORT EPROTOTYPE
226 ERANGE EREMOTE ERESTART EROFS ESHUTDOWN ESOCKTNOSUPPORT
227 ESPIPE ESRCH ESTALE ETIMEDOUT ETOOMANYREFS ETXTBSY
228 EUSERS EWOULDBLOCK EXDEV));
230 $k =~ s/(.{50,70})\s/$1\n\t/g;
231 print "\t",$k,"\n )]\n);\n\n";
233 foreach $err (@err) {
234 printf "sub %s () { %d }\n",,$err,$err{$err};
239 sub TIEHASH { bless [] }
242 my ($self, $errname) = @_;
243 my $proto = prototype("Errno::$errname");
245 if (defined($proto) && $proto eq "") {
248 $errno = 0 unless $! == $errno;
255 Carp::confess("ERRNO hash is read only!");
263 while(($k,$v) = each %Errno::) {
264 my $proto = prototype("Errno::$k");
265 last if (defined($proto) && $proto eq "");
271 my $s = scalar keys %Errno::; # initialize iterator
276 my ($self, $errname) = @_;
277 my $proto = prototype($errname);
278 defined($proto) && $proto eq "";
288 Errno - System errno constants
292 use Errno qw(EINTR EIO :POSIX);
296 C<Errno> defines and conditionally exports all the error constants
297 defined in your system C<errno.h> include file. It has a single export
298 tag, C<:POSIX>, which will export all POSIX defined error numbers.
300 C<Errno> also makes C<%!> magic such that each element of C<%!> has a
301 non-zero value only if C<$!> is set to that value. For example:
305 unless (open(FH, "/fangorn/spouse")) {
307 warn "Get a wife!\n";
309 warn "This path is barred: $!";
313 If a specified constant C<EFOO> does not exist on the system, C<$!{EFOO}>
314 returns C<"">. You may use C<exists $!{EFOO}> to check whether the
315 constant is available on the system.
319 Importing a particular constant may not be very portable, because the
320 import will fail on platforms that do not have that constant. A more
321 portable way to set C<$!> to a valid value is to use:
323 if (exists &Errno::EFOO) {
329 Graham Barr <gbarr@pobox.com>
333 Copyright (c) 1997-8 Graham Barr. All rights reserved.
334 This program is free software; you can redistribute it and/or modify it
335 under the same terms as Perl itself.