use Config;
use strict;
-our $VERSION = "1.20_04";
+our $VERSION = "1.25";
my %err = ();
}
}
+ my $pat;
+ if ($IsMSWin32) {
+ $pat = '^\s*#\s*define\s+((?:WSA)?E\w+)\s+';
+ }
+ else {
+ $pat = '^\s*#\s*define\s+(E\w+)\s+';
+ }
while(<FH>) {
$err{$1} = 1
- if /^\s*#\s*define\s+(E\w+)\s+/;
+ if /$pat/;
}
close(FH);
sub get_files {
my %file = ();
- # VMS keeps its include files in system libraries (well, except for Gcc)
+ # VMS keeps its include files in system libraries
if ($^O eq 'VMS') {
- if ($Config{vms_cc_type} eq 'decc') {
- $file{'Sys$Library:DECC$RTLDEF.TLB'} = 1;
- } elsif ($Config{vms_cc_type} eq 'vaxc') {
- $file{'Sys$Library:vaxcdef.tlb'} = 1;
- } elsif ($Config{vms_cc_type} eq 'gcc') {
- $file{'gnu_cc_include:[000000]errno.h'} = 1;
- }
+ $file{'Sys$Library:DECC$RTLDEF.TLB'} = 1;
} elsif ($^O eq 'os390') {
# OS/390 C compiler doesn't generate #file or #line directives
$file{'/usr/include/errno.h'} = 1;
{ # BeOS (support now removed) did not enter this block
# invoke CPP and read the output
+ my $inhibit_linemarkers = '';
+ if ($Config{gccversion} =~ /\A(\d+)\./ and $1 >= 5) {
+ # GCC 5.0 interleaves expanded macros with line numbers breaking
+ # each line into multiple lines. RT#123784
+ $inhibit_linemarkers = ' -P';
+ }
+
if ($^O eq 'VMS') {
- my $cpp = "$Config{cppstdin} $Config{cppflags} $Config{cppminus}";
+ my $cpp = "$Config{cppstdin} $Config{cppflags}" .
+ $inhibit_linemarkers . " $Config{cppminus}";
$cpp =~ s/sys\$input//i;
open(CPPO,"$cpp errno.c |") or
die "Cannot exec $Config{cppstdin}";
} elsif ($IsMSWin32 || $^O eq 'NetWare') {
- open(CPPO,"$Config{cpprun} $Config{cppflags} errno.c |") or
- die "Cannot run '$Config{cpprun} $Config{cppflags} errno.c'";
+ my $cpp = "$Config{cpprun} $Config{cppflags}" .
+ $inhibit_linemarkers;
+ open(CPPO,"$cpp errno.c |") or
+ die "Cannot run '$cpp errno.c'";
} elsif ($IsSymbian) {
- my $cpp = "gcc -E -I$ENV{SDK}\\epoc32\\include\\libc -";
+ my $cpp = "gcc -E -I$ENV{SDK}\\epoc32\\include\\libc" .
+ $inhibit_linemarkers ." -";
open(CPPO,"$cpp < errno.c |")
or die "Cannot exec $cpp";
} else {
- my $cpp = default_cpp();
+ my $cpp = default_cpp() . $inhibit_linemarkers;
open(CPPO,"$cpp < errno.c |")
or die "Cannot exec $cpp";
}
package Errno;
require Exporter;
-use Config;
use strict;
+EDQ
+
+ # Errno only needs Config to make sure it hasn't changed platforms.
+ # If someone set $ENV{PERL_BUILD_EXPAND_CONFIG_VARS} at build time,
+ # they've already declared perl doesn't need to worry about this risk.
+ if(!$ENV{'PERL_BUILD_EXPAND_CONFIG_VARS'}) {
+ print <<"CONFIG_CHECK_END";
+use Config;
"\$Config{'archname'}-\$Config{'osvers'}" eq
"$archname-$Config{'osvers'}" or
die "Errno architecture ($archname-$Config{'osvers'}) does not match executable architecture (\$Config{'archname'}-\$Config{'osvers'})";
+CONFIG_CHECK_END
+}
+
+ print <<"EDQ";
our \$VERSION = "$VERSION";
\$VERSION = eval \$VERSION;
our \@ISA = 'Exporter';
EUSERS EWOULDBLOCK EXDEV));
$k =~ s/(.{50,70})\s/$1\n\t/g;
- print "\t",$k,"\n )]\n);\n\n";
+ print "\t",$k,"\n )],\n";
+
+ if ($IsMSWin32) {
+ print " WINSOCK => [qw(\n";
+ $k = join(" ", grep { /^WSAE/ } keys %err);
+ $k =~ s/(.{50,70})\s/$1\n\t/g;
+ print "\t",$k,"\n )],\n";
+ }
+
+ print ");\n\n";
print <<'ESQ';
sub TIEHASH { bless \%err }
Carp::confess("ERRNO hash is read only!");
}
+# This is the true return value
*CLEAR = *DELETE = \*STORE; # Typeglob aliasing uses less space
sub NEXTKEY {
exists $err{$errname};
}
-tie %!, __PACKAGE__; # Returns an object, objects are true.
+sub _tie_it {
+ tie %{$_[0]}, __PACKAGE__;
+}
__END__
=head1 DESCRIPTION
C<Errno> defines and conditionally exports all the error constants
-defined in your system C<errno.h> include file. It has a single export
+defined in your system F<errno.h> include file. It has a single export
tag, C<:POSIX>, which will export all POSIX defined error numbers.
+On Windows, C<Errno> also defines and conditionally exports all the
+Winsock error constants defined in your system F<WinError.h> include
+file. These are included in a second export tag, C<:WINSOCK>.
+
C<Errno> also makes C<%!> magic such that each element of C<%!> has a
non-zero value only if C<$!> is set to that value. For example: