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 $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;
46 if /^\s*#\s*define\s+(E\w+)\s+/;
54 unless (defined $cppstdin) {
56 $cppstdin = $Config{cppstdin};
57 my $upup_cppstdin = File::Spec->catfile(File::Spec->updir,
60 my $cppstdin_is_wrapper =
61 ($cppstdin eq 'cppstdin'
63 and -x $upup_cppstdin);
64 $cppstdin = $upup_cppstdin if $cppstdin_is_wrapper;
66 return "$cppstdin $Config{cppflags} $Config{cppminus}";
71 # VMS keeps its include files in system libraries (well, except for Gcc)
73 if ($Config{vms_cc_type} eq 'decc') {
74 $file{'Sys$Library:DECC$RTLDEF.TLB'} = 1;
75 } elsif ($Config{vms_cc_type} eq 'vaxc') {
76 $file{'Sys$Library:vaxcdef.tlb'} = 1;
77 } elsif ($Config{vms_cc_type} eq 'gcc') {
78 $file{'gnu_cc_include:[000000]errno.h'} = 1;
80 } elsif ($^O eq 'os390') {
81 # OS/390 C compiler doesn't generate #file or #line directives
82 $file{'/usr/include/errno.h'} = 1;
83 } elsif ($^O eq 'vmesa') {
84 # OS/390 C compiler doesn't generate #file or #line directives
85 $file{'../../vmesa/errno.h'} = 1;
86 } elsif ($Config{archname} eq 'epoc') {
87 # Watch out for cross compiling for EPOC (usually done on linux)
88 $file{'/usr/local/epoc/include/libc/sys/errno.h'} = 1;
89 } elsif ($^O eq 'linux') {
90 # Some Linuxes have weird errno.hs which generate
91 # no #file or #line directives
92 $file{'/usr/include/errno.h'} = 1;
94 open(CPPI,"> errno.c") or
95 die "Cannot open errno.c";
97 print CPPI "#include <errno.h>\n";
101 # invoke CPP and read the output
102 if ($^O eq 'MSWin32') {
103 open(CPPO,"$Config{cpprun} $Config{cppflags} errno.c |") or
104 die "Cannot run '$Config{cpprun} $Config{cppflags} errno.c'";
106 my $cpp = default_cpp();
107 open(CPPO,"$cpp < errno.c |") or
108 die "Cannot exec $cpp";
112 if ($^O eq 'MSWin32' and $Config{cc} =~ /^bcc/i) {
113 $pat = '^/\*\s+(.+)\s+\d+\s*:\s+\*/';
116 $pat = '^#\s*(?:line)?\s*\d+\s+"([^"]+)"';
119 if ($^O eq 'os2' or $^O eq 'MSWin32') {
127 $file{$1} = 1 if /$pat/o;
140 die "No error definitions found" unless keys %err;
142 # create the CPP input
144 open(CPPI,"> errno.c") or
145 die "Cannot open errno.c";
147 print CPPI "#include <errno.h>\n";
149 foreach $err (keys %err) {
150 print CPPI '"',$err,'" [[',$err,']]',"\n";
155 # invoke CPP and read the output
158 my $cpp = "$Config{cppstdin} $Config{cppflags} $Config{cppminus}";
159 $cpp =~ s/sys\$input//i;
160 open(CPPO,"$cpp errno.c |") or
161 die "Cannot exec $Config{cppstdin}";
162 } elsif ($^O eq 'MSWin32') {
163 open(CPPO,"$Config{cpprun} $Config{cppflags} errno.c |") or
164 die "Cannot run '$Config{cpprun} $Config{cppflags} errno.c'";
166 my $cpp = default_cpp();
167 open(CPPO,"$cpp < errno.c |")
168 or die "Cannot exec $cpp";
175 next unless ($name, $expr) = /"(.*?)"\s*\[\s*\[\s*(.*?)\s*\]\s*\]/;
176 next if $name eq $expr;
177 $err{$name} = eval $expr;
185 # This file is auto-generated. ***ANY*** changes here will be lost
189 our (\@EXPORT_OK,\%EXPORT_TAGS,\@ISA,\$VERSION,\%errno,\$AUTOLOAD);
194 "\$Config{'archname'}-\$Config{'osvers'}" eq
195 "$Config{'archname'}-$Config{'osvers'}" or
196 die "Errno architecture ($Config{'archname'}-$Config{'osvers'}) does not match executable architecture (\$Config{'archname'}-\$Config{'osvers'})";
198 \$VERSION = "$VERSION";
199 \@ISA = qw(Exporter);
204 my @err = sort { $err{$a} <=> $err{$b} } keys %err;
205 map { $len = length if length > $len } @err;
207 my $j = "\@EXPORT_OK = qw(" . join(" ",keys %err) . ");\n";
208 $j =~ s/(.{50,70})\s/$1\n\t/g;
216 my $k = join(" ", grep { exists $err{$_} }
217 qw(E2BIG EACCES EADDRINUSE EADDRNOTAVAIL EAFNOSUPPORT
218 EAGAIN EALREADY EBADF EBUSY ECHILD ECONNABORTED
219 ECONNREFUSED ECONNRESET EDEADLK EDESTADDRREQ EDOM EDQUOT
220 EEXIST EFAULT EFBIG EHOSTDOWN EHOSTUNREACH EINPROGRESS
221 EINTR EINVAL EIO EISCONN EISDIR ELOOP EMFILE EMLINK
222 EMSGSIZE ENAMETOOLONG ENETDOWN ENETRESET ENETUNREACH
223 ENFILE ENOBUFS ENODEV ENOENT ENOEXEC ENOLCK ENOMEM
224 ENOPROTOOPT ENOSPC ENOSYS ENOTBLK ENOTCONN ENOTDIR
225 ENOTEMPTY ENOTSOCK ENOTTY ENXIO EOPNOTSUPP EPERM
226 EPFNOSUPPORT EPIPE EPROCLIM EPROTONOSUPPORT EPROTOTYPE
227 ERANGE EREMOTE ERESTART EROFS ESHUTDOWN ESOCKTNOSUPPORT
228 ESPIPE ESRCH ESTALE ETIMEDOUT ETOOMANYREFS ETXTBSY
229 EUSERS EWOULDBLOCK EXDEV));
231 $k =~ s/(.{50,70})\s/$1\n\t/g;
232 print "\t",$k,"\n )]\n);\n\n";
234 foreach $err (@err) {
235 printf "sub %s () { %d }\n",,$err,$err{$err};
240 sub TIEHASH { bless [] }
243 my ($self, $errname) = @_;
244 my $proto = prototype("Errno::$errname");
246 if (defined($proto) && $proto eq "") {
249 $errno = 0 unless $! == $errno;
256 Carp::confess("ERRNO hash is read only!");
264 while(($k,$v) = each %Errno::) {
265 my $proto = prototype("Errno::$k");
266 last if (defined($proto) && $proto eq "");
272 my $s = scalar keys %Errno::; # initialize iterator
277 my ($self, $errname) = @_;
278 my $proto = prototype($errname);
279 defined($proto) && $proto eq "";
289 Errno - System errno constants
293 use Errno qw(EINTR EIO :POSIX);
297 C<Errno> defines and conditionally exports all the error constants
298 defined in your system C<errno.h> include file. It has a single export
299 tag, C<:POSIX>, which will export all POSIX defined error numbers.
301 C<Errno> also makes C<%!> magic such that each element of C<%!> has a
302 non-zero value only if C<$!> is set to that value. For example:
306 unless (open(FH, "/fangorn/spouse")) {
308 warn "Get a wife!\n";
310 warn "This path is barred: $!";
314 If a specified constant C<EFOO> does not exist on the system, C<$!{EFOO}>
315 returns C<"">. You may use C<exists $!{EFOO}> to check whether the
316 constant is available on the system.
320 Importing a particular constant may not be very portable, because the
321 import will fail on platforms that do not have that constant. A more
322 portable way to set C<$!> to a valid value is to use:
324 if (exists &Errno::EFOO) {
330 Graham Barr <gbarr@pobox.com>
334 Copyright (c) 1997-8 Graham Barr. All rights reserved.
335 This program is free software; you can redistribute it and/or modify it
336 under the same terms as Perl itself.