#!/usr/bin/perl -w
-
-#
-# Generate the reentr.c and reentr.h,
-# and optionally also the relevant metaconfig units (-U option).
#
+# Regenerate (overwriting only if changed):
+#
+# reentr.h
+# reentr.c
+#
+# from information stored in the DATA section of this file.
+#
+# With the -U option, it also unconditionally regenerates the relevant
+# metaconfig units:
+#
+# d_${func}_r.U
+#
+# Also accepts the standard regen_lib -q and -v args.
+#
+# This script is normally invoked from regen.pl.
BEGIN {
# Get function prototypes
use strict;
use Getopt::Std;
my %opts;
-getopts('U', \%opts);
+getopts('Uv', \%opts);
my %map = (
V => "void",
# Example #3: S_CBI means type func_r(const char*, char*, int)
-safer_unlink 'reentr.h';
-die "reentr.h: $!" unless open(H, ">reentr.h");
-binmode H;
-select H;
+# safer_unlink 'reentr.h';
+my $h = safer_open("reentr.h-new");
+select $h;
print <<EOF;
/* -*- buffer-read-only: t -*-
*
# Prepare to continue writing the reentr.h.
-select H;
+select $h;
{
# Write out all the known prototype signatures.
EOF
pushssif $endif;
}
- elsif ($func =~ /^(drand48|gmtime|localtime|random|srandom)$/) {
+ elsif ($func =~ /^(drand48|random|srandom)$/) {
pushssif $ifdef;
push @struct, <<EOF;
$seent{$func} _${func}_struct;
}
my $call = "${func}_r($v$w)";
- if ($func eq 'localtime') {
- $call = "L_R_TZSET $call";
- }
# Must make OpenBSD happy
my $memzero = '';
EOF
}
}
- push @wrap, <<EOF;
-# endif /* if defined(PERL_REENTR_API) && (PERL_REENTR_API+0 == 1) */
+ push @wrap, <<EOF; # !defined(xxx) && XXX_R_PROTO == REENTRANT_PROTO_Y_TS
+# endif
EOF
}
- push @wrap, <<EOF;
-# endif /* HAS_\U$func */
+ push @wrap, <<EOF; # defined(PERL_REENTR_API) && (PERL_REENTR_API+0 == 1)
+# endif
EOF
push @wrap, $endif, "\n";
/* ex: set ro: */
EOF
-close(H);
+safer_close($h);
+rename_if_different('reentr.h-new', 'reentr.h');
# Prepare to write the reentr.c.
-safer_unlink 'reentr.c';
-die "reentr.c: $!" unless open(C, ">reentr.c");
-binmode C;
-select C;
+# safer_unlink 'reentr.c';
+my $c = safer_open("reentr.c-new");
+select $c;
print <<EOF;
/* -*- buffer-read-only: t -*-
*
/* ex: set ro: */
EOF
+safer_close($c);
+rename_if_different('reentr.c-new', 'reentr.c');
+
__DATA__
asctime S |time |const struct tm|B_SB|B_SBI|I_SB|I_SBI
crypt CC |crypt |struct crypt_data|B_CCS|B_CCD|D=CRYPTD*
getservbyport IC|netdb |struct servent |I_ICSBWR|S_ICSBI|I_ICSD|D=struct servent_data*
getservent |netdb |struct servent |I_SBWR|I_SBI|S_SBI|I_SD|D=struct servent_data*
getspnam C |shadow |struct spwd |I_CSBWR|S_CSBI
-gmtime T |time |struct tm |S_TS|I_TS|T=const time_t*
-localtime T |time |struct tm |S_TS|I_TS|T=const time_t*
random |stdlib |struct random_data|I_iS|I_lS|I_St|i=int*|l=long*|t=int32_t*
readdir T |dirent |struct dirent |I_TSR|I_TS|T=DIR*
readdir64 T |dirent |struct dirent64|I_TSR|I_TS|T=DIR*