1 use ExtUtils::MakeMaker;
5 our $VERSION = "1.20_04";
9 # Symbian cross-compiling environment.
10 my $IsSymbian = exists $ENV{SDK} && -d "$ENV{SDK}\\epoc32";
12 my $IsMSWin32 = $^O eq 'MSWin32' && !$IsSymbian;
14 unlink "Errno.pm" if -f "Errno.pm";
15 unlink "Errno.tmp" if -f "Errno.tmp";
16 open OUT, ">Errno.tmp" or die "Cannot open Errno.tmp: $!";
19 my @files = get_files();
20 if ($Config{gccversion} ne '' && $^O eq 'MSWin32') {
21 # MinGW complains "warning: #pragma system_header ignored outside include
22 # file" if the header files are processed individually, so include them
23 # all in .c file and process that instead.
24 open INCS, '>includes.c' or
25 die "Cannot open includes.c";
26 foreach $file (@files) {
27 next if $file eq 'errno.c';
29 print INCS qq[#include "$file"\n];
32 process_file('includes.c');
36 foreach $file (@files) {
41 unlink "errno.c" if -f "errno.c";
42 close OUT or die "Error closing Errno.tmp: $!";
44 rename "Errno.tmp", "Errno.pm" or die "Cannot rename Errno.tmp to Errno.pm: $!";
49 # for win32 perl under cygwin, we need to get a windows pathname
50 if ($^O eq 'MSWin32' && $Config{cc} =~ /\B-mno-cygwin\b/ &&
51 defined($file) && !-f $file) {
52 chomp($file = `cygpath -w "$file"`);
55 return unless defined $file and -f $file;
56 # warn "Processing $file\n";
59 if (($^O eq 'VMS') && ($Config{vms_cc_type} ne 'gnuc')) {
60 unless(open(FH," LIBRARY/EXTRACT=ERRNO/OUTPUT=SYS\$OUTPUT $file |")) {
61 warn "Cannot open '$file'";
64 } elsif ($Config{gccversion} ne '' && $^O ne 'darwin' ) {
65 # With the -dM option, gcc outputs every #define it finds
66 unless(open(FH,"$Config{cc} -E -dM $Config{cppflags} $file |")) {
67 warn "Cannot open '$file'";
71 unless(open(FH,"< $file")) {
72 # This file could be a temporary file created by cppstdin
73 # so only warn under -w, and return
74 warn "Cannot open '$file'" if $^W;
81 if /^\s*#\s*define\s+(E\w+)\s+/;
90 unless (defined $cppstdin) {
92 $cppstdin = $Config{cppstdin};
93 my $upup_cppstdin = File::Spec->catfile(File::Spec->updir,
96 my $cppstdin_is_wrapper =
97 ($cppstdin eq 'cppstdin'
99 and -x $upup_cppstdin);
100 $cppstdin = $upup_cppstdin if $cppstdin_is_wrapper;
102 return "$cppstdin $Config{cppflags} $Config{cppminus}";
107 # VMS keeps its include files in system libraries (well, except for Gcc)
109 if ($Config{vms_cc_type} eq 'decc') {
110 $file{'Sys$Library:DECC$RTLDEF.TLB'} = 1;
111 } elsif ($Config{vms_cc_type} eq 'vaxc') {
112 $file{'Sys$Library:vaxcdef.tlb'} = 1;
113 } elsif ($Config{vms_cc_type} eq 'gcc') {
114 $file{'gnu_cc_include:[000000]errno.h'} = 1;
116 } elsif ($^O eq 'os390') {
117 # OS/390 C compiler doesn't generate #file or #line directives
118 $file{'/usr/include/errno.h'} = 1;
119 } elsif ($Config{archname} eq 'arm-riscos') {
120 # Watch out for cross compiling for RISC OS
121 my $dep = `echo "#include <errno.h>" | gcc -E -M -`;
122 if ($dep =~ /(\S+errno\.h)/) {
125 } elsif ($^O eq 'linux' &&
126 $Config{gccversion} ne '' &&
127 $Config{gccversion} !~ /intel/i
128 # might be using, say, Intel's icc
130 # When cross-compiling we may store a path for gcc's "sysroot" option:
131 my $sysroot = $Config{sysroot} || '';
132 # Some Linuxes have weird errno.hs which generate
133 # no #file or #line directives
134 my ($linux_errno_h) = grep { -e $_ } map { "$_/errno.h" }
135 "$sysroot/usr/include", "$sysroot/usr/local/include",
136 split / / => $Config{locincpth} or
137 die "Cannot find errno.h";
138 $file{$linux_errno_h} = 1;
139 } elsif ($^O eq 'haiku') {
140 # hidden in a special place
141 $file{'/boot/develop/headers/posix/errno.h'} = 1;
143 } elsif ($^O eq 'vos') {
144 # avoid problem where cpp returns non-POSIX pathnames
145 $file{'/system/include_library/errno.h'} = 1;
146 } elsif ($IsSymbian) {
149 $file{"$SDK/epoc32/include/libc/sys/errno.h"} = 1;
151 open(CPPI,"> errno.c") or
152 die "Cannot open errno.c";
154 if ($^O eq 'NetWare') {
155 print CPPI "#include <nwerrno.h>\n";
157 print CPPI "#include <errno.h>\n";
159 print CPPI qq[#include "../../win32/include/sys/errno2.h"\n];
165 # invoke CPP and read the output
166 if ($IsMSWin32 || $^O eq 'NetWare') {
167 open(CPPO,"$Config{cpprun} $Config{cppflags} errno.c |") or
168 die "Cannot run '$Config{cpprun} $Config{cppflags} errno.c'";
170 my $cpp = default_cpp();
171 open(CPPO,"$cpp < errno.c |") or
172 die "Cannot exec $cpp";
175 my $pat = '^#\s*(?:line)?\s*\d+\s+"([^"]+)"';
177 if ($^O eq 'os2' or $IsMSWin32 or $^O eq 'NetWare') {
185 $file{$1} = 1 if /$pat/o;
198 die "No error definitions found" unless keys %err;
200 # create the CPP input
202 open(CPPI,"> errno.c") or
203 die "Cannot open errno.c";
205 if ($^O eq 'NetWare') {
206 print CPPI "#include <nwerrno.h>\n";
209 print CPPI "#include <errno.h>\n";
212 print CPPI qq[#include "../../win32/include/sys/errno2.h"\n];
215 foreach $err (keys %err) {
216 print CPPI '"',$err,'" [[',$err,']]',"\n";
221 { # BeOS (support now removed) did not enter this block
222 # invoke CPP and read the output
225 my $cpp = "$Config{cppstdin} $Config{cppflags} $Config{cppminus}";
226 $cpp =~ s/sys\$input//i;
227 open(CPPO,"$cpp errno.c |") or
228 die "Cannot exec $Config{cppstdin}";
229 } elsif ($IsMSWin32 || $^O eq 'NetWare') {
230 open(CPPO,"$Config{cpprun} $Config{cppflags} errno.c |") or
231 die "Cannot run '$Config{cpprun} $Config{cppflags} errno.c'";
232 } elsif ($IsSymbian) {
233 my $cpp = "gcc -E -I$ENV{SDK}\\epoc32\\include\\libc -";
234 open(CPPO,"$cpp < errno.c |")
235 or die "Cannot exec $cpp";
237 my $cpp = default_cpp();
238 open(CPPO,"$cpp < errno.c |")
239 or die "Cannot exec $cpp";
246 next unless ($name, $expr) = /"(.*?)"\s*\[\s*\[\s*(.*?)\s*\]\s*\]/;
247 next if $name eq $expr;
248 $expr =~ s/\(?\(\s*[a-z_]\w*\s*\)([^\)]*)\)?/$1/i; # ((type)0xcafebabe) at alia
249 $expr =~ s/((?:0x)?[0-9a-fA-F]+)[luLU]+\b/$1/g; # 2147483647L et alia
250 next if $expr =~ m/^[a-zA-Z]+$/; # skip some Win32 functions
251 if($expr =~ m/^0[xX]/) {
252 $err{$name} = hex $expr;
255 $err{$name} = eval $expr;
257 delete $err{$name} unless defined $err{$name};
262 # escape $Config{'archname'}
263 my $archname = $Config{'archname'};
264 $archname =~ s/([@%\$])/\\$1/g;
269 # -*- buffer-read-only: t -*-
271 # This file is auto-generated. ***ANY*** changes here will be lost
279 "\$Config{'archname'}-\$Config{'osvers'}" eq
280 "$archname-$Config{'osvers'}" or
281 die "Errno architecture ($archname-$Config{'osvers'}) does not match executable architecture (\$Config{'archname'}-\$Config{'osvers'})";
283 our \$VERSION = "$VERSION";
284 \$VERSION = eval \$VERSION;
285 our \@ISA = 'Exporter';
293 my @err = sort { $err{$a} <=> $err{$b} || $a cmp $b }
294 grep { $err{$_} =~ /-?\d+$/ } keys %err;
296 foreach $err (@err) {
297 print "\t$err => $err{$err},\n";
302 # Generate proxy constant subroutines for all the values.
303 # Well, almost all the values. Unfortunately we can't assume that at this
304 # point that our symbol table is empty, as code such as if the parser has
305 # seen code such as C<exists &Errno::EINVAL>, it will have created the
307 # Doing this before defining @EXPORT_OK etc means that even if a platform is
308 # crazy enough to define EXPORT_OK as an error constant, everything will
309 # still work, because the parser will upgrade the PCS to a real typeglob.
310 # We rely on the subroutine definitions below to update the internal caches.
311 # Don't use %each, as we don't want a copy of the value.
312 foreach my $name (keys %err) {
313 if ($Errno::{$name}) {
314 # We expect this to be reached fairly rarely, so take an approach
315 # which uses the least compile time effort in the common case:
316 eval "sub $name() { $err{$name} }; 1" or die $@;
318 $Errno::{$name} = \$err{$name};
323 our @EXPORT_OK = keys %err;
329 my $k = join(" ", grep { exists $err{$_} }
330 qw(E2BIG EACCES EADDRINUSE EADDRNOTAVAIL EAFNOSUPPORT
331 EAGAIN EALREADY EBADF EBUSY ECHILD ECONNABORTED
332 ECONNREFUSED ECONNRESET EDEADLK EDESTADDRREQ EDOM EDQUOT
333 EEXIST EFAULT EFBIG EHOSTDOWN EHOSTUNREACH EINPROGRESS
334 EINTR EINVAL EIO EISCONN EISDIR ELOOP EMFILE EMLINK
335 EMSGSIZE ENAMETOOLONG ENETDOWN ENETRESET ENETUNREACH
336 ENFILE ENOBUFS ENODEV ENOENT ENOEXEC ENOLCK ENOMEM
337 ENOPROTOOPT ENOSPC ENOSYS ENOTBLK ENOTCONN ENOTDIR
338 ENOTEMPTY ENOTSOCK ENOTTY ENXIO EOPNOTSUPP EPERM
339 EPFNOSUPPORT EPIPE EPROCLIM EPROTONOSUPPORT EPROTOTYPE
340 ERANGE EREMOTE ERESTART EROFS ESHUTDOWN ESOCKTNOSUPPORT
341 ESPIPE ESRCH ESTALE ETIMEDOUT ETOOMANYREFS ETXTBSY
342 EUSERS EWOULDBLOCK EXDEV));
344 $k =~ s/(.{50,70})\s/$1\n\t/g;
345 print "\t",$k,"\n )]\n);\n\n";
348 sub TIEHASH { bless \%err }
351 my (undef, $errname) = @_;
352 return "" unless exists $err{$errname};
353 my $errno = $err{$errname};
354 return $errno == $! ? $errno : 0;
359 Carp::confess("ERRNO hash is read only!");
362 *CLEAR = *DELETE = \*STORE; # Typeglob aliasing uses less space
369 my $s = scalar keys %err; # initialize iterator
374 my (undef, $errname) = @_;
375 exists $err{$errname};
378 tie %!, __PACKAGE__; # Returns an object, objects are true.
384 Errno - System errno constants
388 use Errno qw(EINTR EIO :POSIX);
392 C<Errno> defines and conditionally exports all the error constants
393 defined in your system C<errno.h> include file. It has a single export
394 tag, C<:POSIX>, which will export all POSIX defined error numbers.
396 C<Errno> also makes C<%!> magic such that each element of C<%!> has a
397 non-zero value only if C<$!> is set to that value. For example:
401 unless (open(FH, "/fangorn/spouse")) {
403 warn "Get a wife!\n";
405 warn "This path is barred: $!";
409 If a specified constant C<EFOO> does not exist on the system, C<$!{EFOO}>
410 returns C<"">. You may use C<exists $!{EFOO}> to check whether the
411 constant is available on the system.
415 Importing a particular constant may not be very portable, because the
416 import will fail on platforms that do not have that constant. A more
417 portable way to set C<$!> to a valid value is to use:
419 if (exists &Errno::EFOO) {
425 Graham Barr <gbarr@pobox.com>
429 Copyright (c) 1997-8 Graham Barr. All rights reserved.
430 This program is free software; you can redistribute it and/or modify it
431 under the same terms as Perl itself.