2 use ExtUtils::MakeMaker;
12 unlink "Errno.pm" if -f "Errno.pm";
13 open OUT, ">Errno.pm" or die "Cannot open Errno.pm: $!";
16 foreach $file (get_files()) {
20 unlink "errno.c" if -f "errno.c";
25 return unless defined $file;
28 if (($^O eq 'VMS') && ($Config{vms_cc_type} ne 'gnuc')) {
29 unless(open(FH," LIBRARY/EXTRACT=ERRNO/OUTPUT=SYS\$OUTPUT $file |")) {
30 warn "Cannot open '$file'";
34 unless(open(FH,"< $file")) {
35 warn "Cannot open '$file'";
41 if /^#\s*define\s+(E\w+)\s+/;
48 # VMS keeps its include files in system libraries (well, except for Gcc)
50 if ($Config{vms_cc_type} eq 'decc') {
51 $file{'Sys$Library:DECC$RTLDEF.TLB'} = 1;
52 } elsif ($Config{vms_cc_type} eq 'vaxc') {
53 $file{'Sys$Library:vaxcdef.tlb'} = 1;
54 } elsif ($Config{vms_cc_type} eq 'gcc') {
55 $file{'gnu_cc_include:[000000]errno.h'} = 1;
58 open(CPPI,"> errno.c") or
59 die "Cannot open errno.c";
61 print CPPI "#include <errno.h>\n";
65 # invoke CPP and read the output
67 open(CPPO,"$Config{cpprun} $Config{cppflags} errno.c |") or
68 die "Cannot exec $Config{cpprun}";
71 if ($^O eq 'MSWin32' and $Config{cc} =~ /^bcc/i) {
72 $pat = '^/\*\s+(.+)\s+\d+\s*:\s+\*/';
75 $pat = '^#(?:line)?\s+\d+\s+"([^"]+)"';
78 $file{$1} = 1 if /$pat/o;
88 # create the CPP input
90 open(CPPI,"> errno.c") or
91 die "Cannot open errno.c";
93 print CPPI "#include <errno.h>\n";
95 foreach $err (keys %err) {
96 print CPPI '"',$err,'" [[',$err,']]',"\n";
101 # 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}";
108 open(CPPO,"$Config{cpprun} $Config{cppflags} errno.c |") or
109 die "Cannot exec $Config{cpprun}";
116 next unless ($name, $expr) = /"(.*?)"\s*\[\s*\[\s*(.*?)\s*\]\s*\]/;
117 next if $name eq $expr;
118 $err{$name} = eval $expr;
126 # This file is auto-generated. ***ANY*** changes here will be lost
130 use vars qw(\@EXPORT_OK \%EXPORT_TAGS \@ISA \$VERSION \%errno \$AUTOLOAD);
135 \$Config{'myarchname'} eq "$Config{'myarchname'}" or
136 die "Errno architecture ($Config{'myarchname'}) does not match executable architecture (\$Config{'myarchname'})";
138 \$VERSION = "$VERSION";
139 \@ISA = qw(Exporter);
144 my @err = sort { $err{$a} <=> $err{$b} } keys %err;
145 map { $len = length if length > $len } @err;
147 my $j = "\@EXPORT_OK = qw(" . join(" ",keys %err) . ");\n";
148 $j =~ s/(.{50,70})\s/$1\n\t/g;
156 my $k = join(" ", grep { exists $err{$_} }
157 qw(E2BIG EACCES EADDRINUSE EADDRNOTAVAIL EAFNOSUPPORT
158 EAGAIN EALREADY EBADF EBUSY ECHILD ECONNABORTED
159 ECONNREFUSED ECONNRESET EDEADLK EDESTADDRREQ EDOM EDQUOT
160 EEXIST EFAULT EFBIG EHOSTDOWN EHOSTUNREACH EINPROGRESS
161 EINTR EINVAL EIO EISCONN EISDIR ELOOP EMFILE EMLINK
162 EMSGSIZE ENAMETOOLONG ENETDOWN ENETRESET ENETUNREACH
163 ENFILE ENOBUFS ENODEV ENOENT ENOEXEC ENOLCK ENOMEM
164 ENOPROTOOPT ENOSPC ENOSYS ENOTBLK ENOTCONN ENOTDIR
165 ENOTEMPTY ENOTSOCK ENOTTY ENXIO EOPNOTSUPP EPERM
166 EPFNOSUPPORT EPIPE EPROCLIM EPROTONOSUPPORT EPROTOTYPE
167 ERANGE EREMOTE ERESTART EROFS ESHUTDOWN ESOCKTNOSUPPORT
168 ESPIPE ESRCH ESTALE ETIMEDOUT ETOOMANYREFS ETXTBSY
169 EUSERS EWOULDBLOCK EXDEV));
171 $k =~ s/(.{50,70})\s/$1\n\t/g;
172 print "\t",$k,"\n )]\n);\n\n";
174 foreach $err (@err) {
175 printf "sub %s () { %d }\n",,$err,$err{$err};
180 sub TIEHASH { bless [] }
183 my ($self, $errname) = @_;
184 my $proto = prototype("Errno::$errname");
185 if (defined($proto) && $proto eq "") {
187 return $! == &$errname;
190 Carp::confess("No errno $errname");
195 Carp::confess("ERRNO hash is read only!");
203 while(($k,$v) = each %Errno::) {
204 my $proto = prototype("Errno::$k");
205 last if (defined($proto) && $proto eq "");
212 my $s = scalar keys %Errno::;
217 my ($self, $errname) = @_;
218 my $proto = prototype($errname);
219 defined($proto) && $proto eq "";
229 Errno - System errno constants
233 use Errno qw(EINTR EIO :POSIX);
237 C<Errno> defines and conditionally exports all the error constants
238 defined in your system C<errno.h> include file. It has a single export
239 tag, C<:POSIX>, which will export all POSIX defined error numbers.
241 C<Errno> also makes C<%!> magic such that each element of C<%!> has a non-zero
242 value only if C<$!> is set to that value, eg
246 unless (open(FH, "/fangorn/spouse")) {
248 warn "Get a wife!\n";
250 warn "This path is barred: $!";
256 Graham Barr <gbarr@pobox.com>
260 Copyright (c) 1997-8 Graham Barr. All rights reserved.
261 This program is free software; you can redistribute it and/or modify it
262 under the same terms as Perl itself.