This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
Upgrade to Time-HiRes-1.89.
[perl5.git] / reentr.pl
index ef9a7a1..13cf4d1 100644 (file)
--- a/reentr.pl
+++ b/reentr.pl
@@ -5,6 +5,11 @@
 # and optionally also the relevant metaconfig units (-U option).
 # 
 
+BEGIN {
+    # Get function prototypes
+    require 'regen_lib.pl';
+}
+
 use strict;
 use Getopt::Std;
 my %opts;
@@ -35,23 +40,26 @@ my %map = (
 # 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;
 print <<EOF;
-/*
+/* -*- buffer-read-only: t -*-
+ *
  *    reentr.h
  *
- *    Copyright (c) 1997-2002, Larry Wall
+ *    Copyright (C) 2002, 2003, 2005, 2006 by Larry Wall and others
  *
  *    You may distribute under the terms of either the GNU General Public
  *    License or the Artistic License, as specified in the README file.
  *
  *  !!!!!!!   DO NOT EDIT THIS FILE   !!!!!!!
- *  This file is built by reentrl.pl from data in reentr.pl.
+ *  This file is built by reentr.pl from data in reentr.pl.
  */
 
 #ifndef REENTR_H
-#define REENTR_H 
+#define REENTR_H
 
 #ifdef USE_REENTRANT_API
  
@@ -80,6 +88,17 @@ print <<EOF;
 #   define NETDB_R_OBSOLETE
 #endif
 
+/*
+ * As of OpenBSD 3.7, reentrant functions are now working, they just are
+ * incompatible with everyone else.  To make OpenBSD happy, we have to
+ * memzero out certain structures before calling the functions.
+ */
+#if defined(__OpenBSD__)
+#    define REENTR_MEMZERO(a,b) memzero(a,b),
+#else
+#    define REENTR_MEMZERO(a,b)
+#endif 
+
 #ifdef NETDB_R_OBSOLETE
 #   undef HAS_ENDHOSTENT_R
 #   undef HAS_ENDNETENT_R
@@ -128,29 +147,33 @@ print <<EOF;
 
 EOF
 
-my %seenh;
-my %seena;
-my @seenf;
-my %seenp;
-my %seent;
-my %seens;
-my %seend;
-my %seenu;
+my %seenh; # the different prototypes signatures for this function
+my %seena; # the different prototypes signatures for this function in order
+my @seenf; # all the seen functions
+my %seenp; # the different prototype signatures for all functions
+my %seent; # the return type of this function
+my %seens; # the type of this function's "S"
+my %seend; # the type of this function's "D"
+my %seenm; # all the types
+my %seenu; # the length of the argument list of this function
 
-while (<DATA>) {
+while (<DATA>) { # Read in the protypes.
     next if /^\s+$/;
     chomp;
-    my ($f, $h, $t, @p) = split(/\s*\|\s*/, $_, -1);
+    my ($func, $hdr, $type, @p) = split(/\s*\|\s*/, $_, -1);
     my $u;
-    ($f, $u) = split(' ', $f);
-    $seenu{$f} = defined $u ? length $u : 0;
-    my $F = uc $f;
-    push @seenf, $f;
+    # Split off the real function name and the argument list.
+    ($func, $u) = split(' ', $func);
+    $seenu{$func} = defined $u ? length $u : 0;
+    my $FUNC = uc $func; # for output.
+    push @seenf, $func;
     my %m = %map;
-    if ($t) {
-       $m{S} = "$t*";
-       $m{R} = "$t**";
+    if ($type) {
+       $m{S} = "$type*";
+       $m{R} = "$type**";
     }
+
+    # Set any special mapping variables (like X=x_t)
     if (@p) {
        while ($p[-1] =~ /=/) {
            my ($k, $v) = ($p[-1] =~ /^([A-Za-z])\s*=\s*(.*)/);
@@ -158,110 +181,129 @@ while (<DATA>) {
            pop @p;
        }
     }
-    if ($opts{U} && open(U, ">d_${f}_r.U"))  {
+
+    # If given the -U option open up the metaconfig unit for this function.
+    if ($opts{U} && open(U, ">d_${func}_r.U"))  {
+       binmode U;
        select U;
     }
-    my $prereqs  = '';
-    my $prereqh  = '';
-    my $prereqsh = '';
-    if ($h ne 'stdio') { # There's no i_stdio.
-       $prereqs  = "i_$h";
-       $prereqh  = "$h.h";
-       $prereqsh = "\$$prereqs $prereqh";
-    }
-    print <<EOF if $opts{U};
-?RCS: \$Id: d_${f}_r.U,v $
+
+    if ($opts{U}) {
+       # The metaconfig units needs prerequisite dependencies.
+       my $prereqs  = '';
+       my $prereqh  = '';
+       my $prereqsh = '';
+       if ($hdr ne 'stdio') { # There's no i_stdio.
+           $prereqs  = "i_$hdr";
+           $prereqh  = "$hdr.h";
+           $prereqsh = "\$$prereqs $prereqh";
+       }
+       my @prereq = qw(Inlibc Protochk Hasproto i_systypes usethreads);
+       push @prereq, $prereqs;
+        my $hdrs = "\$i_systypes sys/types.h define stdio.h $prereqsh";
+        if ($hdr eq 'time') {
+           $hdrs .= " \$i_systime sys/time.h";
+           push @prereq, 'i_systime';
+       }
+       # Output the metaconfig unit header.
+       print <<EOF;
+?RCS: \$Id: d_${func}_r.U,v $
 ?RCS:
-?RCS: Copyright (c) 2002 Jarkko Hietaniemi
+?RCS: Copyright (c) 2002,2003 Jarkko Hietaniemi
 ?RCS:
 ?RCS: You may distribute under the terms of either the GNU General Public
 ?RCS: License or the Artistic License, as specified in the README file.
 ?RCS:
 ?RCS: Generated by the reentr.pl from the Perl 5.8 distribution.
 ?RCS:
-?MAKE:d_${f}_r ${f}_r_proto: Inlibc Protochk Hasproto i_systypes i_systime $prereqs usethreads
+?MAKE:d_${func}_r ${func}_r_proto: @prereq
 ?MAKE: -pick add \$@ %<
-?S:d_${f}_r:
-?S:    This variable conditionally defines the HAS_${F}_R symbol,
-?S:    which indicates to the C program that the ${f}_r()
+?S:d_${func}_r:
+?S:    This variable conditionally defines the HAS_${FUNC}_R symbol,
+?S:    which indicates to the C program that the ${func}_r()
 ?S:    routine is available.
 ?S:.
-?S:${f}_r_proto:
-?S:    This variable encodes the prototype of ${f}_r.
+?S:${func}_r_proto:
+?S:    This variable encodes the prototype of ${func}_r.
+?S:    It is zero if d_${func}_r is undef, and one of the
+?S:    REENTRANT_PROTO_T_ABC macros of reentr.h if d_${func}_r
+?S:    is defined.
 ?S:.
-?C:HAS_${F}_R:
-?C:    This symbol, if defined, indicates that the ${f}_r routine
-?C:    is available to ${f} re-entrantly.
+?C:HAS_${FUNC}_R:
+?C:    This symbol, if defined, indicates that the ${func}_r routine
+?C:    is available to ${func} re-entrantly.
 ?C:.
-?C:${F}_R_PROTO:
-?C:    This symbol encodes the prototype of ${f}_r.
+?C:${FUNC}_R_PROTO:
+?C:    This symbol encodes the prototype of ${func}_r.
+?C:    It is zero if d_${func}_r is undef, and one of the
+?C:    REENTRANT_PROTO_T_ABC macros of reentr.h if d_${func}_r
+?C:    is defined.
 ?C:.
-?H:#\$d_${f}_r HAS_${F}_R         /**/
-?H:#define ${F}_R_PROTO \$${f}_r_proto    /**/
+?H:#\$d_${func}_r HAS_${FUNC}_R           /**/
+?H:#define ${FUNC}_R_PROTO \$${func}_r_proto      /**/
 ?H:.
-?T:try hdrs d_${f}_r_proto
-?LINT:set d_${f}_r
-?LINT:set ${f}_r_proto
-: see if ${f}_r exists
-set ${f}_r d_${f}_r
+?T:try hdrs d_${func}_r_proto
+?LINT:set d_${func}_r
+?LINT:set ${func}_r_proto
+: see if ${func}_r exists
+set ${func}_r d_${func}_r
 eval \$inlibc
-case "\$d_${f}_r" in
+case "\$d_${func}_r" in
 "\$define")
-       hdrs="\$i_systypes sys/types.h define stdio.h $prereqsh"
-       case "$h" in
-       time)
-               hdrs="\$hdrs \$i_systime sys/time.h"
-               ;;
-       esac
-       case "\$d_${f}_r_proto:\$usethreads" in
-       ":define")      d_${f}_r_proto=define
-               set d_${f}_r_proto ${f}_r \$hdrs
+EOF
+       print <<EOF;
+       hdrs="$hdrs"
+       case "\$d_${func}_r_proto:\$usethreads" in
+       ":define")      d_${func}_r_proto=define
+               set d_${func}_r_proto ${func}_r \$hdrs
                eval \$hasproto ;;
        *)      ;;
        esac
-       case "\$d_${f}_r_proto" in
+       case "\$d_${func}_r_proto" in
        define)
 EOF
-       for my $p (@p) {
-           my ($r, $a) = ($p =~ /^(.)_(.+)/);
-           my $v = join(", ", map { $m{$_} } split '', $a);
-           if ($opts{U}) {
-               print <<EOF ;
-       case "\$${f}_r_proto" in
-       ''|0) try='$m{$r} ${f}_r($v);'
-       ./protochk "extern \$try" \$hdrs && ${f}_r_proto=$p ;;
+    }
+    for my $p (@p) {
+        my ($r, $a) = ($p =~ /^(.)_(.+)/);
+       my $v = join(", ", map { $m{$_} } split '', $a);
+       if ($opts{U}) {
+           print <<EOF ;
+       case "\$${func}_r_proto" in
+       ''|0) try='$m{$r} ${func}_r($v);'
+       ./protochk "extern \$try" \$hdrs && ${func}_r_proto=$p ;;
        esac
 EOF
-            }
-           $seenh{$f}->{$p}++;
-           push @{$seena{$f}}, $p;
-           $seenp{$p}++;
-           $seent{$f} = $t;
-           $seens{$f} = $m{S};
-           $seend{$f} = $m{D};
-       }
-       if ($opts{U}) {
-           print <<EOF;
-       case "\$${f}_r_proto" in
-       ''|0)   d_${f}_r=undef
-               ${f}_r_proto=0
-               echo "Disabling ${f}_r, cannot determine prototype." >&4 ;;
-       * )     case "\$${f}_r_proto" in
+        }
+        $seenh{$func}->{$p}++;
+        push @{$seena{$func}}, $p;
+        $seenp{$p}++;
+        $seent{$func} = $type;
+        $seens{$func} = $m{S};
+        $seend{$func} = $m{D};
+       $seenm{$func} = \%m;
+    }
+    if ($opts{U}) {
+       print <<EOF;
+       case "\$${func}_r_proto" in
+       ''|0)   d_${func}_r=undef
+               ${func}_r_proto=0
+               echo "Disabling ${func}_r, cannot determine prototype." >&4 ;;
+       * )     case "\$${func}_r_proto" in
                REENTRANT_PROTO*) ;;
