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*#\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
104 my $cpp = "$Config{cppstdin} $Config{cppflags} $Config{cppminus}";
105 $cpp =~ s/sys\$input//i;
106 open(CPPO,"$cpp errno.c |") or
107 die "Cannot exec $Config{cppstdin}";
108 } elsif($^O eq 'next') {
109 # NeXT will do syntax checking unless it is reading from stdin
110 my $cpp = "$Config{cppstdin} $Config{cppflags} $Config{cppminus}";
111 open(CPPO,"$cpp < errno.c |")
112 or die "Cannot exec $cpp";
114 open(CPPO,"$Config{cpprun} $Config{cppflags} errno.c |") or
115 die "Cannot exec $Config{cpprun}";
122 next unless ($name, $expr) = /"(.*?)"\s*\[\s*\[\s*(.*?)\s*\]\s*\]/;
123 next if $name eq $expr;
124 $err{$name} = eval $expr;
132 # This file is auto-generated. ***ANY*** changes here will be lost
136 use vars qw(\@EXPORT_OK \%EXPORT_TAGS \@ISA \$VERSION \%errno \$AUTOLOAD);
141 \$Config{'myarchname'} eq "$Config{'myarchname'}" or
142 die "Errno architecture ($Config{'myarchname'}) does not match executable architecture (\$Config{'myarchname'})";
144 \$VERSION = "$VERSION";
145 \@ISA = qw(Exporter);
150 my @err = sort { $err{$a} <=> $err{$b} } keys %err;
151 map { $len = length if length > $len } @err;
153 my $j = "\@EXPORT_OK = qw(" . join(" ",keys %err) . ");\n";
154 $j =~ s/(.{50,70})\s/$1\n\t/g;
162 my $k = join(" ", grep { exists $err{$_} }
163 qw(E2BIG EACCES EADDRINUSE EADDRNOTAVAIL EAFNOSUPPORT
164 EAGAIN EALREADY EBADF EBUSY ECHILD ECONNABORTED
165 ECONNREFUSED ECONNRESET EDEADLK EDESTADDRREQ EDOM EDQUOT
166 EEXIST EFAULT EFBIG EHOSTDOWN EHOSTUNREACH EINPROGRESS
167 EINTR EINVAL EIO EISCONN EISDIR ELOOP EMFILE EMLINK
168 EMSGSIZE ENAMETOOLONG ENETDOWN ENETRESET ENETUNREACH
169 ENFILE ENOBUFS ENODEV ENOENT ENOEXEC ENOLCK ENOMEM
170 ENOPROTOOPT ENOSPC ENOSYS ENOTBLK ENOTCONN ENOTDIR
171 ENOTEMPTY ENOTSOCK ENOTTY ENXIO EOPNOTSUPP EPERM
172 EPFNOSUPPORT EPIPE EPROCLIM EPROTONOSUPPORT EPROTOTYPE
173 ERANGE EREMOTE ERESTART EROFS ESHUTDOWN ESOCKTNOSUPPORT
174 ESPIPE ESRCH ESTALE ETIMEDOUT ETOOMANYREFS ETXTBSY
175 EUSERS EWOULDBLOCK EXDEV));
177 $k =~ s/(.{50,70})\s/$1\n\t/g;
178 print "\t",$k,"\n )]\n);\n\n";
180 foreach $err (@err) {
181 printf "sub %s () { %d }\n",,$err,$err{$err};
186 sub TIEHASH { bless [] }
189 my ($self, $errname) = @_;
190 my $proto = prototype("Errno::$errname");
191 if (defined($proto) && $proto eq "") {
193 return $! == &$errname;
196 Carp::confess("No errno $errname");
201 Carp::confess("ERRNO hash is read only!");
209 while(($k,$v) = each %Errno::) {
210 my $proto = prototype("Errno::$k");
211 last if (defined($proto) && $proto eq "");
218 my $s = scalar keys %Errno::;
223 my ($self, $errname) = @_;
224 my $proto = prototype($errname);
225 defined($proto) && $proto eq "";
235 Errno - System errno constants
239 use Errno qw(EINTR EIO :POSIX);
243 C<Errno> defines and conditionally exports all the error constants
244 defined in your system C<errno.h> include file. It has a single export
245 tag, C<:POSIX>, which will export all POSIX defined error numbers.
247 C<Errno> also makes C<%!> magic such that each element of C<%!> has a non-zero
248 value only if C<$!> is set to that value, eg
252 unless (open(FH, "/fangorn/spouse")) {
254 warn "Get a wife!\n";
256 warn "This path is barred: $!";
262 Graham Barr <gbarr@pobox.com>
266 Copyright (c) 1997-8 Graham Barr. All rights reserved.
267 This program is free software; you can redistribute it and/or modify it
268 under the same terms as Perl itself.