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
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 my $cpp = "$Config{cppstdin} $Config{cppflags} $Config{cppminus}";
109 open(CPPO,"$cpp < errno.c |") or die "Cannot exec $cpp";
111 open(CPPO,"$Config{cpprun} $Config{cppflags} errno.c |") or
112 die "Cannot exec $Config{cpprun}";
119 next unless ($name, $expr) = /"(.*?)"\s*\[\s*\[\s*(.*?)\s*\]\s*\]/;
120 next if $name eq $expr;
121 $err{$name} = eval $expr;
129 # This file is auto-generated. ***ANY*** changes here will be lost
133 use vars qw(\@EXPORT_OK \%EXPORT_TAGS \@ISA \$VERSION \%errno \$AUTOLOAD);
138 \$Config{'myarchname'} eq "$Config{'myarchname'}" or
139 die "Errno architecture ($Config{'myarchname'}) does not match executable architecture (\$Config{'myarchname'})";
141 \$VERSION = "$VERSION";
142 \@ISA = qw(Exporter);
147 my @err = sort { $err{$a} <=> $err{$b} } keys %err;
148 map { $len = length if length > $len } @err;
150 my $j = "\@EXPORT_OK = qw(" . join(" ",keys %err) . ");\n";
151 $j =~ s/(.{50,70})\s/$1\n\t/g;
159 my $k = join(" ", grep { exists $err{$_} }
160 qw(E2BIG EACCES EADDRINUSE EADDRNOTAVAIL EAFNOSUPPORT
161 EAGAIN EALREADY EBADF EBUSY ECHILD ECONNABORTED
162 ECONNREFUSED ECONNRESET EDEADLK EDESTADDRREQ EDOM EDQUOT
163 EEXIST EFAULT EFBIG EHOSTDOWN EHOSTUNREACH EINPROGRESS
164 EINTR EINVAL EIO EISCONN EISDIR ELOOP EMFILE EMLINK
165 EMSGSIZE ENAMETOOLONG ENETDOWN ENETRESET ENETUNREACH
166 ENFILE ENOBUFS ENODEV ENOENT ENOEXEC ENOLCK ENOMEM
167 ENOPROTOOPT ENOSPC ENOSYS ENOTBLK ENOTCONN ENOTDIR
168 ENOTEMPTY ENOTSOCK ENOTTY ENXIO EOPNOTSUPP EPERM
169 EPFNOSUPPORT EPIPE EPROCLIM EPROTONOSUPPORT EPROTOTYPE
170 ERANGE EREMOTE ERESTART EROFS ESHUTDOWN ESOCKTNOSUPPORT
171 ESPIPE ESRCH ESTALE ETIMEDOUT ETOOMANYREFS ETXTBSY
172 EUSERS EWOULDBLOCK EXDEV));
174 $k =~ s/(.{50,70})\s/$1\n\t/g;
175 print "\t",$k,"\n )]\n);\n\n";
177 foreach $err (@err) {
178 printf "sub %s () { %d }\n",,$err,$err{$err};
183 sub TIEHASH { bless [] }
186 my ($self, $errname) = @_;
187 my $proto = prototype("Errno::$errname");
188 if (defined($proto) && $proto eq "") {
190 return $! == &$errname;
193 Carp::confess("No errno $errname");
198 Carp::confess("ERRNO hash is read only!");
206 while(($k,$v) = each %Errno::) {
207 my $proto = prototype("Errno::$k");
208 last if (defined($proto) && $proto eq "");
215 my $s = scalar keys %Errno::;
220 my ($self, $errname) = @_;
221 my $proto = prototype($errname);
222 defined($proto) && $proto eq "";
232 Errno - System errno constants
236 use Errno qw(EINTR EIO :POSIX);
240 C<Errno> defines and conditionally exports all the error constants
241 defined in your system C<errno.h> include file. It has a single export
242 tag, C<:POSIX>, which will export all POSIX defined error numbers.
244 C<Errno> also makes C<%!> magic such that each element of C<%!> has a non-zero
245 value only if C<$!> is set to that value, eg
249 unless (open(FH, "/fangorn/spouse")) {
251 warn "Get a wife!\n";
253 warn "This path is barred: $!";
259 Graham Barr <gbarr@pobox.com>
263 Copyright (c) 1997-8 Graham Barr. All rights reserved.
264 This program is free software; you can redistribute it and/or modify it
265 under the same terms as Perl itself.