use Config;
use strict;
-our $VERSION = "1.12";
+our $VERSION = "1.19";
my %err = ();
my %wsa = ();
}
}
- if ($^O eq 'MacOS') {
- while(<FH>) {
- $err{$1} = $2
- if /^\s*#\s*define\s+(E\w+)\s+(\d+)/;
- }
- } else {
- while(<FH>) {
- $err{$1} = 1
- if /^\s*#\s*define\s+(E\w+)\s+/;
- if ($IsMSWin32) {
- $wsa{$1} = 1
- if /^\s*#\s*define\s+WSA(E\w+)\s+/;
- }
+ while(<FH>) {
+ $err{$1} = 1
+ if /^\s*#\s*define\s+(E\w+)\s+/;
+ if ($IsMSWin32) {
+ $wsa{$1} = 1
+ if /^\s*#\s*define\s+WSA(E\w+)\s+/;
}
}
} elsif ($^O eq 'os390') {
# OS/390 C compiler doesn't generate #file or #line directives
$file{'/usr/include/errno.h'} = 1;
- } elsif ($^O eq 'vmesa') {
- # OS/390 C compiler doesn't generate #file or #line directives
- $file{'../../vmesa/errno.h'} = 1;
- } elsif ($Config{archname} eq 'epoc') {
- # Watch out for cross compiling for EPOC (usually done on linux)
- $file{'/usr/local/epocemx/epocsdk/include/libc/sys/errno.h'} = 1;
} elsif ($Config{archname} eq 'arm-riscos') {
# Watch out for cross compiling for RISC OS
my $dep = `echo "#include <errno.h>" | gcc -E -M -`;
my $linux_errno_h = -e '/usr/include/errno.h' ?
'/usr/include/errno.h' : '/usr/local/include/errno.h';
$file{$linux_errno_h} = 1;
- } elsif ($^O eq 'MacOS') {
- # note that we are only getting the GUSI errno's here ...
- # we might miss out on compiler-specific ones
- $file{"$ENV{GUSI}include:sys:errno.h"} = 1;
-
- } elsif ($^O eq 'beos' || $^O eq 'haiku') {
+ } elsif ($^O eq 'haiku') {
# hidden in a special place
$file{'/boot/develop/headers/posix/errno.h'} = 1;
die "Cannot exec $cpp";
}
- my $pat;
- if (($IsMSWin32 || $^O eq 'NetWare') and $Config{cc} =~ /^bcc/i) {
- $pat = '^/\*\s+(.+)\s+\d+\s*:\s+\*/';
- }
- else {
- $pat = '^#\s*(?:line)?\s*\d+\s+"([^"]+)"';
- }
+ my $pat = '^#\s*(?:line)?\s*\d+\s+"([^"]+)"';
while(<CPPO>) {
if ($^O eq 'os2' or $IsMSWin32 or $^O eq 'NetWare') {
if (/$pat/o) {
if ($IsMSWin32) {
print CPPI "#include <winsock.h>\n";
foreach $err (keys %wsa) {
+ print CPPI "#if defined($err) && $err >= 100\n";
+ print CPPI "#undef $err\n";
+ print CPPI "#endif\n";
print CPPI "#ifndef $err\n";
print CPPI "#define $err WSA$err\n";
print CPPI "#endif\n";
close(CPPI);
- unless ($^O eq 'MacOS' || $^O eq 'beos') { # trust what we have / get later
+ { # BeOS (support now removed) did not enter this block
# invoke CPP and read the output
if ($^O eq 'VMS') {
close(CPPO);
}
- # Many of the E constants (including ENOENT, which is being
- # used in the Perl test suite a lot), are available only as
- # enums in BeOS, so compiling and executing some code is about
- # only way to find out what the numeric Evalues are. In fact above, we
- # didn't even bother to get the values of the ones that have numeric
- # values, since we can get all of them here, anyway.
-
- if ($^O eq 'beos') {
- if (open(C, ">errno.c")) {
- my @allerrs = keys %err;
- print C <<EOF;
-#include <errno.h>
-#include <stdio.h>
-int main() {
-EOF
- for (@allerrs) {
- print C qq[printf("$_ %d\n", $_);]
- }
- print C "}\n";
- close C;
- system("cc -o errno errno.c");
- unlink("errno.c");
- if (open(C, "./errno|")) {
- while (<C>) {
- if (/^(\w+) (-?\d+)$/) { $err{$1} = $2 }
- }
- close(C);
- } else {
- die "failed to execute ./errno: $!\n";
- }
- unlink("errno");
- } else {
- die "failed to create errno.c: $!\n";
- }
- }
+ # escape $Config{'archname'}
+ my $archname = $Config{'archname'};
+ $archname =~ s/([@%\$])/\\\1/g;
# Write Errno.pm
print <<"EDQ";
+# -*- buffer-read-only: t -*-
#
# This file is auto-generated. ***ANY*** changes here will be lost
#
package Errno;
-our (\@ISA,\$VERSION);
-use Exporter ();
+require Exporter;
use Config;
use strict;
"\$Config{'archname'}-\$Config{'osvers'}" eq
-"$Config{'archname'}-$Config{'osvers'}" or
- die "Errno architecture ($Config{'archname'}-$Config{'osvers'}) does not match executable architecture (\$Config{'archname'}-\$Config{'osvers'})";
+"$archname-$Config{'osvers'}" or
+ die "Errno architecture ($archname-$Config{'osvers'}) does not match executable architecture (\$Config{'archname'}-\$Config{'osvers'})";
-\$VERSION = "$VERSION";
+our \$VERSION = "$VERSION";
\$VERSION = eval \$VERSION;
-\@ISA = qw(Exporter);
+our \@ISA = 'Exporter';
my %err;
BEGIN {
%err = (
EDQ
-
- my @err = sort { $err{$a} <=> $err{$b} } keys %err;
+
+ my @err = sort { $err{$a} <=> $err{$b} || $a cmp $b }
+ grep { $err{$_} =~ /-?\d+$/ } keys %err;
foreach $err (@err) {
print "\t$err => $err{$err},\n";
print <<'ESQ';
);
# Generate proxy constant subroutines for all the values.
- # We assume at this point that our symbol table is empty.
+ # Well, almost all the values. Unfortunately we can't assume that at this
+ # point that our symbol table is empty, as code such as if the parser has
+ # seen code such as C<exists &Errno::EINVAL>, it will have created the
+ # typeglob.
# Doing this before defining @EXPORT_OK etc means that even if a platform is
# crazy enough to define EXPORT_OK as an error constant, everything will
# still work, because the parser will upgrade the PCS to a real typeglob.
# We rely on the subroutine definitions below to update the internal caches.
# Don't use %each, as we don't want a copy of the value.
foreach my $name (keys %err) {
- $Errno::{$name} = \$err{$name};
+ if ($Errno::{$name}) {
+ # We expect this to be reached fairly rarely, so take an approach
+ # which uses the least compile time effort in the common case:
+ eval "sub $name() { $err{$name} }; 1" or die $@;
+ } else {
+ $Errno::{$name} = \$err{$name};
+ }
}
}
-our (@EXPORT_OK, %EXPORT_TAGS);
-
-@EXPORT_OK = keys %err;
+our @EXPORT_OK = keys %err;
-%EXPORT_TAGS = (
+our %EXPORT_TAGS = (
POSIX => [qw(
ESQ
Carp::confess("ERRNO hash is read only!");
}
-*CLEAR = \&STORE;
-*DELETE = \&STORE;
+*CLEAR = *DELETE = \*STORE; # Typeglob aliasing uses less space
sub NEXTKEY {
each %err;
=cut
+# ex: set ro:
ESQ
}