-               *) ${f}_r_proto="REENTRANT_PROTO_\$${f}_r_proto" ;;
+               *) ${func}_r_proto="REENTRANT_PROTO_\$${func}_r_proto" ;;
                esac
                echo "Prototype: \$try" ;;
        esac
        ;;
        *)      case "\$usethreads" in
-               define) echo "${f}_r has no prototype, not using it." >&4 ;;
+               define) echo "${func}_r has no prototype, not using it." >&4 ;;
                esac
-               d_${f}_r=undef
-               ${f}_r_proto=0
+               d_${func}_r=undef
+               ${func}_r_proto=0
                ;;
        esac
        ;;
-*)     ${f}_r_proto=0
+*)     ${func}_r_proto=0
        ;;
 esac
 
@@ -272,9 +314,12 @@ EOF
 
 close DATA;
 
+# Prepare to continue writing the reentr.h.
+
 select H;
 
 {
+    # Write out all the known prototype signatures.
     my $i = 1;
     for my $p (sort keys %seenp) {
        print "#define REENTRANT_PROTO_${p}     ${i}\n";
@@ -282,18 +327,18 @@ select H;
     }
 }
 
+my @struct; # REENTR struct members
+my @size;   # struct member buffer size initialization code
+my @init;   # struct member buffer initialization (malloc) code
+my @free;   # struct member buffer release (free) code
+my @wrap;   # the wrapper (foo(a) -> foo_r(a,...)) cpp code
+my @define; # defines for optional features
+
 sub ifprotomatch {
-    my $F = shift;
-    join " || ", map { "${F}_R_PROTO == REENTRANT_PROTO_$_" } @_;
+    my $FUNC = shift;
+    join " || ", map { "${FUNC}_R_PROTO == REENTRANT_PROTO_$_" } @_;
 }
 
