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;
56 } elsif ($^O eq 'os390') {
57 # OS/390 C compiler doesn't generate #file or #line directives
58 $file{'/usr/include/errno.h'} = 1;
60 open(CPPI,"> errno.c") or
61 die "Cannot open errno.c";
63 print CPPI "#include <errno.h>\n";
67 # invoke CPP and read the output
69 open(CPPO,"$Config{cpprun} $Config{cppflags} errno.c |") or
70 die "Cannot exec $Config{cpprun}";
73 if ($^O eq 'MSWin32' and $Config{cc} =~ /^bcc/i) {
74 $pat = '^/\*\s+(.+)\s+\d+\s*:\s+\*/';
77 $pat = '^#(?:line)?\s*\d+\s+"([^"]+)"';
80 $file{$1} = 1 if /$pat/o;
90 # create the CPP input
92 open(CPPI,"> errno.c") or
93 die "Cannot open errno.c";
95 print CPPI "#include <errno.h>\n";
97 foreach $err (keys %err) {
98 print CPPI '"',$err,'" [[',$err,']]',"\n";
103 # invoke CPP and read the output
106 my $cpp = "$Config{cppstdin} $Config{cppflags} $Config{cppminus}";
107 $cpp =~ s/sys\$input//i;
108 open(CPPO,"$cpp errno.c |") or
109 die "Cannot exec $Config{cppstdin}";
110 } elsif(!$Config{'cpprun'} or $^O eq 'next') {
111 # NeXT will do syntax checking unless it is reading from stdin
112 my $cpp = "$Config{cppstdin} $Config{cppflags} $Config{cppminus}";
113 open(CPPO,"$cpp < errno.c |")
114 or die "Cannot exec $cpp";
116 open(CPPO,"$Config{cpprun} $Config{cppflags} errno.c |") or
117 die "Cannot exec $Config{cpprun}";
124 next unless ($name, $expr) = /"(.*?)"\s*\[\s*\[\s*(.*?)\s*\]\s*\]/;
125 next if $name eq $expr;
126 $err{$name} = eval $expr;
134 # This file is auto-generated. ***ANY*** changes here will be lost
138 use vars qw(\@EXPORT_OK \%EXPORT_TAGS \@ISA \$VERSION \%errno \$AUTOLOAD);
143 \$Config{'myarchname'} eq "$Config{'myarchname'}" or
144 die "Errno architecture ($Config{'myarchname'}) does not match executable architecture (\$Config{'myarchname'})";
146 \$VERSION = "$VERSION";
147 \@ISA = qw(Exporter);
152 my @err = sort { $err{$a} <=> $err{$b} } keys %err;
153 map { $len = length if length > $len } @err;
155 my $j = "\@EXPORT_OK = qw(" . join(" ",keys %err) . ");\n";
156 $j =~ s/(.{50,70})\s/$1\n\t/g;
164 my $k = join(" ", grep { exists $err{$_} }
165 qw(E2BIG EACCES EADDRINUSE EADDRNOTAVAIL EAFNOSUPPORT
166 EAGAIN EALREADY EBADF EBUSY ECHILD ECONNABORTED
167 ECONNREFUSED ECONNRESET EDEADLK EDESTADDRREQ EDOM EDQUOT
168 EEXIST EFAULT EFBIG EHOSTDOWN EHOSTUNREACH EINPROGRESS
169 EINTR EINVAL EIO EISCONN EISDIR ELOOP EMFILE EMLINK
170 EMSGSIZE ENAMETOOLONG ENETDOWN ENETRESET ENETUNREACH
171 ENFILE ENOBUFS ENODEV ENOENT ENOEXEC ENOLCK ENOMEM
172 ENOPROTOOPT ENOSPC ENOSYS ENOTBLK ENOTCONN ENOTDIR
173 ENOTEMPTY ENOTSOCK ENOTTY ENXIO EOPNOTSUPP EPERM
174 EPFNOSUPPORT EPIPE EPROCLIM EPROTONOSUPPORT EPROTOTYPE
175 ERANGE EREMOTE ERESTART EROFS ESHUTDOWN ESOCKTNOSUPPORT
176 ESPIPE ESRCH ESTALE ETIMEDOUT ETOOMANYREFS ETXTBSY
177 EUSERS EWOULDBLOCK EXDEV));
179 $k =~ s/(.{50,70})\s/$1\n\t/g;
180 print "\t",$k,"\n )]\n);\n\n";
182 foreach $err (@err) {
183 printf "sub %s () { %d }\n",,$err,$err{$err};
188 sub TIEHASH { bless [] }
191 my ($self, $errname) = @_;
192 my $proto = prototype("Errno::$errname");
193 if (defined($proto) && $proto eq "") {
195 return $! == &$errname;
198 Carp::confess("No errno $errname");
203 Carp::confess("ERRNO hash is read only!");
211 while(($k,$v) = each %Errno::) {
212 my $proto = prototype("Errno::$k");
213 last if (defined($proto) && $proto eq "");
220 my $s = scalar keys %Errno::;
225 my ($self, $errname) = @_;
226 my $proto = prototype($errname);
227 defined($proto) && $proto eq "";
237 Errno - System errno constants
241 use Errno qw(EINTR EIO :POSIX);
245 C<Errno> defines and conditionally exports all the error constants
246 defined in your system C<errno.h> include file. It has a single export
247 tag, C<:POSIX>, which will export all POSIX defined error numbers.
249 C<Errno> also makes C<%!> magic such that each element of C<%!> has a non-zero
250 value only if C<$!> is set to that value, eg
254 unless (open(FH, "/fangorn/spouse")) {
256 warn "Get a wife!\n";
258 warn "This path is barred: $!";
264 Graham Barr <gbarr@pobox.com>
268 Copyright (c) 1997-8 Graham Barr. All rights reserved.
269 This program is free software; you can redistribute it and/or modify it
270 under the same terms as Perl itself.