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 warn "Cannot open '$file'";
40 if /^\s*#\s*define\s+(E\w+)\s+/;
47 # VMS keeps its include files in system libraries (well, except for Gcc)
49 if ($Config{vms_cc_type} eq 'decc') {
50 $file{'Sys$Library:DECC$RTLDEF.TLB'} = 1;
51 } elsif ($Config{vms_cc_type} eq 'vaxc') {
52 $file{'Sys$Library:vaxcdef.tlb'} = 1;
53 } elsif ($Config{vms_cc_type} eq 'gcc') {
54 $file{'gnu_cc_include:[000000]errno.h'} = 1;
57 open(CPPI,"> errno.c") or
58 die "Cannot open errno.c";
60 print CPPI "#include <errno.h>\n";
64 # invoke CPP and read the output
66 open(CPPO,"$Config{cpprun} $Config{cppflags} errno.c |") or
67 die "Cannot exec $Config{cpprun}";
70 if ($^O eq 'MSWin32' and $Config{cc} =~ /^bcc/i) {
71 $pat = '^/\*\s+(.+)\s+\d+\s*:\s+\*/';
74 $pat = '^#(?:line)?\s*\d+\s+"([^"]+)"';
77 $file{$1} = 1 if /$pat/o;
87 # create the CPP input
89 open(CPPI,"> errno.c") or
90 die "Cannot open errno.c";
92 print CPPI "#include <errno.h>\n";
94 foreach $err (keys %err) {
95 print CPPI '"',$err,'" [[',$err,']]',"\n";
100 # invoke CPP and read the output
103 my $cpp = "$Config{cppstdin} $Config{cppflags} $Config{cppminus}";
104 $cpp =~ s/sys\$input//i;
105 open(CPPO,"$cpp errno.c |") or
106 die "Cannot exec $Config{cppstdin}";
107 } elsif($^O eq 'next') {
108 # NeXT will do syntax checking unless it is reading from stdin
109 my $cpp = "$Config{cppstdin} $Config{cppflags} $Config{cppminus}";
110 open(CPPO,"$cpp < errno.c |")
111 or die "Cannot exec $cpp";
113 open(CPPO,"$Config{cpprun} $Config{cppflags} errno.c |") or
114 die "Cannot exec $Config{cpprun}";
121 next unless ($name, $expr) = /"(.*?)"\s*\[\s*\[\s*(.*?)\s*\]\s*\]/;
122 next if $name eq $expr;
123 $err{$name} = eval $expr;
131 # This file is auto-generated. ***ANY*** changes here will be lost
135 use vars qw(\@EXPORT_OK \%EXPORT_TAGS \@ISA \$VERSION \%errno \$AUTOLOAD);
140 \$Config{'myarchname'} eq "$Config{'myarchname'}" or
141 die "Errno architecture ($Config{'myarchname'}) does not match executable architecture (\$Config{'myarchname'})";
143 \$VERSION = "$VERSION";
144 \@ISA = qw(Exporter);
149 my @err = sort { $err{$a} <=> $err{$b} } keys %err;
150 map { $len = length if length > $len } @err;
152 my $j = "\@EXPORT_OK = qw(" . join(" ",keys %err) . ");\n";
153 $j =~ s/(.{50,70})\s/$1\n\t/g;
161 my $k = join(" ", grep { exists $err{$_} }
162 qw(E2BIG EACCES EADDRINUSE EADDRNOTAVAIL EAFNOSUPPORT
163 EAGAIN EALREADY EBADF EBUSY ECHILD ECONNABORTED
164 ECONNREFUSED ECONNRESET EDEADLK EDESTADDRREQ EDOM EDQUOT
165 EEXIST EFAULT EFBIG EHOSTDOWN EHOSTUNREACH EINPROGRESS
166 EINTR EINVAL EIO EISCONN EISDIR ELOOP EMFILE EMLINK
167 EMSGSIZE ENAMETOOLONG ENETDOWN ENETRESET ENETUNREACH
168 ENFILE ENOBUFS ENODEV ENOENT ENOEXEC ENOLCK ENOMEM
169 ENOPROTOOPT ENOSPC ENOSYS ENOTBLK ENOTCONN ENOTDIR
170 ENOTEMPTY ENOTSOCK ENOTTY ENXIO EOPNOTSUPP EPERM
171 EPFNOSUPPORT EPIPE EPROCLIM EPROTONOSUPPORT EPROTOTYPE
172 ERANGE EREMOTE ERESTART EROFS ESHUTDOWN ESOCKTNOSUPPORT
173 ESPIPE ESRCH ESTALE ETIMEDOUT ETOOMANYREFS ETXTBSY
174 EUSERS EWOULDBLOCK EXDEV));
176 $k =~ s/(.{50,70})\s/$1\n\t/g;
177 print "\t",$k,"\n )]\n);\n\n";
179 foreach $err (@err) {
180 printf "sub %s () { %d }\n",,$err,$err{$err};
185 sub TIEHASH { bless [] }
188 my ($self, $errname) = @_;
189 my $proto = prototype("Errno::$errname");
190 if (defined($proto) && $proto eq "") {
192 return $! == &$errname;
195 Carp::confess("No errno $errname");
200 Carp::confess("ERRNO hash is read only!");
208 while(($k,$v) = each %Errno::) {
209 my $proto = prototype("Errno::$k");
210 last if (defined($proto) && $proto eq "");
217 my $s = scalar keys %Errno::;
222 my ($self, $errname) = @_;
223 my $proto = prototype($errname);
224 defined($proto) && $proto eq "";
234 Errno - System errno constants
238 use Errno qw(EINTR EIO :POSIX);
242 C<Errno> defines and conditionally exports all the error constants
243 defined in your system C<errno.h> include file. It has a single export
244 tag, C<:POSIX>, which will export all POSIX defined error numbers.
246 C<Errno> also makes C<%!> magic such that each element of C<%!> has a non-zero
247 value only if C<$!> is set to that value, eg
251 unless (open(FH, "/fangorn/spouse")) {
253 warn "Get a wife!\n";
255 warn "This path is barred: $!";
261 Graham Barr <gbarr@pobox.com>
265 Copyright (c) 1997-8 Graham Barr. All rights reserved.
266 This program is free software; you can redistribute it and/or modify it
267 under the same terms as Perl itself.