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;
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'";
33 unless(open(FH,"< $file")) {
34 # This file could be a temporay file created by cppstdin
35 # so only warn under -w, and return
36 warn "Cannot open '$file'" if $^W;
42 if /^\s*#\s*define\s+(E\w+)\s+/;
49 # VMS keeps its include files in system libraries (well, except for Gcc)
51 if ($Config{vms_cc_type} eq 'decc') {
52 $file{'Sys$Library:DECC$RTLDEF.TLB'} = 1;
53 } elsif ($Config{vms_cc_type} eq 'vaxc') {
54 $file{'Sys$Library:vaxcdef.tlb'} = 1;
55 } elsif ($Config{vms_cc_type} eq 'gcc') {
56 $file{'gnu_cc_include:[000000]errno.h'} = 1;
58 } elsif ($^O eq 'os390') {
59 # OS/390 C compiler doesn't generate #file or #line directives
60 $file{'/usr/include/errno.h'} = 1;
62 open(CPPI,"> errno.c") or
63 die "Cannot open errno.c";
65 print CPPI "#include <errno.h>\n";
69 # invoke CPP and read the output
70 if ($^O eq 'MSWin32') {
71 open(CPPO,"$Config{cpprun} $Config{cppflags} errno.c |") or
72 die "Cannot run '$Config{cpprun} $Config{cppflags} errno.c'";
74 my $cpp = "$Config{cppstdin} $Config{cppflags} $Config{cppminus}";
75 open(CPPO,"$cpp < errno.c |") or
76 die "Cannot exec $cpp";
80 if ($^O eq 'MSWin32' and $Config{cc} =~ /^bcc/i) {
81 $pat = '^/\*\s+(.+)\s+\d+\s*:\s+\*/';
84 $pat = '^#(?:line)?\s*\d+\s+"([^"]+)"';
87 $file{$1} = 1 if /$pat/o;
97 # create the CPP input
99 open(CPPI,"> errno.c") or
100 die "Cannot open errno.c";
102 print CPPI "#include <errno.h>\n";
104 foreach $err (keys %err) {
105 print CPPI '"',$err,'" [[',$err,']]',"\n";
110 # invoke CPP and read the output
113 my $cpp = "$Config{cppstdin} $Config{cppflags} $Config{cppminus}";
114 $cpp =~ s/sys\$input//i;
115 open(CPPO,"$cpp errno.c |") or
116 die "Cannot exec $Config{cppstdin}";
117 } elsif ($^O eq 'MSWin32') {
118 open(CPPO,"$Config{cpprun} $Config{cppflags} errno.c |") or
119 die "Cannot run '$Config{cpprun} $Config{cppflags} errno.c'";
121 my $cpp = "$Config{cppstdin} $Config{cppflags} $Config{cppminus}";
122 open(CPPO,"$cpp < errno.c |")
123 or die "Cannot exec $cpp";
130 next unless ($name, $expr) = /"(.*?)"\s*\[\s*\[\s*(.*?)\s*\]\s*\]/;
131 next if $name eq $expr;
132 $err{$name} = eval $expr;
140 # This file is auto-generated. ***ANY*** changes here will be lost
144 use vars qw(\@EXPORT_OK \%EXPORT_TAGS \@ISA \$VERSION \%errno \$AUTOLOAD);
149 \$Config{'myarchname'} eq "$Config{'myarchname'}" or
150 die "Errno architecture ($Config{'myarchname'}) does not match executable architecture (\$Config{'myarchname'})";
152 \$VERSION = "$VERSION";
153 \@ISA = qw(Exporter);
158 my @err = sort { $err{$a} <=> $err{$b} } keys %err;
159 map { $len = length if length > $len } @err;
161 my $j = "\@EXPORT_OK = qw(" . join(" ",keys %err) . ");\n";
162 $j =~ s/(.{50,70})\s/$1\n\t/g;
170 my $k = join(" ", grep { exists $err{$_} }
171 qw(E2BIG EACCES EADDRINUSE EADDRNOTAVAIL EAFNOSUPPORT
172 EAGAIN EALREADY EBADF EBUSY ECHILD ECONNABORTED
173 ECONNREFUSED ECONNRESET EDEADLK EDESTADDRREQ EDOM EDQUOT
174 EEXIST EFAULT EFBIG EHOSTDOWN EHOSTUNREACH EINPROGRESS
175 EINTR EINVAL EIO EISCONN EISDIR ELOOP EMFILE EMLINK
176 EMSGSIZE ENAMETOOLONG ENETDOWN ENETRESET ENETUNREACH
177 ENFILE ENOBUFS ENODEV ENOENT ENOEXEC ENOLCK ENOMEM
178 ENOPROTOOPT ENOSPC ENOSYS ENOTBLK ENOTCONN ENOTDIR
179 ENOTEMPTY ENOTSOCK ENOTTY ENXIO EOPNOTSUPP EPERM
180 EPFNOSUPPORT EPIPE EPROCLIM EPROTONOSUPPORT EPROTOTYPE
181 ERANGE EREMOTE ERESTART EROFS ESHUTDOWN ESOCKTNOSUPPORT
182 ESPIPE ESRCH ESTALE ETIMEDOUT ETOOMANYREFS ETXTBSY
183 EUSERS EWOULDBLOCK EXDEV));
185 $k =~ s/(.{50,70})\s/$1\n\t/g;
186 print "\t",$k,"\n )]\n);\n\n";
188 foreach $err (@err) {
189 printf "sub %s () { %d }\n",,$err,$err{$err};
194 sub TIEHASH { bless [] }
197 my ($self, $errname) = @_;
198 my $proto = prototype("Errno::$errname");
199 if (defined($proto) && $proto eq "") {
201 return $! == &$errname;
204 Carp::confess("No errno $errname");
209 Carp::confess("ERRNO hash is read only!");
217 while(($k,$v) = each %Errno::) {
218 my $proto = prototype("Errno::$k");
219 last if (defined($proto) && $proto eq "");
226 my $s = scalar keys %Errno::;
231 my ($self, $errname) = @_;
232 my $proto = prototype($errname);
233 defined($proto) && $proto eq "";
243 Errno - System errno constants
247 use Errno qw(EINTR EIO :POSIX);
251 C<Errno> defines and conditionally exports all the error constants
252 defined in your system C<errno.h> include file. It has a single export
253 tag, C<:POSIX>, which will export all POSIX defined error numbers.
255 C<Errno> also makes C<%!> magic such that each element of C<%!> has a non-zero
256 value only if C<$!> is set to that value, eg
260 unless (open(FH, "/fangorn/spouse")) {
262 warn "Get a wife!\n";
264 warn "This path is barred: $!";
270 Graham Barr <gbarr@pobox.com>
274 Copyright (c) 1997-8 Graham Barr. All rights reserved.
275 This program is free software; you can redistribute it and/or modify it
276 under the same terms as Perl itself.