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 # This file could be a temporay file created by cppstdin
35 # so only warn under -w, and return
36 warn "Cannot open '$file'" if $^W;
42 if /^\s*#\s*define\s+(E\w+)\s+/;
49 # VMS keeps its include files in system libraries (well, except for Gcc)
51 if ($Config{vms_cc_type} eq 'decc') {
52 $file{'Sys$Library:DECC$RTLDEF.TLB'} = 1;
53 } elsif ($Config{vms_cc_type} eq 'vaxc') {
54 $file{'Sys$Library:vaxcdef.tlb'} = 1;
55 } elsif ($Config{vms_cc_type} eq 'gcc') {
56 $file{'gnu_cc_include:[000000]errno.h'} = 1;
58 } elsif ($^O eq 'os390') {
59 # OS/390 C compiler doesn't generate #file or #line directives
60 $file{'/usr/include/errno.h'} = 1;
61 } elsif ($^O eq 'vmesa') {
62 # OS/390 C compiler doesn't generate #file or #line directives
63 $file{'../../vmesa/errno.h'} = 1;
65 open(CPPI,"> errno.c") or
66 die "Cannot open errno.c";
68 print CPPI "#include <errno.h>\n";
72 # invoke CPP and read the output
73 if ($^O eq 'MSWin32') {
74 open(CPPO,"$Config{cpprun} $Config{cppflags} errno.c |") or
75 die "Cannot run '$Config{cpprun} $Config{cppflags} errno.c'";
77 my $cpp = "$Config{cppstdin} $Config{cppflags} $Config{cppminus}";
78 open(CPPO,"$cpp < errno.c |") or
79 die "Cannot exec $cpp";
83 if ($^O eq 'MSWin32' and $Config{cc} =~ /^bcc/i) {
84 $pat = '^/\*\s+(.+)\s+\d+\s*:\s+\*/';
87 $pat = '^#(?:line)?\s*\d+\s+"([^"]+)"';
90 $file{$1} = 1 if /$pat/o;
100 # create the CPP input
102 open(CPPI,"> errno.c") or
103 die "Cannot open errno.c";
105 print CPPI "#include <errno.h>\n";
107 foreach $err (keys %err) {
108 print CPPI '"',$err,'" [[',$err,']]',"\n";
113 # invoke CPP and read the output
116 my $cpp = "$Config{cppstdin} $Config{cppflags} $Config{cppminus}";
117 $cpp =~ s/sys\$input//i;
118 open(CPPO,"$cpp errno.c |") or
119 die "Cannot exec $Config{cppstdin}";
120 } elsif ($^O eq 'MSWin32') {
121 open(CPPO,"$Config{cpprun} $Config{cppflags} errno.c |") or
122 die "Cannot run '$Config{cpprun} $Config{cppflags} errno.c'";
124 my $cpp = "$Config{cppstdin} $Config{cppflags} $Config{cppminus}";
125 open(CPPO,"$cpp < errno.c |")
126 or die "Cannot exec $cpp";
133 next unless ($name, $expr) = /"(.*?)"\s*\[\s*\[\s*(.*?)\s*\]\s*\]/;
134 next if $name eq $expr;
135 $err{$name} = eval $expr;
143 # This file is auto-generated. ***ANY*** changes here will be lost
147 use vars qw(\@EXPORT_OK \%EXPORT_TAGS \@ISA \$VERSION \%errno \$AUTOLOAD);
152 \$Config{'myarchname'} eq "$Config{'myarchname'}" or
153 die "Errno architecture ($Config{'myarchname'}) does not match executable architecture (\$Config{'myarchname'})";
155 \$VERSION = "$VERSION";
156 \@ISA = qw(Exporter);
161 my @err = sort { $err{$a} <=> $err{$b} } keys %err;
162 map { $len = length if length > $len } @err;
164 my $j = "\@EXPORT_OK = qw(" . join(" ",keys %err) . ");\n";
165 $j =~ s/(.{50,70})\s/$1\n\t/g;
173 my $k = join(" ", grep { exists $err{$_} }
174 qw(E2BIG EACCES EADDRINUSE EADDRNOTAVAIL EAFNOSUPPORT
175 EAGAIN EALREADY EBADF EBUSY ECHILD ECONNABORTED
176 ECONNREFUSED ECONNRESET EDEADLK EDESTADDRREQ EDOM EDQUOT
177 EEXIST EFAULT EFBIG EHOSTDOWN EHOSTUNREACH EINPROGRESS
178 EINTR EINVAL EIO EISCONN EISDIR ELOOP EMFILE EMLINK
179 EMSGSIZE ENAMETOOLONG ENETDOWN ENETRESET ENETUNREACH
180 ENFILE ENOBUFS ENODEV ENOENT ENOEXEC ENOLCK ENOMEM
181 ENOPROTOOPT ENOSPC ENOSYS ENOTBLK ENOTCONN ENOTDIR
182 ENOTEMPTY ENOTSOCK ENOTTY ENXIO EOPNOTSUPP EPERM
183 EPFNOSUPPORT EPIPE EPROCLIM EPROTONOSUPPORT EPROTOTYPE
184 ERANGE EREMOTE ERESTART EROFS ESHUTDOWN ESOCKTNOSUPPORT
185 ESPIPE ESRCH ESTALE ETIMEDOUT ETOOMANYREFS ETXTBSY
186 EUSERS EWOULDBLOCK EXDEV));
188 $k =~ s/(.{50,70})\s/$1\n\t/g;
189 print "\t",$k,"\n )]\n);\n\n";
191 foreach $err (@err) {
192 printf "sub %s () { %d }\n",,$err,$err{$err};
197 sub TIEHASH { bless [] }
200 my ($self, $errname) = @_;
201 my $proto = prototype("Errno::$errname");
202 if (defined($proto) && $proto eq "") {
204 return $! == &$errname;
207 Carp::confess("No errno $errname");
212 Carp::confess("ERRNO hash is read only!");
220 while(($k,$v) = each %Errno::) {
221 my $proto = prototype("Errno::$k");
222 last if (defined($proto) && $proto eq "");
229 my $s = scalar keys %Errno::;
234 my ($self, $errname) = @_;
235 my $proto = prototype($errname);
236 defined($proto) && $proto eq "";
246 Errno - System errno constants
250 use Errno qw(EINTR EIO :POSIX);
254 C<Errno> defines and conditionally exports all the error constants
255 defined in your system C<errno.h> include file. It has a single export
256 tag, C<:POSIX>, which will export all POSIX defined error numbers.
258 C<Errno> also makes C<%!> magic such that each element of C<%!> has a non-zero
259 value only if C<$!> is set to that value, eg
263 unless (open(FH, "/fangorn/spouse")) {
265 warn "Get a wife!\n";
267 warn "This path is barred: $!";
273 Graham Barr <gbarr@pobox.com>
277 Copyright (c) 1997-8 Graham Barr. All rights reserved.
278 This program is free software; you can redistribute it and/or modify it
279 under the same terms as Perl itself.