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 temporary 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+/;
50 unless (defined $cppstdin) {
52 $cppstdin = $Config{cppstdin};
53 my $upup_cppstdin = File::Spec->catfile(File::Spec->updir,
56 my $cppstdin_is_wrapper =
57 ($cppstdin eq 'cppstdin'
59 and -x $upup_cppstdin);
60 $cppstdin = $upup_cppstdin if $cppstdin_is_wrapper;
62 return "$cppstdin $Config{cppflags} $Config{cppminus}";
67 # VMS keeps its include files in system libraries (well, except for Gcc)
69 if ($Config{vms_cc_type} eq 'decc') {
70 $file{'Sys$Library:DECC$RTLDEF.TLB'} = 1;
71 } elsif ($Config{vms_cc_type} eq 'vaxc') {
72 $file{'Sys$Library:vaxcdef.tlb'} = 1;
73 } elsif ($Config{vms_cc_type} eq 'gcc') {
74 $file{'gnu_cc_include:[000000]errno.h'} = 1;
76 } elsif ($^O eq 'os390') {
77 # OS/390 C compiler doesn't generate #file or #line directives
78 $file{'/usr/include/errno.h'} = 1;
79 } elsif ($^O eq 'vmesa') {
80 # OS/390 C compiler doesn't generate #file or #line directives
81 $file{'../../vmesa/errno.h'} = 1;
83 open(CPPI,"> errno.c") or
84 die "Cannot open errno.c";
86 print CPPI "#include <errno.h>\n";
90 # invoke CPP and read the output
91 if ($^O eq 'MSWin32') {
92 open(CPPO,"$Config{cpprun} $Config{cppflags} errno.c |") or
93 die "Cannot run '$Config{cpprun} $Config{cppflags} errno.c'";
95 my $cpp = default_cpp();
96 open(CPPO,"$cpp < errno.c |") or
97 die "Cannot exec $cpp";
101 if ($^O eq 'MSWin32' and $Config{cc} =~ /^bcc/i) {
102 $pat = '^/\*\s+(.+)\s+\d+\s*:\s+\*/';
105 $pat = '^#(?:line)?\s*\d+\s+"([^"]+)"';
116 $file{$1} = 1 if /$pat/o;
129 die "No error definitions found" unless keys %err;
131 # create the CPP input
133 open(CPPI,"> errno.c") or
134 die "Cannot open errno.c";
136 print CPPI "#include <errno.h>\n";
138 foreach $err (keys %err) {
139 print CPPI '"',$err,'" [[',$err,']]',"\n";
144 # invoke CPP and read the output
147 my $cpp = "$Config{cppstdin} $Config{cppflags} $Config{cppminus}";
148 $cpp =~ s/sys\$input//i;
149 open(CPPO,"$cpp errno.c |") or
150 die "Cannot exec $Config{cppstdin}";
151 } elsif ($^O eq 'MSWin32') {
152 open(CPPO,"$Config{cpprun} $Config{cppflags} errno.c |") or
153 die "Cannot run '$Config{cpprun} $Config{cppflags} errno.c'";
155 my $cpp = default_cpp();
156 open(CPPO,"$cpp < errno.c |")
157 or die "Cannot exec $cpp";
164 next unless ($name, $expr) = /"(.*?)"\s*\[\s*\[\s*(.*?)\s*\]\s*\]/;
165 next if $name eq $expr;
166 $err{$name} = eval $expr;
174 # This file is auto-generated. ***ANY*** changes here will be lost
178 use vars qw(\@EXPORT_OK \%EXPORT_TAGS \@ISA \$VERSION \%errno \$AUTOLOAD);
183 \$Config{'myarchname'} eq "$Config{'myarchname'}" or
184 die "Errno architecture ($Config{'myarchname'}) does not match executable architecture (\$Config{'myarchname'})";
186 \$VERSION = "$VERSION";
187 \@ISA = qw(Exporter);
192 my @err = sort { $err{$a} <=> $err{$b} } keys %err;
193 map { $len = length if length > $len } @err;
195 my $j = "\@EXPORT_OK = qw(" . join(" ",keys %err) . ");\n";
196 $j =~ s/(.{50,70})\s/$1\n\t/g;
204 my $k = join(" ", grep { exists $err{$_} }
205 qw(E2BIG EACCES EADDRINUSE EADDRNOTAVAIL EAFNOSUPPORT
206 EAGAIN EALREADY EBADF EBUSY ECHILD ECONNABORTED
207 ECONNREFUSED ECONNRESET EDEADLK EDESTADDRREQ EDOM EDQUOT
208 EEXIST EFAULT EFBIG EHOSTDOWN EHOSTUNREACH EINPROGRESS
209 EINTR EINVAL EIO EISCONN EISDIR ELOOP EMFILE EMLINK
210 EMSGSIZE ENAMETOOLONG ENETDOWN ENETRESET ENETUNREACH
211 ENFILE ENOBUFS ENODEV ENOENT ENOEXEC ENOLCK ENOMEM
212 ENOPROTOOPT ENOSPC ENOSYS ENOTBLK ENOTCONN ENOTDIR
213 ENOTEMPTY ENOTSOCK ENOTTY ENXIO EOPNOTSUPP EPERM
214 EPFNOSUPPORT EPIPE EPROCLIM EPROTONOSUPPORT EPROTOTYPE
215 ERANGE EREMOTE ERESTART EROFS ESHUTDOWN ESOCKTNOSUPPORT
216 ESPIPE ESRCH ESTALE ETIMEDOUT ETOOMANYREFS ETXTBSY
217 EUSERS EWOULDBLOCK EXDEV));
219 $k =~ s/(.{50,70})\s/$1\n\t/g;
220 print "\t",$k,"\n )]\n);\n\n";
222 foreach $err (@err) {
223 printf "sub %s () { %d }\n",,$err,$err{$err};
228 sub TIEHASH { bless [] }
231 my ($self, $errname) = @_;
232 my $proto = prototype("Errno::$errname");
233 if (defined($proto) && $proto eq "") {
235 return $! == &$errname;
238 Carp::confess("No errno $errname");
243 Carp::confess("ERRNO hash is read only!");
251 while(($k,$v) = each %Errno::) {
252 my $proto = prototype("Errno::$k");
253 last if (defined($proto) && $proto eq "");
260 my $s = scalar keys %Errno::;
265 my ($self, $errname) = @_;
266 my $proto = prototype($errname);
267 defined($proto) && $proto eq "";
277 Errno - System errno constants
281 use Errno qw(EINTR EIO :POSIX);
285 C<Errno> defines and conditionally exports all the error constants
286 defined in your system C<errno.h> include file. It has a single export
287 tag, C<:POSIX>, which will export all POSIX defined error numbers.
289 C<Errno> also makes C<%!> magic such that each element of C<%!> has a non-zero
290 value only if C<$!> is set to that value, eg
294 unless (open(FH, "/fangorn/spouse")) {
296 warn "Get a wife!\n";
298 warn "This path is barred: $!";
304 Graham Barr <gbarr@pobox.com>
308 Copyright (c) 1997-8 Graham Barr. All rights reserved.
309 This program is free software; you can redistribute it and/or modify it
310 under the same terms as Perl itself.