-my @struct;
-my @size;
-my @init;
-my @free;
-my @wrap;
-my @define;
-
 sub pushssif {
     push @struct, @_;
     push @size, @_;
@@ -302,12 +347,12 @@ sub pushssif {
 }
 
 sub pushinitfree {
-    my $f = shift;
+    my $func = shift;
     push @init, <<EOF;
-       New(31338, PL_reentrant_buffer->_${f}_buffer, PL_reentrant_buffer->_${f}_size, char);
+       Newx(PL_reentrant_buffer->_${func}_buffer, PL_reentrant_buffer->_${func}_size, char);
 EOF
     push @free, <<EOF;
-       Safefree(PL_reentrant_buffer->_${f}_buffer);
+       Safefree(PL_reentrant_buffer->_${func}_buffer);
 EOF
 }
 
@@ -319,22 +364,28 @@ sub define {
 /* The @F using \L$n? */
 
 EOF
-    for my $f (@F) {
-       my $F = uc $f;
-       my $h = "${F}_R_HAS_$n";
-       push @H, $h;
-       my @h = grep { /$p/ } @{$seena{$f}};
+    my $GENFUNC;
+    for my $func (@F) {
+       my $FUNC = uc $func;
+       my $HAS = "${FUNC}_R_HAS_$n";
+       push @H, $HAS;
+       my @h = grep { /$p/ } @{$seena{$func}};
+       unless (defined $GENFUNC) {
+           $GENFUNC = $FUNC;
+           $GENFUNC =~ s/^GET//;
+       }
        if (@h) {
-           push @define, "#if defined(HAS_${F}_R) && (" . join(" || ", map { "${F}_R_PROTO == REENTRANT_PROTO_$_" } @h) . ")\n";
+           push @define, "#if defined(HAS_${FUNC}_R) && (" . join(" || ", map { "${FUNC}_R_PROTO == REENTRANT_PROTO_$_" } @h) . ")\n";
 
            push @define, <<EOF;
-#   define $h
+#   define $HAS
 #else
-#   undef  $h
+#   undef  $HAS
 #endif
 EOF
         }
     }
+    return if @F == 1;
     push @define, <<EOF;
 
 /* Any of the @F using \L$n? */
@@ -342,9 +393,9 @@ EOF
 EOF
     push @define, "#if (" . join(" || ", map { "defined($_)" } @H) . ")\n";
     push @define, <<EOF;
-#   define USE_${H}_$n
+#   define USE_${GENFUNC}_$n
 #else
-#   undef  USE_${H}_$n
+#   undef  USE_${GENFUNC}_$n
 #endif
 
 EOF
@@ -361,9 +412,9 @@ define('PTR',  'R',
        qw(getspent getspnam));
 
 define('FPTR', 'H',
-       qw(getgrent getgrgid getgrnam));
+       qw(getgrent getgrgid getgrnam setgrent endgrent));
 define('FPTR', 'H',
-       qw(getpwent getpwnam getpwuid));
+       qw(getpwent getpwnam getpwuid setpwent endpwent));
 
 define('BUFFER',  'B',
        qw(getpwent getpwgid getpwnam));
@@ -391,167 +442,191 @@ define('ERRNO', 'E',
 define('ERRNO', 'E',
        qw(getnetent getnetbyaddr getnetbyname));
 
-for my $f (@seenf) {
-    my $F = uc $f;
-    my $ifdef = "#ifdef HAS_${F}_R\n";
-    my $endif = "#endif /* HAS_${F}_R */\n";
-    if (exists $seena{$f}) {
-       my @p = @{$seena{$f}};
-       if ($f =~ /^(asctime|ctime|getlogin|setlocale|strerror|ttyname)$/) {
+# The following loop accumulates the "ssif" (struct, size, init, free)
+# sections that declare the struct members (in reentr.h), and the buffer
+# size initialization, buffer initialization (malloc), and buffer
+# release (free) code (in reentr.c).
+#
+# The loop also contains a lot of intrinsic logic about groups of
+# functions (since functions of certain kind operate the same way).
+
+for my $func (@seenf) {
+    my $FUNC = uc $func;
+    my $ifdef = "#ifdef HAS_${FUNC}_R\n";
+    my $endif = "#endif /* HAS_${FUNC}_R */\n";
+    if (exists $seena{$func}) {
+       my @p = @{$seena{$func}};
+       if ($func =~ /^(asctime|ctime|getlogin|setlocale|strerror|ttyname)$/) {
            pushssif $ifdef;
            push @struct, <<EOF;
-       char*   _${f}_buffer;
-       size_t  _${f}_size;
+       char*   _${func}_buffer;
+       size_t  _${func}_size;
 EOF
            push @size, <<EOF;
-       PL_reentrant_buffer->_${f}_size = REENTRANTSMALLSIZE;
+       PL_reentrant_buffer->_${func}_size = REENTRANTSMALLSIZE;
 EOF
-           pushinitfree $f;
+           pushinitfree $func;
            pushssif $endif;
        }
-        elsif ($f =~ /^(crypt)$/) {
+        elsif ($func =~ /^(crypt)$/) {
            pushssif $ifdef;
            push @struct, <<EOF;
 #if CRYPT_R_PROTO == REENTRANT_PROTO_B_CCD
-       $seend{$f} _${f}_data;
+       $seend{$func} _${func}_data;
 #else
-       $seent{$f} _${f}_struct;
+       $seent{$func} *_${func}_struct_buffer;
 #endif
 EOF
            push @init, <<EOF;
-#ifdef __GLIBC__
-       PL_reentrant_buffer->_${f}_struct.initialized = 0;
+#if CRYPT_R_PROTO != REENTRANT_PROTO_B_CCD
+       PL_reentrant_buffer->_${func}_struct_buffer = 0;
+#endif
+EOF
+           push @free, <<EOF;
+#if CRYPT_R_PROTO != REENTRANT_PROTO_B_CCD
+       Safefree(PL_reentrant_buffer->_${func}_struct_buffer);
 #endif
 EOF
            pushssif $endif;
        }
-        elsif ($f =~ /^(drand48|gmtime|localtime|random)$/) {
+        elsif ($func =~ /^(drand48|gmtime|localtime|random|srandom)$/) {
            pushssif $ifdef;
            push @struct, <<EOF;
-       $seent{$f} _${f}_struct;
+       $seent{$func} _${func}_struct;
 EOF
            if ($1 eq 'drand48') {
                push @struct, <<EOF;
-       double  _${f}_double;
+       double  _${func}_double;
+EOF
+           } elsif ($1 eq 'random') {
+           push @struct, <<EOF;
+#   if RANDOM_R_PROTO == REENTRANT_PROTO_I_iS
+       int     _${func}_retval;
+#   endif
+#   if RANDOM_R_PROTO == REENTRANT_PROTO_I_lS
+       long    _${func}_retval;
+#   endif
+#   if RANDOM_R_PROTO == REENTRANT_PROTO_I_St
+       int32_t _${func}_retval;
+#   endif
 EOF
            }
            pushssif $endif;
        }
-        elsif ($f =~ /^(getgrnam|getpwnam|getspnam)$/) {
+        elsif ($func =~ /^(getgrnam|getpwnam|getspnam)$/) {
            pushssif $ifdef;
-           my $g = $f;
-           $g =~ s/nam/ent/g;
-           my $G = uc $g;
+           # 'genfunc' can be read either as 'generic' or 'genre',
+           # it represents a group of functions.
+           my $genfunc = $func;
+           $genfunc =~ s/nam/ent/g;
+           $genfunc =~ s/^get//;
+           my $GENFUNC = uc $genfunc;
            push @struct, <<EOF;
-       $seent{$f}      _${g}_struct;
-       char*   _${g}_buffer;
-       size_t  _${g}_size;
+       $seent{$func}   _${genfunc}_struct;
+       char*   _${genfunc}_buffer;
+       size_t  _${genfunc}_size;
 EOF
             push @struct, <<EOF;
-#   ifdef USE_${G}_PTR
-       $seent{$f}*     _${g}_ptr;
+#   ifdef USE_${GENFUNC}_PTR
+       $seent{$func}*  _${genfunc}_ptr;
 #   endif
 EOF
-           if ($g eq 'getspent') {
-               push @size, <<EOF;
-       PL_reentrant_buffer->_${g}_size = 1024;
-EOF
-           } else {
-               push @struct, <<EOF;
-#   ifdef USE_${G}_FPTR
-       FILE*   _${g}_fptr;
+           push @struct, <<EOF;
+#   ifdef USE_${GENFUNC}_FPTR
+       FILE*   _${genfunc}_fptr;
 #   endif
 EOF
-                   push @init, <<EOF;
-#   ifdef USE_${G}_FPTR
-       PL_reentrant_buffer->_${g}_fptr = NULL;
+           push @init, <<EOF;
+#   ifdef USE_${GENFUNC}_FPTR
+       PL_reentrant_buffer->_${genfunc}_fptr = NULL;
 #   endif
 EOF
-               my $sc = $g eq 'getgrent' ?
+           my $sc = $genfunc eq 'grent' ?
                    '_SC_GETGR_R_SIZE_MAX' : '_SC_GETPW_R_SIZE_MAX';
-               push @size, <<EOF;
+           my $sz = "_${genfunc}_size";
+           push @size, <<EOF;
 #   if defined(HAS_SYSCONF) && defined($sc) && !defined(__GLIBC__)
-       PL_reentrant_buffer->_${g}_size = sysconf($sc);
-       if (PL_reentrant_buffer->_getgrent_size == -1)
-               PL_reentrant_buffer->_getgrent_size = REENTRANTUSUALSIZE;
+       PL_reentrant_buffer->$sz = sysconf($sc);
+       if (PL_reentrant_buffer->$sz == -1)
+               PL_reentrant_buffer->$sz = REENTRANTUSUALSIZE;
 #   else
 #       if defined(__osf__) && defined(__alpha) && defined(SIABUFSIZ)
-       PL_reentrant_buffer->_${g}_size = SIABUFSIZ;
+       PL_reentrant_buffer->$sz = SIABUFSIZ;
 #       else
 #           ifdef __sgi
-       PL_reentrant_buffer->_${g}_size = BUFSIZ;
+       PL_reentrant_buffer->$sz = BUFSIZ;
 #           else
-       PL_reentrant_buffer->_${g}_size = REENTRANTUSUALSIZE;
+       PL_reentrant_buffer->$sz = REENTRANTUSUALSIZE;
 #           endif
 #       endif
 #   endif 
 EOF
-            }
-           pushinitfree $g;
+           pushinitfree $genfunc;
            pushssif $endif;
        }
-        elsif ($f =~ /^(gethostbyname|getnetbyname|getservbyname|getprotobyname)$/) {
+        elsif ($func =~ /^(gethostbyname|getnetbyname|getservbyname|getprotobyname)$/) {
            pushssif $ifdef;
-           my $g = $f;
-           $g =~ s/byname/ent/;
-           my $G = uc $g;
-           my $D = ifprotomatch($F, grep {/D/} @p);
-           my $d = $seend{$f};
+           my $genfunc = $func;
+           $genfunc =~ s/byname/ent/;
+           $genfunc =~ s/^get//;
+           my $GENFUNC = uc $genfunc;
+           my $D = ifprotomatch($FUNC, grep {/D/} @p);
+           my $d = $seend{$func};
            $d =~ s/\*$//; # snip: we need need the base type.
            push @struct, <<EOF;
-       $seent{$f}      _${g}_struct;
+       $seent{$func}   _${genfunc}_struct;
 #   if $D
-       $d      _${g}_data;
+       $d      _${genfunc}_data;
 #   else
-       char*   _${g}_buffer;
-       size_t  _${g}_size;
+       char*   _${genfunc}_buffer;
+       size_t  _${genfunc}_size;
 #   endif
-#   ifdef USE_${G}_PTR
-       $seent{$f}*     _${g}_ptr;
+#   ifdef USE_${GENFUNC}_PTR
+       $seent{$func}*  _${genfunc}_ptr;
 #   endif
 EOF
            push @struct, <<EOF;
-#   ifdef USE_${G}_ERRNO
-       int     _${g}_errno;
+#   ifdef USE_${GENFUNC}_ERRNO
+       int     _${genfunc}_errno;
 #   endif 
 EOF
            push @size, <<EOF;
 #if   !($D)
-       PL_reentrant_buffer->_${g}_size = REENTRANTUSUALSIZE;
+       PL_reentrant_buffer->_${genfunc}_size = REENTRANTUSUALSIZE;
 #endif
 EOF
            push @init, <<EOF;
 #if   !($D)
-       New(31338, PL_reentrant_buffer->_${g}_buffer, PL_reentrant_buffer->_${g}_size, char);
+       Newx(PL_reentrant_buffer->_${genfunc}_buffer, PL_reentrant_buffer->_${genfunc}_size, char);
 #endif
 EOF
            push @free, <<EOF;
 #if   !($D)
-       Safefree(PL_reentrant_buffer->_${g}_buffer);
+       Safefree(PL_reentrant_buffer->_${genfunc}_buffer);
 #endif
 EOF
            pushssif $endif;
        }
-        elsif ($f =~ /^(readdir|readdir64)$/) {
+        elsif ($func =~ /^(readdir|readdir64)$/) {
            pushssif $ifdef;
-           my $R = ifprotomatch($F, grep {/R/} @p);
+           my $R = ifprotomatch($FUNC, grep {/R/} @p);
            push @struct, <<EOF;
-       $seent{$f}*     _${f}_struct;
-       size_t  _${f}_size;
+       $seent{$func}*  _${func}_struct;
+       size_t  _${func}_size;
 #   if $R
-       $seent{$f}*     _${f}_ptr;
+       $seent{$func}*  _${func}_ptr;
 #   endif
 EOF
            push @size, <<EOF;
        /* This is the size Solaris recommends.
         * (though we go static, should use pathconf() instead) */
-       PL_reentrant_buffer->_${f}_size = sizeof($seent{$f}) + MAXPATHLEN + 1;
+       PL_reentrant_buffer->_${func}_size = sizeof($seent{$func}) + MAXPATHLEN + 1;
 EOF
            push @init, <<EOF;
-       PL_reentrant_buffer->_${f}_struct = ($seent{$f}*)safemalloc(PL_reentrant_buffer->_${f}_size);
+       PL_reentrant_buffer->_${func}_struct = ($seent{$func}*)safemalloc(PL_reentrant_buffer->_${func}_size);
 EOF
            push @free, <<EOF;
-       Safefree(PL_reentrant_buffer->_${f}_struct);
+       Safefree(PL_reentrant_buffer->_${func}_struct);
 EOF
            pushssif $endif;
        }
@@ -559,79 +634,100 @@ EOF
        push @wrap, $ifdef;
 
        push @wrap, <<EOF;
-#   undef $f
+#   undef $func
 EOF
+
+        # Write out what we have learned.
+       
         my @v = 'a'..'z';
-        my $v = join(", ", @v[0..$seenu{$f}-1]);
+        my $v = join(", ", @v[0..$seenu{$func}-1]);
        for my $p (@p) {
            my ($r, $a) = split '_', $p;
            my $test = $r eq 'I' ? ' == 0' : '';
            my $true  = 1;
-           my $g = $f;
-           if ($g =~ /^(?:get|set|end)(pw|gr|host|net|proto|serv|sp)/) {
-               $g = "get$1ent";
-           } elsif ($g eq 'srand48') {
-               $g = "drand48";
+           my $genfunc = $func;
+           if ($genfunc =~ /^(?:get|set|end)(pw|gr|host|net|proto|serv|sp)/) {
+               $genfunc = "${1}ent";
+           } elsif ($genfunc eq 'srand48') {
+               $genfunc = "drand48";
            }
            my $b = $a;
            my $w = '';
-           substr($b, 0, $seenu{$f}) = '';
-           if ($b =~ /R/) {
-               $true = "PL_reentrant_buffer->_${g}_ptr";
-           } elsif ($b =~ /T/ && $f eq 'drand48') {
-               $true = "PL_reentrant_buffer->_${g}_double";
+           substr($b, 0, $seenu{$func}) = '';
+           if ($func =~ /^random$/) {
+               $true = "PL_reentrant_buffer->_random_retval";
+           } elsif ($b =~ /R/) {
+               $true = "PL_reentrant_buffer->_${genfunc}_ptr";
+           } elsif ($b =~ /T/ && $func eq 'drand48') {
+               $true = "PL_reentrant_buffer->_${genfunc}_double";
            } elsif ($b =~ /S/) {
-               if ($f =~ /^readdir/) {
-                   $true = "PL_reentrant_buffer->_${g}_struct";
+               if ($func =~ /^readdir/) {
+                   $true = "PL_reentrant_buffer->_${genfunc}_struct";
                } else {
-                   $true = "&PL_reentrant_buffer->_${g}_struct";
+                   $true = "&PL_reentrant_buffer->_${genfunc}_struct";
                }
            } elsif ($b =~ /B/) {
-               $true = "PL_reentrant_buffer->_${g}_buffer";
+               $true = "PL_reentrant_buffer->_${genfunc}_buffer";
            }
            if (length $b) {
                $w = join ", ",
                         map {
                             $_ eq 'R' ?
-                                "&PL_reentrant_buffer->_${g}_ptr" :
+                                "&PL_reentrant_buffer->_${genfunc}_ptr" :
                             $_ eq 'E' ?
-                                "&PL_reentrant_buffer->_${g}_errno" :
+                                "&PL_reentrant_buffer->_${genfunc}_errno" :
                             $_ eq 'B' ?
-                                "PL_reentrant_buffer->_${g}_buffer" :
+                                "PL_reentrant_buffer->_${genfunc}_buffer" :
                             $_ =~ /^[WI]$/ ?
-                                "PL_reentrant_buffer->_${g}_size" :
+                                "PL_reentrant_buffer->_${genfunc}_size" :
                             $_ eq 'H' ?
-                                "&PL_reentrant_buffer->_${g}_fptr" :
+                                "&PL_reentrant_buffer->_${genfunc}_fptr" :
                             $_ eq 'D' ?
-                                "&PL_reentrant_buffer->_${g}_data" :
+                                "&PL_reentrant_buffer->_${genfunc}_data" :
                             $_ eq 'S' ?
-                                ($f =~ /^readdir/ ?
-                                 "PL_reentrant_buffer->_${g}_struct" :
-                                 "&PL_reentrant_buffer->_${g}_struct" ) :
-                            $_ eq 'T' && $f eq 'drand48' ?
-                                "&PL_reentrant_buffer->_${g}_double" :
+                                ($func =~ /^readdir\d*$/ ?
+                                 "PL_reentrant_buffer->_${genfunc}_struct" :
+                                 $func =~ /^crypt$/ ?
+                                 "PL_reentrant_buffer->_${genfunc}_struct_buffer" :
+                                 "&PL_reentrant_buffer->_${genfunc}_struct") :
+                            $_ eq 'T' && $func eq 'drand48' ?
+                                "&PL_reentrant_buffer->_${genfunc}_double" :
+                            $_ =~ /^[ilt]$/ && $func eq 'random' ?
+                                "&PL_reentrant_buffer->_random_retval" :
                                 $_
                         } split '', $b;
                $w = ", $w" if length $v;
            }
-           my $call = "${f}_r($v$w)";
-           $call = "((errno = $call))" if $r eq 'I';
+           my $call = "${func}_r($v$w)";
+
+            # Must make OpenBSD happy
+            my $memzero = '';
+            if($p =~ /D$/ &&
+                ($genfunc eq 'protoent' || $genfunc eq 'servent')) {
+                $memzero = 'REENTR_MEMZERO(&PL_reentrant_buffer->_' . $genfunc . '_data, sizeof(PL_reentrant_buffer->_' . $genfunc . '_data))';
+            }
            push @wrap, <<EOF;
-#   if !defined($f) && ${F}_R_PROTO == REENTRANT_PROTO_$p
+#   if !defined($func) && ${FUNC}_R_PROTO == REENTRANT_PROTO_$p
 EOF
            if ($r eq 'V' || $r eq 'B') {
                push @wrap, <<EOF;
-#       define $f($v) $call
+#       define $func($v) $call
 EOF
            } else {
-               if ($f =~ /^get/) {
+               if ($func =~ /^get/) {
                    my $rv = $v ? ", $v" : "";
-                   push @wrap, <<EOF;
-#       define $f($v) ($call$test ? $true : (errno == ERANGE ? Perl_reentrant_retry("$f"$rv) : 0))
+                   if ($r eq 'I') {
+                       push @wrap, <<EOF;
+#       define $func($v) ($memzero(PL_reentrant_retint = $call)$test ? $true : ((PL_reentrant_retint == ERANGE) ? ($seent{$func} *) Perl_reentrant_retry("$func"$rv) : 0))
 EOF
+                   } else {
+                       push @wrap, <<EOF;
+#       define $func($v) ($call$test ? $true : ((errno == ERANGE) ? ($seent{$func} *) Perl_reentrant_retry("$func"$rv) : 0))
+EOF
+                    }
                } else {
                    push @wrap, <<EOF;
-#       define $f($v) ($call$test ? $true : 0)
+#       define $func($v) ($call$test ? $true : 0)
 EOF
                }
            }
@@ -653,36 +749,50 @@ print <<EOF;
 @define
 typedef struct {
 @struct
+    int dummy; /* cannot have empty structs */
 } REENTR;
 
 /* The wrappers. */
 
 @wrap
+
 #endif /* USE_REENTRANT_API */
  
 #endif
 
+/* ex: set ro: */
 EOF
 
 close(H);
 
+# Prepare to write the reentr.c.
+
+safer_unlink 'reentr.c';
 die "reentr.c: $!" unless open(C, ">reentr.c");
+binmode C;
 select C;
 print <<EOF;
-/*
+/* -*- buffer-read-only: t -*-
+ *
  *    reentr.c
  *
- *    Copyright (c) 1997-2002, Larry Wall
+ *    Copyright (C) 2002, 2003, 2005, 2006 by Larry Wall and others
  *
  *    You may distribute under the terms of either the GNU General Public
  *    License or the Artistic License, as specified in the README file.
  *
  *  !!!!!!!   DO NOT EDIT THIS FILE   !!!!!!!
- *  This file is built by reentrl.pl from data in reentr.pl.
+ *  This file is built by reentr.pl from data in reentr.pl.
  *
  * "Saruman," I said, standing away from him, "only one hand at a time can
  *  wield the One, and you know that well, so do not trouble to say we!"
  *
+ * This file contains a collection of automatically created wrappers
+ * (created by running reentr.pl) for reentrant (thread-safe) versions of
+ * various library calls, such as getpwent_r.  The wrapping is done so
+ * that other files like pp_sys.c calling those library functions need not
+ * care about the differences between various platforms' idiosyncrasies
+ * regarding these reentrant interfaces.  
  */
 
 #include "EXTERN.h"
@@ -702,7 +812,7 @@ Perl_reentrant_size(pTHX) {
 void
 Perl_reentrant_init(pTHX) {
 #ifdef USE_REENTRANT_API
-       New(31337, PL_reentrant_buffer, 1, REENTR);
+       Newx(PL_reentrant_buffer, 1, REENTR);
        Perl_reentrant_size(aTHX);
 @init
 #endif /* USE_REENTRANT_API */
@@ -722,25 +832,36 @@ Perl_reentrant_retry(const char *f, ...)
     dTHX;
     void *retptr = NULL;
 #ifdef USE_REENTRANT_API
-    void *p0, *p1;
+#  if defined(USE_HOSTENT_BUFFER) || defined(USE_GRENT_BUFFER) || defined(USE_NETENT_BUFFER) || defined(USE_PWENT_BUFFER) || defined(USE_PROTOENT_BUFFER) || defined(USE_SERVENT_BUFFER)
+    void *p0;
+#  endif
+#  if defined(USE_SERVENT_BUFFER)
+    void *p1;
+#  endif
+#  if defined(USE_HOSTENT_BUFFER)
     size_t asize;
+#  endif
+#  if defined(USE_HOSTENT_BUFFER) || defined(USE_NETENT_BUFFER) || defined(USE_PROTOENT_BUFFER) || defined(USE_SERVENT_BUFFER)
     int anint;
+#  endif
     va_list ap;
 
     va_start(ap, f);
 
-#define REENTRANTHALFMAXSIZE 32768 /* The maximum may end up twice this. */
-
     switch (PL_op->op_type) {
-#ifdef USE_GETHOSTENT_BUFFER
+#ifdef USE_HOSTENT_BUFFER
     case OP_GHBYADDR:
     case OP_GHBYNAME:
     case OP_GHOSTENT:
        {
-           if (PL_reentrant_buffer->_gethostent_size <= REENTRANTHALFMAXSIZE) {
-               PL_reentrant_buffer->_gethostent_size *= 2;
-               Renew(PL_reentrant_buffer->_gethostent_buffer,
-                     PL_reentrant_buffer->_gethostent_size, char);
+#ifdef PERL_REENTRANT_MAXSIZE
+           if (PL_reentrant_buffer->_hostent_size <=
+               PERL_REENTRANT_MAXSIZE / 2)
+#endif
+           {
+               PL_reentrant_buffer->_hostent_size *= 2;
+               Renew(PL_reentrant_buffer->_hostent_buffer,
+                     PL_reentrant_buffer->_hostent_size, char);
                switch (PL_op->op_type) {
                case OP_GHBYADDR:
                    p0    = va_arg(ap, void *);
@@ -749,52 +870,66 @@ Perl_reentrant_retry(const char *f, ...)
                    retptr = gethostbyaddr(p0, asize, anint); break;
                case OP_GHBYNAME:
                    p0 = va_arg(ap, void *);
-                   retptr = gethostbyname(p0); break;
+                   retptr = gethostbyname((char *)p0); break;
                case OP_GHOSTENT:
                    retptr = gethostent(); break;
                default:
+                   SETERRNO(ERANGE, LIB_INVARG);
                    break;
                }
            }
        }
        break;
 #endif
-#ifdef USE_GETGRENT_BUFFER
+#ifdef USE_GRENT_BUFFER
     case OP_GGRNAM:
     case OP_GGRGID:
     case OP_GGRENT:
        {
-           if (PL_reentrant_buffer->_getgrent_size <= REENTRANTHALFMAXSIZE) {
+#ifdef PERL_REENTRANT_MAXSIZE
+           if (PL_reentrant_buffer->_grent_size <=
+               PERL_REENTRANT_MAXSIZE / 2)
+#endif
+           {
                Gid_t gid;
-               PL_reentrant_buffer->_getgrent_size *= 2;
-               Renew(PL_reentrant_buffer->_getgrent_buffer,
-                     PL_reentrant_buffer->_getgrent_size, char);
+               PL_reentrant_buffer->_grent_size *= 2;
+               Renew(PL_reentrant_buffer->_grent_buffer,
+                     PL_reentrant_buffer->_grent_size, char);
                switch (PL_op->op_type) {
                case OP_GGRNAM:
                    p0 = va_arg(ap, void *);
-                   retptr = getgrnam(p0); break;
+                   retptr = getgrnam((char *)p0); break;
                case OP_GGRGID:
+#if Gid_t_size < INTSIZE
+                   gid = (Gid_t)va_arg(ap, int);
+#else
                    gid = va_arg(ap, Gid_t);
+#endif
                    retptr = getgrgid(gid); break;
                case OP_GGRENT:
                    retptr = getgrent(); break;
                default:
+                   SETERRNO(ERANGE, LIB_INVARG);
                    break;
                }
            }
        }
        break;
 #endif
-#ifdef USE_GETNETENT_BUFFER
+#ifdef USE_NETENT_BUFFER
     case OP_GNBYADDR:
     case OP_GNBYNAME:
     case OP_GNETENT:
        {
-           if (PL_reentrant_buffer->_getnetent_size <= REENTRANTHALFMAXSIZE) {
+#ifdef PERL_REENTRANT_MAXSIZE
+           if (PL_reentrant_buffer->_netent_size <=
+               PERL_REENTRANT_MAXSIZE / 2)
+#endif
+           {
                Netdb_net_t net;
-               PL_reentrant_buffer->_getnetent_size *= 2;
-               Renew(PL_reentrant_buffer->_getnetent_buffer,
-                     PL_reentrant_buffer->_getnetent_size, char);
+               PL_reentrant_buffer->_netent_size *= 2;
+               Renew(PL_reentrant_buffer->_netent_buffer,
+                     PL_reentrant_buffer->_netent_size, char);
                switch (PL_op->op_type) {
                case OP_GNBYADDR:
                    net = va_arg(ap, Netdb_net_t);
@@ -802,88 +937,108 @@ Perl_reentrant_retry(const char *f, ...)
                    retptr = getnetbyaddr(net, anint); break;
                case OP_GNBYNAME:
                    p0 = va_arg(ap, void *);
-                   retptr = getnetbyname(p0); break;
+                   retptr = getnetbyname((char *)p0); break;
                case OP_GNETENT:
                    retptr = getnetent(); break;
                default:
+                   SETERRNO(ERANGE, LIB_INVARG);
                    break;
                }
            }
        }
        break;
 #endif
-#ifdef USE_GETPWENT_BUFFER
+#ifdef USE_PWENT_BUFFER
     case OP_GPWNAM:
     case OP_GPWUID:
     case OP_GPWENT:
        {
-           if (PL_reentrant_buffer->_getpwent_size <= REENTRANTHALFMAXSIZE) {
+#ifdef PERL_REENTRANT_MAXSIZE
+           if (PL_reentrant_buffer->_pwent_size <=
+               PERL_REENTRANT_MAXSIZE / 2)
+#endif
+           {
                Uid_t uid;
-               PL_reentrant_buffer->_getpwent_size *= 2;
-               Renew(PL_reentrant_buffer->_getpwent_buffer,
-                     PL_reentrant_buffer->_getpwent_size, char);
+               PL_reentrant_buffer->_pwent_size *= 2;
+               Renew(PL_reentrant_buffer->_pwent_buffer,
+                     PL_reentrant_buffer->_pwent_size, char);
                switch (PL_op->op_type) {
                case OP_GPWNAM:
                    p0 = va_arg(ap, void *);
-                   retptr = getpwnam(p0); break;
+                   retptr = getpwnam((char *)p0); break;
                case OP_GPWUID:
+#if Uid_t_size < INTSIZE
+                   uid = (Uid_t)va_arg(ap, int);
+#else
                    uid = va_arg(ap, Uid_t);
+#endif
                    retptr = getpwuid(uid); break;
                case OP_GPWENT:
                    retptr = getpwent(); break;
                default:
+                   SETERRNO(ERANGE, LIB_INVARG);
                    break;
                }
            }
        }
        break;
 #endif
-#ifdef USE_GETPROTOENT_BUFFER
+#ifdef USE_PROTOENT_BUFFER
     case OP_GPBYNAME:
     case OP_GPBYNUMBER:
     case OP_GPROTOENT:
        {
-           if (PL_reentrant_buffer->_getprotoent_size <= REENTRANTHALFMAXSIZE) {
-               PL_reentrant_buffer->_getprotoent_size *= 2;
-               Renew(PL_reentrant_buffer->_getprotoent_buffer,
-                     PL_reentrant_buffer->_getprotoent_size, char);
+#ifdef PERL_REENTRANT_MAXSIZE
+           if (PL_reentrant_buffer->_protoent_size <=
+               PERL_REENTRANT_MAXSIZE / 2)
+#endif
+           {
+               PL_reentrant_buffer->_protoent_size *= 2;
+               Renew(PL_reentrant_buffer->_protoent_buffer,
+                     PL_reentrant_buffer->_protoent_size, char);
                switch (PL_op->op_type) {
                case OP_GPBYNAME:
                    p0 = va_arg(ap, void *);
-                   retptr = getprotobyname(p0); break;
+                   retptr = getprotobyname((char *)p0); break;
                case OP_GPBYNUMBER:
                    anint = va_arg(ap, int);
                    retptr = getprotobynumber(anint); break;
                case OP_GPROTOENT:
                    retptr = getprotoent(); break;
                default:
+                   SETERRNO(ERANGE, LIB_INVARG);
                    break;
                }
            }
        }
        break;
 #endif
-#ifdef USE_GETSERVENT_BUFFER
+#ifdef USE_SERVENT_BUFFER
     case OP_GSBYNAME:
     case OP_GSBYPORT:
     case OP_GSERVENT:
        {
-           if (PL_reentrant_buffer->_getservent_size <= REENTRANTHALFMAXSIZE) {
-               PL_reentrant_buffer->_getservent_size *= 2;
-               Renew(PL_reentrant_buffer->_getservent_buffer,
-                     PL_reentrant_buffer->_getservent_size, char);
+#ifdef PERL_REENTRANT_MAXSIZE
+           if (PL_reentrant_buffer->_servent_size <=
+               PERL_REENTRANT_MAXSIZE / 2)
+#endif
+           {
+               PL_reentrant_buffer->_servent_size *= 2;
+               Renew(PL_reentrant_buffer->_servent_buffer,
+                     PL_reentrant_buffer->_servent_size, char);
                switch (PL_op->op_type) {
                case OP_GSBYNAME:
                    p0 = va_arg(ap, void *);
                    p1 = va_arg(ap, void *);
-                   retptr = getservbyname(p0, p1); break;
+                   retptr = getservbyname((char *)p0, (char *)p1); break;
                case OP_GSBYPORT:
                    anint = va_arg(ap, int);
                    p0 = va_arg(ap, void *);
-                   retptr = getservbyport(anint, p0); break;
+                   retptr = getservbyport(anint, (char *)p0); break;
                case OP_GSERVENT:
                    retptr = getservent(); break;
                default:
+                   SETERRNO(ERANGE, LIB_INVARG);
                    break;
                }
            }
@@ -896,10 +1051,13 @@ Perl_reentrant_retry(const char *f, ...)
     }
 
     va_end(ap);
+#else
+    PERL_UNUSED_ARG(f);
 #endif
     return retptr;
 }
 
+/* ex: set ro: */
 EOF
 
 __DATA__
@@ -917,11 +1075,11 @@ endservent       |netdb  |               |I_D|V_D|D=struct servent_data*
 getgrent       |grp    |struct group   |I_SBWR|I_SBIR|S_SBW|S_SBI|I_SBI|I_SBIH
 getgrgid T     |grp    |struct group   |I_TSBWR|I_TSBIR|I_TSBI|S_TSBI|T=gid_t
 getgrnam C     |grp    |struct group   |I_CSBWR|I_CSBIR|S_CBI|I_CSBI|S_CSBI
-gethostbyaddr CWI      |netdb  |struct hostent |I_CWISBWRE|S_CWISBWIE|S_CWISBIE|S_TWISBIE|S_CIISBIE|S_CSBIE|S_TSBIE|I_CWISD|I_CIISD|I_CII|D=struct hostent_data*|T=const void*
+gethostbyaddr CWI      |netdb  |struct hostent |I_CWISBWRE|S_CWISBWIE|S_CWISBIE|S_TWISBIE|S_CIISBIE|S_CSBIE|S_TSBIE|I_CWISD|I_CIISD|I_CII|I_TsISBWRE|D=struct hostent_data*|T=const void*|s=socklen_t
 gethostbyname C        |netdb  |struct hostent |I_CSBWRE|S_CSBIE|I_CSD|D=struct hostent_data*
 gethostent     |netdb  |struct hostent |I_SBWRE|I_SBIE|S_SBIE|S_SBI|I_SBI|I_SD|D=struct hostent_data*
-getlogin       |unistd |               |I_BW|I_BI|B_BW|B_BI
-getnetbyaddr LI        |netdb  |struct netent  |I_UISBWRE|I_LISBI|S_TISBI|S_LISBI|I_TISD|I_LISD|I_IISD|D=struct netent_data*|T=in_addr_t|U=unsigned long
+getlogin       |unistd |char           |I_BW|I_BI|B_BW|B_BI
+getnetbyaddr LI        |netdb  |struct netent  |I_UISBWRE|I_LISBI|S_TISBI|S_LISBI|I_TISD|I_LISD|I_IISD|I_uISBWRE|D=struct netent_data*|T=in_addr_t|U=unsigned long|u=uint32_t
 getnetbyname C |netdb  |struct netent  |I_CSBWRE|I_CSBI|S_CSBI|I_CSD|D=struct netent_data*
 getnetent      |netdb  |struct netent  |I_SBWRE|I_SBIE|S_SBIE|S_SBI|I_SBI|I_SD|D=struct netent_data*
 getprotobyname C|netdb |struct protoent|I_CSBWR|S_CSBI|I_CSD|D=struct protoent_data*
@@ -936,7 +1094,7 @@ 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_TS|T=int*
+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*
 setgrent       |grp    |               |I_H|V_H