This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
Change docs display for PERL_UNUSED_foo
[perl5.git] / regen / reentr.pl
CommitLineData
10bc17b6 1#!/usr/bin/perl -w
7c1815b7 2#
6294c161
DM
3# Regenerate (overwriting only if changed):
4#
5# reentr.h
6# reentr.c
7#
8# from information stored in the DATA section of this file.
9#
10# With the -U option, it also unconditionally regenerates the relevant
11# metaconfig units:
12#
13# d_${func}_r.U
14#
15# Also accepts the standard regen_lib -q and -v args.
16#
17# This script is normally invoked from regen.pl.
10bc17b6 18
e06c4d37
NC
19BEGIN {
20 # Get function prototypes
3d7c117d 21 require './regen/regen_lib.pl';
e06c4d37
NC
22}
23
10bc17b6
JH
24use strict;
25use Getopt::Std;
26my %opts;
b6b9a099 27getopts('Uv', \%opts);
10bc17b6
JH
28
29my %map = (
30 V => "void",
31 A => "char*", # as an input argument
7c1815b7 32 B => "char*", # as an output argument
10bc17b6
JH
33 C => "const char*", # as a read-only input argument
34 I => "int",
35 L => "long",
36 W => "size_t",
37 H => "FILE**",
38 E => "int*",
39 );
40
41# (See the definitions after __DATA__.)
42# In func|inc|type|... a "S" means "type*", and a "R" means "type**".
43# (The "types" are often structs, such as "struct passwd".)
44#
45# After the prototypes one can have |X=...|Y=... to define more types.
46# A commonly used extra type is to define D to be equal to "type_data",
47# for example "struct_hostent_data to" go with "struct hostent".
48#
49# Example #1: I_XSBWR means int func_r(X, type, char*, size_t, type**)
50# Example #2: S_SBIE means type func_r(type, char*, int, int*)
51# Example #3: S_CBI means type func_r(const char*, char*, int)
52
d91994bb
NC
53sub open_print_header {
54 my ($file, $quote) = @_;
55 return open_new($file, '>',
56 { by => 'regen/reentr.pl',
57 from => 'data in regen/reentr.pl',
58 file => $file, style => '*',
59 copyright => [2002, 2003, 2005 .. 2007],
60 quote => $quote });
61}
10bc17b6 62
d91994bb 63my $h = open_print_header('reentr.h');
2d6469fe 64print $h <<EOF;
6a5bc5ac
KW
65#ifndef PERL_REENTR_H_
66#define PERL_REENTR_H_
10bc17b6 67
832a833b
JH
68/* If compiling for a threaded perl, we will macro-wrap the system/library
69 * interfaces (e.g. getpwent()) which have threaded versions
70 * (e.g. getpwent_r()), which will handle things correctly for
6f16cbe7
KW
71 * the Perl interpreter. This is done automatically for the perl core and
72 * extensions, but not generally for XS modules unless they
73 * #define PERL_REENTRANT
74 * See L<perlxs/Thread-aware system interfaces>.
7dc0f1bb
KW
75 *
76 * For a function 'foo', use the compile-time directive
77 * #ifdef PERL_REENTR_USING_FOO_R
78 * to test if the function actually did get replaced by the reentrant version.
79 * (If it isn't getting replaced, it might mean it uses a different prototype
80 * on the given platform than any we are expecting. To fix that, add the
81 * prototype to the __DATA__ section of regen/reentr.pl.)
832a833b
JH
82 */
83
84#ifndef PERL_REENTR_API
7c1815b7
KW
85# if defined(PERL_CORE) || defined(PERL_EXT) || defined(PERL_REENTRANT)
86# define PERL_REENTR_API 1
87# else
88# define PERL_REENTR_API 0
89# endif
832a833b
JH
90#endif
91
10bc17b6 92#ifdef USE_REENTRANT_API
7c1815b7 93
95fb10e3
KW
94/* For thread-safe builds, alternative methods are used to make calls to this
95 * safe. */
96#ifdef USE_THREAD_SAFE_LOCALE
97# undef HAS_SETLOCALE_R
98#endif
99
10bc17b6
JH
100/* Deprecations: some platforms have the said reentrant interfaces
101 * but they are declared obsolete and are not to be used. Often this
102 * means that the platform has threadsafed the interfaces (hopefully).
103 * All this is OS version dependent, so we are of course fooling ourselves.
832a833b
JH
104 * If you know of more deprecations on some platforms, please add your own
105 * (by editing reentr.pl, mind!) */
10bc17b6 106
7c1815b7
KW
107# ifdef __hpux
108# undef HAS_CRYPT_R
109# undef HAS_ENDGRENT_R
110# undef HAS_ENDPWENT_R
111# undef HAS_GETGRENT_R
112# undef HAS_GETPWENT_R
113# undef HAS_SETLOCALE_R
114# undef HAS_STRERROR_R
115# define NETDB_R_OBSOLETE
116# endif
10bc17b6 117
7c1815b7
KW
118# if defined(__osf__) && defined(__alpha) /* Tru64 aka Digital UNIX */
119# undef HAS_CRYPT_R
120# undef HAS_STRERROR_R
121# define NETDB_R_OBSOLETE
122# endif
10bc17b6 123
7c1815b7
KW
124# if defined(__GLIBC__) && (__GLIBC__ > 2 || (__GLIBC__ == 2 && __GLIBC_MINOR__ >= 24))
125# undef HAS_READDIR_R
126# undef HAS_READDIR64_R
127# endif
c6709bf9 128
23e2b7a9
SP
129/*
130 * As of OpenBSD 3.7, reentrant functions are now working, they just are
131 * incompatible with everyone else. To make OpenBSD happy, we have to
132 * memzero out certain structures before calling the functions.
133 */
7c1815b7 134# if defined(__OpenBSD__)
3fb2f3ac 135# define REENTR_MEMZERO(a,b) memzero(a,b)
7c1815b7 136# else
3fb2f3ac 137# define REENTR_MEMZERO(a,b) 0
7c1815b7 138# endif
10bc17b6 139
7c1815b7
KW
140# ifdef NETDB_R_OBSOLETE
141# undef HAS_ENDHOSTENT_R
142# undef HAS_ENDNETENT_R
143# undef HAS_ENDPROTOENT_R
144# undef HAS_ENDSERVENT_R
145# undef HAS_GETHOSTBYADDR_R
146# undef HAS_GETHOSTBYNAME_R
147# undef HAS_GETHOSTENT_R
148# undef HAS_GETNETBYADDR_R
149# undef HAS_GETNETBYNAME_R
150# undef HAS_GETNETENT_R
151# undef HAS_GETPROTOBYNAME_R
152# undef HAS_GETPROTOBYNUMBER_R
153# undef HAS_GETPROTOENT_R
154# undef HAS_GETSERVBYNAME_R
155# undef HAS_GETSERVBYPORT_R
156# undef HAS_GETSERVENT_R
157# undef HAS_SETHOSTENT_R
158# undef HAS_SETNETENT_R
159# undef HAS_SETPROTOENT_R
160# undef HAS_SETSERVENT_R
161# endif
162
163# ifdef I_PWD
164# include <pwd.h>
165# endif
166# ifdef I_GRP
167# include <grp.h>
168# endif
169# ifdef I_NETDB
170# include <netdb.h>
171# endif
172# ifdef I_CRYPT
173# ifdef I_CRYPT
174# include <crypt.h>
175# endif
176# endif
177# ifdef HAS_GETSPNAM_R
178# ifdef I_SHADOW
179# include <shadow.h>
180# endif
181# endif
10bc17b6
JH
182
183EOF
184
aa418cf1
JH
185my %seenh; # the different prototypes signatures for this function
186my %seena; # the different prototypes signatures for this function in order
187my @seenf; # all the seen functions
188my %seenp; # the different prototype signatures for all functions
189my %seent; # the return type of this function
190my %seens; # the type of this function's "S"
191my %seend; # the type of this function's "D"
a845a0d4 192my %seenm; # all the types
aa418cf1
JH
193my %seenu; # the length of the argument list of this function
194
b6a6e956 195while (<DATA>) { # Read in the protoypes.
10bc17b6
JH
196 next if /^\s+$/;
197 chomp;
aa418cf1 198 my ($func, $hdr, $type, @p) = split(/\s*\|\s*/, $_, -1);
10bc17b6 199 my $u;
aa418cf1
JH
200 # Split off the real function name and the argument list.
201 ($func, $u) = split(' ', $func);
202 $seenu{$func} = defined $u ? length $u : 0;
203 my $FUNC = uc $func; # for output.
204 push @seenf, $func;
10bc17b6 205 my %m = %map;
aa418cf1
JH
206 if ($type) {
207 $m{S} = "$type*";
208 $m{R} = "$type**";
10bc17b6 209 }
aa418cf1
JH
210
211 # Set any special mapping variables (like X=x_t)
10bc17b6
JH
212 if (@p) {
213 while ($p[-1] =~ /=/) {
214 my ($k, $v) = ($p[-1] =~ /^([A-Za-z])\s*=\s*(.*)/);
215 $m{$k} = $v;
216 pop @p;
217 }
218 }
aa418cf1
JH
219
220 # If given the -U option open up the metaconfig unit for this function.
1ae6ead9 221 if ($opts{U} && open(U, ">", "d_${func}_r.U")) {
7c1815b7 222 binmode U;
10bc17b6 223 }
aa418cf1 224
d63eadf0 225 if ($opts{U}) {
aa418cf1
JH
226 # The metaconfig units needs prerequisite dependencies.
227 my $prereqs = '';
228 my $prereqh = '';
229 my $prereqsh = '';
230 if ($hdr ne 'stdio') { # There's no i_stdio.
231 $prereqs = "i_$hdr";
232 $prereqh = "$hdr.h";
233 $prereqsh = "\$$prereqs $prereqh";
234 }
1fdb6f84
JH
235 my @prereq = qw(Inlibc Protochk Hasproto i_systypes usethreads);
236 push @prereq, $prereqs;
237 my $hdrs = "\$i_systypes sys/types.h define stdio.h $prereqsh";
aa418cf1 238 if ($hdr eq 'time') {
1fdb6f84
JH
239 $hdrs .= " \$i_systime sys/time.h";
240 push @prereq, 'i_systime';
241 }
aa418cf1 242 # Output the metaconfig unit header.
2d6469fe 243 print U <<"EOF";
aa418cf1 244?RCS: \$Id: d_${func}_r.U,v $
10bc17b6 245?RCS:
a845a0d4 246?RCS: Copyright (c) 2002,2003 Jarkko Hietaniemi
10bc17b6
JH
247?RCS:
248?RCS: You may distribute under the terms of either the GNU General Public
249?RCS: License or the Artistic License, as specified in the README file.
250?RCS:
251?RCS: Generated by the reentr.pl from the Perl 5.8 distribution.
252?RCS:
aa418cf1 253?MAKE:d_${func}_r ${func}_r_proto: @prereq
10bc17b6 254?MAKE: -pick add \$@ %<
aa418cf1
JH
255?S:d_${func}_r:
256?S: This variable conditionally defines the HAS_${FUNC}_R symbol,
257?S: which indicates to the C program that the ${func}_r()
10bc17b6
JH
258?S: routine is available.
259?S:.
aa418cf1
JH
260?S:${func}_r_proto:
261?S: This variable encodes the prototype of ${func}_r.
39183afa
JH
262?S: It is zero if d_${func}_r is undef, and one of the
263?S: REENTRANT_PROTO_T_ABC macros of reentr.h if d_${func}_r
264?S: is defined.
10bc17b6 265?S:.
aa418cf1
JH
266?C:HAS_${FUNC}_R:
267?C: This symbol, if defined, indicates that the ${func}_r routine
268?C: is available to ${func} re-entrantly.
10bc17b6 269?C:.
aa418cf1
JH
270?C:${FUNC}_R_PROTO:
271?C: This symbol encodes the prototype of ${func}_r.
39183afa
JH
272?C: It is zero if d_${func}_r is undef, and one of the
273?C: REENTRANT_PROTO_T_ABC macros of reentr.h if d_${func}_r
274?C: is defined.
10bc17b6 275?C:.
aa418cf1
JH
276?H:#\$d_${func}_r HAS_${FUNC}_R /**/
277?H:#define ${FUNC}_R_PROTO \$${func}_r_proto /**/
10bc17b6 278?H:.
aa418cf1
JH
279?T:try hdrs d_${func}_r_proto
280?LINT:set d_${func}_r
281?LINT:set ${func}_r_proto
282: see if ${func}_r exists
283set ${func}_r d_${func}_r
10bc17b6 284eval \$inlibc
aa418cf1 285case "\$d_${func}_r" in
10bc17b6 286"\$define")
d63eadf0 287EOF
2d6469fe 288 print U <<"EOF";
d63eadf0 289 hdrs="$hdrs"
aa418cf1
JH
290 case "\$d_${func}_r_proto:\$usethreads" in
291 ":define") d_${func}_r_proto=define
292 set d_${func}_r_proto ${func}_r \$hdrs
a48ec845
JH
293 eval \$hasproto ;;
294 *) ;;
295 esac
aa418cf1 296 case "\$d_${func}_r_proto" in
a48ec845 297 define)
10bc17b6 298EOF
d63eadf0
JH
299 }
300 for my $p (@p) {
301 my ($r, $a) = ($p =~ /^(.)_(.+)/);
302 my $v = join(", ", map { $m{$_} } split '', $a);
303 if ($opts{U}) {
2d6469fe 304 print U <<"EOF";
aa418cf1
JH
305 case "\$${func}_r_proto" in
306 ''|0) try='$m{$r} ${func}_r($v);'
307 ./protochk "extern \$try" \$hdrs && ${func}_r_proto=$p ;;
10bc17b6
JH
308 esac
309EOF
d63eadf0 310 }
aa418cf1
JH
311 $seenh{$func}->{$p}++;
312 push @{$seena{$func}}, $p;
d63eadf0 313 $seenp{$p}++;
aa418cf1
JH
314 $seent{$func} = $type;
315 $seens{$func} = $m{S};
316 $seend{$func} = $m{D};
a845a0d4 317 $seenm{$func} = \%m;
d63eadf0
JH
318 }
319 if ($opts{U}) {
2d6469fe 320 print U <<"EOF";
aa418cf1
JH
321 case "\$${func}_r_proto" in
322 ''|0) d_${func}_r=undef
7c1815b7 323 ${func}_r_proto=0
aa418cf1
JH
324 echo "Disabling ${func}_r, cannot determine prototype." >&4 ;;
325 * ) case "\$${func}_r_proto" in
10bc17b6 326 REENTRANT_PROTO*) ;;
aa418cf1 327 *) ${func}_r_proto="REENTRANT_PROTO_\$${func}_r_proto" ;;
10bc17b6
JH
328 esac
329 echo "Prototype: \$try" ;;
330 esac
331 ;;
c18e646a 332 *) case "\$usethreads" in
aa418cf1 333 define) echo "${func}_r has no prototype, not using it." >&4 ;;
c18e646a 334 esac
aa418cf1
JH
335 d_${func}_r=undef
336 ${func}_r_proto=0
c18e646a 337 ;;
a48ec845
JH
338 esac
339 ;;
aa418cf1 340*) ${func}_r_proto=0
10bc17b6
JH
341 ;;
342esac
343
344EOF
7c1815b7 345 close(U);
10bc17b6
JH
346 }
347}
348
349close DATA;
350
10bc17b6 351{
aa418cf1 352 # Write out all the known prototype signatures.
10bc17b6
JH
353 my $i = 1;
354 for my $p (sort keys %seenp) {
7c1815b7 355 print $h "# define REENTRANT_PROTO_${p} ${i}\n";
10bc17b6
JH
356 $i++;
357 }
358}
359
aa418cf1
JH
360my @struct; # REENTR struct members
361my @size; # struct member buffer size initialization code
362my @init; # struct member buffer initialization (malloc) code
363my @free; # struct member buffer release (free) code
364my @wrap; # the wrapper (foo(a) -> foo_r(a,...)) cpp code
365my @define; # defines for optional features
366
10bc17b6 367sub ifprotomatch {
aa418cf1
JH
368 my $FUNC = shift;
369 join " || ", map { "${FUNC}_R_PROTO == REENTRANT_PROTO_$_" } @_;
10bc17b6
JH
370}
371
10bc17b6
JH
372sub pushssif {
373 push @struct, @_;
374 push @size, @_;
375 push @init, @_;
376 push @free, @_;
377}
378
379sub pushinitfree {
aa418cf1 380 my $func = shift;
10bc17b6 381 push @init, <<EOF;
a02a5408 382 Newx(PL_reentrant_buffer->_${func}_buffer, PL_reentrant_buffer->_${func}_size, char);
10bc17b6
JH
383EOF
384 push @free, <<EOF;
aa418cf1 385 Safefree(PL_reentrant_buffer->_${func}_buffer);
10bc17b6
JH
386EOF
387}
388
389sub define {
390 my ($n, $p, @F) = @_;
391 my @H;
392 my $H = uc $F[0];
393 push @define, <<EOF;
394/* The @F using \L$n? */
395
396EOF
aa418cf1
JH
397 my $GENFUNC;
398 for my $func (@F) {
399 my $FUNC = uc $func;
400 my $HAS = "${FUNC}_R_HAS_$n";
401 push @H, $HAS;
402 my @h = grep { /$p/ } @{$seena{$func}};
403 unless (defined $GENFUNC) {
404 $GENFUNC = $FUNC;
405 $GENFUNC =~ s/^GET//;
f7937171 406 }
10bc17b6 407 if (@h) {
7c1815b7 408 push @define, "# if defined(HAS_${FUNC}_R) && (" . join(" || ", map { "${FUNC}_R_PROTO == REENTRANT_PROTO_$_" } @h) . ")\n";
10bc17b6
JH
409
410 push @define, <<EOF;
7c1815b7
KW
411# define $HAS
412# else
413# undef $HAS
414# endif
10bc17b6
JH
415EOF
416 }
417 }
0891a229 418 return if @F == 1;
10bc17b6
JH
419 push @define, <<EOF;
420
421/* Any of the @F using \L$n? */
422
423EOF
7c1815b7 424 push @define, "# if (" . join(" || ", map { "defined($_)" } @H) . ")\n";
10bc17b6 425 push @define, <<EOF;
7c1815b7
KW
426# define USE_${GENFUNC}_$n
427# else
428# undef USE_${GENFUNC}_$n
429# endif
10bc17b6
JH
430
431EOF
432}
433
edd309b7
JH
434define('BUFFER', 'B',
435 qw(getgrent getgrgid getgrnam));
436
10bc17b6
JH
437define('PTR', 'R',
438 qw(getgrent getgrgid getgrnam));
439define('PTR', 'R',
440 qw(getpwent getpwnam getpwuid));
441define('PTR', 'R',
442 qw(getspent getspnam));
443
444define('FPTR', 'H',
f7937171 445 qw(getgrent getgrgid getgrnam setgrent endgrent));
10bc17b6 446define('FPTR', 'H',
f7937171 447 qw(getpwent getpwnam getpwuid setpwent endpwent));
10bc17b6 448
edd309b7
JH
449define('BUFFER', 'B',
450 qw(getpwent getpwgid getpwnam));
451
5baa389e
KW
452define('BUFFER', 'B',
453 qw(getspent getspnam));
454
10bc17b6
JH
455define('PTR', 'R',
456 qw(gethostent gethostbyaddr gethostbyname));
457define('PTR', 'R',
458 qw(getnetent getnetbyaddr getnetbyname));
459define('PTR', 'R',
460 qw(getprotoent getprotobyname getprotobynumber));
461define('PTR', 'R',
462 qw(getservent getservbyname getservbyport));
463
edd309b7
JH
464define('BUFFER', 'B',
465 qw(gethostent gethostbyaddr gethostbyname));
466define('BUFFER', 'B',
467 qw(getnetent getnetbyaddr getnetbyname));
468define('BUFFER', 'B',
469 qw(getprotoent getprotobyname getprotobynumber));
470define('BUFFER', 'B',
471 qw(getservent getservbyname getservbyport));
472
10bc17b6
JH
473define('ERRNO', 'E',
474 qw(gethostent gethostbyaddr gethostbyname));
475define('ERRNO', 'E',
476 qw(getnetent getnetbyaddr getnetbyname));
477
aa418cf1
JH
478# The following loop accumulates the "ssif" (struct, size, init, free)
479# sections that declare the struct members (in reentr.h), and the buffer
480# size initialization, buffer initialization (malloc), and buffer
481# release (free) code (in reentr.c).
482#
483# The loop also contains a lot of intrinsic logic about groups of
484# functions (since functions of certain kind operate the same way).
485
486for my $func (@seenf) {
487 my $FUNC = uc $func;
7c1815b7
KW
488 my $ifdef = "# ifdef HAS_${FUNC}_R\n";
489 my $endif = "# endif /* HAS_${FUNC}_R */\n\n";
aa418cf1
JH
490 if (exists $seena{$func}) {
491 my @p = @{$seena{$func}};
492 if ($func =~ /^(asctime|ctime|getlogin|setlocale|strerror|ttyname)$/) {
10bc17b6
JH
493 pushssif $ifdef;
494 push @struct, <<EOF;
aa418cf1
JH
495 char* _${func}_buffer;
496 size_t _${func}_size;
10bc17b6 497EOF
81169c06
KW
498 my $size = ($func =~ /^(asctime|ctime)$/)
499 ? 26
500 : "REENTRANTSMALLSIZE";
10bc17b6 501 push @size, <<EOF;
81169c06 502 PL_reentrant_buffer->_${func}_size = $size;
10bc17b6 503EOF
aa418cf1 504 pushinitfree $func;
10bc17b6
JH
505 pushssif $endif;
506 }
e63f5cd5
KW
507 elsif ($func =~ /^(gm|local)time$/) {
508 pushssif $ifdef;
509 push @struct, <<EOF; # Fixed size
510 $seent{$func} _${func}_struct;
511EOF
512 pushssif $endif;
513 }
aa418cf1 514 elsif ($func =~ /^(crypt)$/) {
10bc17b6
JH
515 pushssif $ifdef;
516 push @struct, <<EOF;
7c1815b7 517# if CRYPT_R_PROTO == REENTRANT_PROTO_B_CCD
aa418cf1 518 $seend{$func} _${func}_data;
7c1815b7 519# else
05404ffe 520 $seent{$func} *_${func}_struct_buffer;
7c1815b7 521# endif
10bc17b6 522EOF
7c1815b7
KW
523 push @init, <<EOF;
524# if CRYPT_R_PROTO != REENTRANT_PROTO_B_CCD
05404ffe 525 PL_reentrant_buffer->_${func}_struct_buffer = 0;
7c1815b7 526# endif
05404ffe 527EOF
7c1815b7
KW
528 push @free, <<EOF;
529# if CRYPT_R_PROTO != REENTRANT_PROTO_B_CCD
05404ffe 530 Safefree(PL_reentrant_buffer->_${func}_struct_buffer);
7c1815b7 531# endif
10bc17b6 532EOF
b430fd04
JH
533 pushssif $endif;
534 }
aa418cf1 535 elsif ($func =~ /^(getgrnam|getpwnam|getspnam)$/) {
10bc17b6 536 pushssif $ifdef;
aa418cf1
JH
537 # 'genfunc' can be read either as 'generic' or 'genre',
538 # it represents a group of functions.
539 my $genfunc = $func;
540 $genfunc =~ s/nam/ent/g;
541 $genfunc =~ s/^get//;
542 my $GENFUNC = uc $genfunc;
10bc17b6 543 push @struct, <<EOF;
aa418cf1
JH
544 $seent{$func} _${genfunc}_struct;
545 char* _${genfunc}_buffer;
546 size_t _${genfunc}_size;
10bc17b6
JH
547EOF
548 push @struct, <<EOF;
aa418cf1
JH
549# ifdef USE_${GENFUNC}_PTR
550 $seent{$func}* _${genfunc}_ptr;
10bc17b6
JH
551# endif
552EOF
0de8cad8 553 push @struct, <<EOF;
aa418cf1
JH
554# ifdef USE_${GENFUNC}_FPTR
555 FILE* _${genfunc}_fptr;
10bc17b6
JH
556# endif
557EOF
0de8cad8 558 push @init, <<EOF;
aa418cf1
JH
559# ifdef USE_${GENFUNC}_FPTR
560 PL_reentrant_buffer->_${genfunc}_fptr = NULL;
10bc17b6
JH
561# endif
562EOF
0de8cad8 563 my $sc = $genfunc eq 'grent' ?
10bc17b6 564 '_SC_GETGR_R_SIZE_MAX' : '_SC_GETPW_R_SIZE_MAX';
0de8cad8
RGS
565 my $sz = "_${genfunc}_size";
566 push @size, <<EOF;
7c1815b7 567# if defined(HAS_SYSCONF) && defined($sc) && !defined(__GLIBC__)
0de8cad8 568 PL_reentrant_buffer->$sz = sysconf($sc);
832a833b 569 if (PL_reentrant_buffer->$sz == (size_t) -1)
e3410746 570 PL_reentrant_buffer->$sz = REENTRANTUSUALSIZE;
7c1815b7 571# elif defined(__osf__) && defined(__alpha) && defined(SIABUFSIZ)
0de8cad8 572 PL_reentrant_buffer->$sz = SIABUFSIZ;
7c1815b7 573# elif defined(__sgi)
0de8cad8 574 PL_reentrant_buffer->$sz = BUFSIZ;
7c1815b7 575# else
0de8cad8 576 PL_reentrant_buffer->$sz = REENTRANTUSUALSIZE;
7c1815b7 577# endif
10bc17b6 578EOF
aa418cf1 579 pushinitfree $genfunc;
10bc17b6
JH
580 pushssif $endif;
581 }
aa418cf1 582 elsif ($func =~ /^(gethostbyname|getnetbyname|getservbyname|getprotobyname)$/) {
10bc17b6 583 pushssif $ifdef;
aa418cf1
JH
584 my $genfunc = $func;
585 $genfunc =~ s/byname/ent/;
586 $genfunc =~ s/^get//;
587 my $GENFUNC = uc $genfunc;
588 my $D = ifprotomatch($FUNC, grep {/D/} @p);
589 my $d = $seend{$func};
b6a6e956 590 $d =~ s/\*$//; # snip: we need the base type.
10bc17b6 591 push @struct, <<EOF;
aa418cf1 592 $seent{$func} _${genfunc}_struct;
10bc17b6 593# if $D
aa418cf1 594 $d _${genfunc}_data;
10bc17b6 595# else
aa418cf1
JH
596 char* _${genfunc}_buffer;
597 size_t _${genfunc}_size;
10bc17b6 598# endif
aa418cf1
JH
599# ifdef USE_${GENFUNC}_PTR
600 $seent{$func}* _${genfunc}_ptr;
10bc17b6
JH
601# endif
602EOF
7c1815b7 603 push @struct, <<EOF;
aa418cf1
JH
604# ifdef USE_${GENFUNC}_ERRNO
605 int _${genfunc}_errno;
7c1815b7 606# endif
10bc17b6
JH
607EOF
608 push @size, <<EOF;
7c1815b7 609# if !($D)
aa418cf1 610 PL_reentrant_buffer->_${genfunc}_size = REENTRANTUSUALSIZE;
7c1815b7 611# endif
10bc17b6
JH
612EOF
613 push @init, <<EOF;
7c1815b7 614# if !($D)
a02a5408 615 Newx(PL_reentrant_buffer->_${genfunc}_buffer, PL_reentrant_buffer->_${genfunc}_size, char);
7c1815b7 616# endif
10bc17b6
JH
617EOF
618 push @free, <<EOF;
7c1815b7 619# if !($D)
aa418cf1 620 Safefree(PL_reentrant_buffer->_${genfunc}_buffer);
7c1815b7 621# endif
10bc17b6
JH
622EOF
623 pushssif $endif;
624 }
aa418cf1 625 elsif ($func =~ /^(readdir|readdir64)$/) {
10bc17b6 626 pushssif $ifdef;
aa418cf1 627 my $R = ifprotomatch($FUNC, grep {/R/} @p);
10bc17b6 628 push @struct, <<EOF;
aa418cf1
JH
629 $seent{$func}* _${func}_struct;
630 size_t _${func}_size;
10bc17b6 631# if $R
aa418cf1 632 $seent{$func}* _${func}_ptr;
10bc17b6
JH
633# endif
634EOF
635 push @size, <<EOF;
636 /* This is the size Solaris recommends.
637 * (though we go static, should use pathconf() instead) */
aa418cf1 638 PL_reentrant_buffer->_${func}_size = sizeof($seent{$func}) + MAXPATHLEN + 1;
10bc17b6 639EOF
7c1815b7 640 push @init, <<EOF;
aa418cf1 641 PL_reentrant_buffer->_${func}_struct = ($seent{$func}*)safemalloc(PL_reentrant_buffer->_${func}_size);
10bc17b6
JH
642EOF
643 push @free, <<EOF;
aa418cf1 644 Safefree(PL_reentrant_buffer->_${func}_struct);
10bc17b6
JH
645EOF
646 pushssif $endif;
647 }
648
649 push @wrap, $ifdef;
650
10bc17b6 651 push @wrap, <<EOF;
02af4629
KW
652# if defined(PERL_REENTR_API) && (PERL_REENTR_API+0 == 1)
653# undef $func
10bc17b6 654EOF
aa418cf1
JH
655
656 # Write out what we have learned.
657
10bc17b6 658 my @v = 'a'..'z';
aa418cf1 659 my $v = join(", ", @v[0..$seenu{$func}-1]);
10bc17b6
JH
660 for my $p (@p) {
661 my ($r, $a) = split '_', $p;
662 my $test = $r eq 'I' ? ' == 0' : '';
663 my $true = 1;
aa418cf1
JH
664 my $genfunc = $func;
665 if ($genfunc =~ /^(?:get|set|end)(pw|gr|host|net|proto|serv|sp)/) {
666 $genfunc = "${1}ent";
10bc17b6
JH
667 }
668 my $b = $a;
669 my $w = '';
aa418cf1 670 substr($b, 0, $seenu{$func}) = '';
a7f3e46a 671 if ($b =~ /R/) {
aa418cf1 672 $true = "PL_reentrant_buffer->_${genfunc}_ptr";
10bc17b6 673 } elsif ($b =~ /S/) {
aa418cf1
JH
674 if ($func =~ /^readdir/) {
675 $true = "PL_reentrant_buffer->_${genfunc}_struct";
10bc17b6 676 } else {
aa418cf1 677 $true = "&PL_reentrant_buffer->_${genfunc}_struct";
10bc17b6
JH
678 }
679 } elsif ($b =~ /B/) {
aa418cf1 680 $true = "PL_reentrant_buffer->_${genfunc}_buffer";
10bc17b6
JH
681 }
682 if (length $b) {
683 $w = join ", ",
76baed8e
KW
684 map { $_ eq 'R'
685 ? "&PL_reentrant_buffer->_${genfunc}_ptr"
686 : $_ eq 'E'
687 ? "&PL_reentrant_buffer->_${genfunc}_errno"
688 : $_ eq 'B'
689 ? "PL_reentrant_buffer->_${genfunc}_buffer"
690 : $_ =~ /^[WI]$/
691 ? "PL_reentrant_buffer->_${genfunc}_size"
692 : $_ eq 'H'
693 ? "&PL_reentrant_buffer->_${genfunc}_fptr"
694 : $_ eq 'D'
695 ? "&PL_reentrant_buffer->_${genfunc}_data"
696 : $_ eq 'S'
697 ? ($func =~ /^readdir\d*$/
698 ? "PL_reentrant_buffer->_${genfunc}_struct"
699 : $func =~ /^crypt$/
700 ? "PL_reentrant_buffer->_${genfunc}_struct_buffer"
701 : "&PL_reentrant_buffer->_${genfunc}_struct")
702 : $_
703 } split '', $b;
10bc17b6
JH
704 $w = ", $w" if length $v;
705 }
832a833b 706
e63f5cd5
KW
707 # This needs a special case, see its definition in config.h
708 my $setup = ($func eq 'localtime') ? "L_R_TZSET " : "";
709
710 my $call = "$setup${func}_r($v$w)";
23e2b7a9
SP
711
712 # Must make OpenBSD happy
713 my $memzero = '';
714 if($p =~ /D$/ &&
715 ($genfunc eq 'protoent' || $genfunc eq 'servent')) {
3fb2f3ac 716 $memzero = 'REENTR_MEMZERO(&PL_reentrant_buffer->_' . $genfunc . '_data, sizeof(PL_reentrant_buffer->_' . $genfunc . '_data)),';
23e2b7a9 717 }
10bc17b6 718 push @wrap, <<EOF;
02af4629 719# if !defined($func) && ${FUNC}_R_PROTO == REENTRANT_PROTO_$p
10bc17b6
JH
720EOF
721 if ($r eq 'V' || $r eq 'B') {
722 push @wrap, <<EOF;
02af4629 723# define $func($v) $call
10bc17b6
JH
724EOF
725 } else {
aa418cf1 726 if ($func =~ /^get/) {
edd309b7 727 my $rv = $v ? ", $v" : "";
0891a229
JH
728 if ($r eq 'I') {
729 push @wrap, <<EOF;
02af4629 730# define $func($v) ($memzero(PL_reentrant_retint = $call)$test ? $true : ((PL_reentrant_retint == ERANGE) ? ($seent{$func} *) Perl_reentrant_retry("$func"$rv) : 0))
0891a229
JH
731EOF
732 } else {
733 push @wrap, <<EOF;
02af4629 734# define $func($v) ($call$test ? $true : ((errno == ERANGE) ? ($seent{$func} *) Perl_reentrant_retry("$func"$rv) : 0))
10bc17b6 735EOF
0891a229 736 }
edd309b7
JH
737 } else {
738 push @wrap, <<EOF;
02af4629 739# define $func($v) ($call$test ? $true : 0)
edd309b7
JH
740EOF
741 }
10bc17b6 742 }
02af4629
KW
743 push @wrap, <<EOF; # !defined(xxx) && XXX_R_PROTO == REENTRANT_PROTO_Y_TS
744# endif
10bc17b6
JH
745EOF
746 }
7dc0f1bb
KW
747 push @wrap, <<EOF;
748# if defined($func)
749# define PERL_REENTR_USING_${FUNC}_R
750# endif
751EOF
10bc17b6 752
02af4629
KW
753 push @wrap, <<EOF; # defined(PERL_REENTR_API) && (PERL_REENTR_API+0 == 1)
754# endif
832a833b
JH
755EOF
756
10bc17b6
JH
757 push @wrap, $endif, "\n";
758 }
759}
760
761local $" = '';
762
2d6469fe 763print $h <<EOF;
10bc17b6
JH
764
765/* Defines for indicating which special features are supported. */
766
767@define
768typedef struct {
7c1815b7 769
10bc17b6 770@struct
aa418cf1 771 int dummy; /* cannot have empty structs */
10bc17b6
JH
772} REENTR;
773
774/* The wrappers. */
775
776@wrap
5baa389e
KW
777
778/* Special case this; if others came along, could automate it */
779# ifdef HAS_GETSPNAM_R
780# define KEY_getspnam -1
781# endif
782
10bc17b6 783#endif /* USE_REENTRANT_API */
7c1815b7 784
10bc17b6 785#endif
10bc17b6
JH
786EOF
787
ce716c52 788read_only_bottom_close_and_rename($h);
10bc17b6 789
aa418cf1
JH
790# Prepare to write the reentr.c.
791
d91994bb 792my $c = open_print_header('reentr.c', <<'EOQ');
23ce015e
JH
793 */
794
795/*
10bc17b6 796 * "Saruman," I said, standing away from him, "only one hand at a time can
56fd1190 797 * wield the One, and you know that well, so do not trouble to say we!"
10bc17b6 798 *
23ce015e
JH
799 * [p.260 of _The Lord of the Rings_, II/ii: "The Council of Elrond"]
800 */
801
802/*
61296642
DM
803 * This file contains a collection of automatically created wrappers
804 * (created by running reentr.pl) for reentrant (thread-safe) versions of
805 * various library calls, such as getpwent_r. The wrapping is done so
806 * that other files like pp_sys.c calling those library functions need not
807 * care about the differences between various platforms' idiosyncrasies
7c1815b7 808 * regarding these reentrant interfaces.
10bc17b6 809 */
56fd1190 810EOQ
10bc17b6 811
56fd1190 812print $c <<"EOF";
10bc17b6
JH
813#include "EXTERN.h"
814#define PERL_IN_REENTR_C
815#include "perl.h"
816#include "reentr.h"
5f478816 817#include "keywords.h"
10bc17b6 818
acfc2cc3
HS
819#define RenewDouble(data_pointer, size_pointer, type) \\
820 STMT_START { \\
981fbfc1 821 const size_t size = MAX(*(size_pointer), 1) * 2; \\
acfc2cc3
HS
822 Renew((data_pointer), (size), type); \\
823 *(size_pointer) = size; \\
824 } STMT_END
825
10bc17b6
JH
826void
827Perl_reentrant_size(pTHX) {
23491f1d 828 PERL_UNUSED_CONTEXT;
0917d9b3
KW
829
830 /* Set the sizes of the reentrant buffers */
831
10bc17b6 832#ifdef USE_REENTRANT_API
7c1815b7
KW
833# define REENTRANTSMALLSIZE 256 /* Make something up. */
834# define REENTRANTUSUALSIZE 4096 /* Make something up. */
835
10bc17b6
JH
836@size
837#endif /* USE_REENTRANT_API */
7c1815b7 838
10bc17b6
JH
839}
840
841void
842Perl_reentrant_init(pTHX) {
23491f1d 843 PERL_UNUSED_CONTEXT;
0917d9b3
KW
844
845 /* Initialize the whole thing */
846
10bc17b6 847#ifdef USE_REENTRANT_API
7c1815b7 848
a02a5408 849 Newx(PL_reentrant_buffer, 1, REENTR);
10bc17b6 850 Perl_reentrant_size(aTHX);
7c1815b7 851
10bc17b6
JH
852@init
853#endif /* USE_REENTRANT_API */
7c1815b7 854
10bc17b6
JH
855}
856
857void
858Perl_reentrant_free(pTHX) {
23491f1d 859 PERL_UNUSED_CONTEXT;
0917d9b3
KW
860
861 /* Tear down */
862
10bc17b6 863#ifdef USE_REENTRANT_API
7c1815b7 864
10bc17b6
JH
865@free
866 Safefree(PL_reentrant_buffer);
7c1815b7 867
10bc17b6
JH
868#endif /* USE_REENTRANT_API */
869}
870
edd309b7
JH
871void*
872Perl_reentrant_retry(const char *f, ...)
873{
0917d9b3
KW
874 /* This function is set up to be called if the normal function returns
875 * failure with errno ERANGE, which indicates the buffer is too small.
876 * This function calls the failing one again with a larger buffer.
877 *
878 * What has happened is that, due to the magic of C preprocessor macro
879 * expansion, when the original code called function 'foo(args)', it was
880 * instead compiled into something like a call of 'foo_r(args, buffer)'
881 * Below we retry with 'foo', but the preprocessor has changed that into
882 * 'foo_r', so this function will end up calling itself recursively, each
883 * time with a larger buffer. If PERL_REENTRANT_MAXSIZE is defined, it
884 * won't increase beyond that, instead failing. */
885
edd309b7 886 void *retptr = NULL;
fe5bfecd 887 va_list ap;
7c1815b7 888
5f478816
KW
889 I32 key = 0;
890
7918f24d 891#ifdef USE_REENTRANT_API
7c1815b7 892
dbf7dff6 893 dTHX;
7c1815b7 894
5f478816
KW
895 key = Perl_keyword (aTHX_ f, strlen(f), FALSE /* not feature enabled */);
896
7918f24d
NC
897 /* Easier to special case this here than in embed.pl. (Look at what it
898 generates for proto.h) */
899 PERL_ARGS_ASSERT_REENTRANT_RETRY;
7c1815b7 900
7918f24d 901#endif
7c1815b7 902
5f478816 903 if (key == 0) {
5baa389e
KW
904
905#ifdef HAS_GETSPNAM_R
906
907 /* This is a #define as has no corresponding keyword */
908 if (strEQ(f, "getspnam")) {
909 key = KEY_getspnam;
910 }
911
912#endif
913
5f478816
KW
914 }
915 else if (key < 0) {
916 key = -key;
917 }
918
fe5bfecd 919 va_start(ap, f);
7c1815b7 920
edd309b7 921#ifdef USE_REENTRANT_API
edd309b7 922
5f478816 923 switch (key) {
7c1815b7
KW
924
925# ifdef USE_HOSTENT_BUFFER
926
5f478816
KW
927 case KEY_gethostbyaddr:
928 case KEY_gethostbyname:
929 case KEY_endhostent:
edd309b7 930 {
72761345
KW
931 char * host_addr;
932 Size_t asize;
933 char * host_name;
934 int anint;
7c1815b7
KW
935
936# ifdef PERL_REENTRANT_MAXSIZE
af685957
JH
937 if (PL_reentrant_buffer->_hostent_size <=
938 PERL_REENTRANT_MAXSIZE / 2)
7c1815b7 939# endif
72761345
KW
940 RenewDouble(PL_reentrant_buffer->_hostent_buffer,
941 &PL_reentrant_buffer->_hostent_size, char);
5f478816 942 switch (key) {
72761345
KW
943 case KEY_gethostbyaddr:
944 host_addr = va_arg(ap, char *);
945 asize = va_arg(ap, Size_t);
edd309b7 946 anint = va_arg(ap, int);
72761345
KW
947 /* socklen_t is what Posix 2001 says this should be */
948 retptr = gethostbyaddr(host_addr, (socklen_t) asize, anint); break;
5f478816 949 case KEY_gethostbyname:
72761345
KW
950 host_name = va_arg(ap, char *);
951 retptr = gethostbyname(host_name); break;
5f478816 952 case KEY_endhostent:
edd309b7
JH
953 retptr = gethostent(); break;
954 default:
0de8cad8 955 SETERRNO(ERANGE, LIB_INVARG);
edd309b7 956 break;
edd309b7
JH
957 }
958 }
959 break;
7c1815b7
KW
960
961# endif
962# ifdef USE_GRENT_BUFFER
963
5f478816
KW
964 case KEY_getgrent:
965 case KEY_getgrgid:
966 case KEY_getgrnam:
edd309b7 967 {
72761345
KW
968 char * name;
969 Gid_t gid;
7c1815b7
KW
970
971# ifdef PERL_REENTRANT_MAXSIZE
af685957
JH
972 if (PL_reentrant_buffer->_grent_size <=
973 PERL_REENTRANT_MAXSIZE / 2)
7c1815b7 974# endif
7c1815b7
KW
975 RenewDouble(PL_reentrant_buffer->_grent_buffer,
976 &PL_reentrant_buffer->_grent_size, char);
5f478816 977 switch (key) {
72761345
KW
978 case KEY_getgrnam:
979 name = va_arg(ap, char *);
980 retptr = getgrnam(name); break;
5f478816 981 case KEY_getgrgid:
7c1815b7
KW
982# if Gid_t_size < INTSIZE
983 gid = (Gid_t)va_arg(ap, int);
984# else
edd309b7 985 gid = va_arg(ap, Gid_t);
7c1815b7 986# endif
edd309b7 987 retptr = getgrgid(gid); break;
5f478816 988 case KEY_getgrent:
edd309b7
JH
989 retptr = getgrent(); break;
990 default:
0de8cad8 991 SETERRNO(ERANGE, LIB_INVARG);
edd309b7 992 break;
edd309b7
JH
993 }
994 }
995 break;
7c1815b7
KW
996
997# endif
998# ifdef USE_NETENT_BUFFER
999
5f478816
KW
1000 case KEY_getnetbyaddr:
1001 case KEY_getnetbyname:
1002 case KEY_getnetent:
edd309b7 1003 {
72761345
KW
1004 char * name;
1005 Netdb_net_t net;
1006 int anint;
7c1815b7
KW
1007
1008# ifdef PERL_REENTRANT_MAXSIZE
af685957
JH
1009 if (PL_reentrant_buffer->_netent_size <=
1010 PERL_REENTRANT_MAXSIZE / 2)
7c1815b7 1011# endif
7c1815b7
KW
1012 RenewDouble(PL_reentrant_buffer->_netent_buffer,
1013 &PL_reentrant_buffer->_netent_size, char);
5f478816 1014 switch (key) {
72761345
KW
1015 case KEY_getnetbyaddr:
1016 net = va_arg(ap, Netdb_net_t);
1017 anint = va_arg(ap, int);
1018 retptr = getnetbyaddr(net, anint); break;
1019 case KEY_getnetbyname:
1020 name = va_arg(ap, char *);
1021 retptr = getnetbyname(name); break;
1022 case KEY_getnetent:
1023 retptr = getnetent(); break;
1024 default:
1025 SETERRNO(ERANGE, LIB_INVARG);
1026 break;
1027 }
edd309b7
JH
1028 }
1029 break;
7c1815b7
KW
1030
1031# endif
1032# ifdef USE_PWENT_BUFFER
1033
5baa389e
KW
1034 case KEY_getpwnam:
1035 case KEY_getpwuid:
1036 case KEY_getpwent:
edd309b7 1037 {
72761345
KW
1038 Uid_t uid;
1039 char * name;
7c1815b7
KW
1040
1041# ifdef PERL_REENTRANT_MAXSIZE
af685957
JH
1042 if (PL_reentrant_buffer->_pwent_size <=
1043 PERL_REENTRANT_MAXSIZE / 2)
7c1815b7
KW
1044
1045# endif
7c1815b7
KW
1046 RenewDouble(PL_reentrant_buffer->_pwent_buffer,
1047 &PL_reentrant_buffer->_pwent_size, char);
5f478816
KW
1048 switch (key) {
1049 case KEY_getpwnam:
72761345
KW
1050 name = va_arg(ap, char *);
1051 retptr = getpwnam(name); break;
5f478816 1052 case KEY_getpwuid:
7c1815b7
KW
1053
1054# if Uid_t_size < INTSIZE
ab2b559b 1055 uid = (Uid_t)va_arg(ap, int);
7c1815b7 1056# else
edd309b7 1057 uid = va_arg(ap, Uid_t);
7c1815b7 1058# endif
edd309b7 1059 retptr = getpwuid(uid); break;
7c1815b7
KW
1060
1061# if defined(HAS_GETPWENT) || defined(HAS_GETPWENT_R)
5f478816
KW
1062
1063 case KEY_getpwent:
edd309b7 1064 retptr = getpwent(); break;
7c1815b7 1065# endif
edd309b7 1066 default:
0de8cad8 1067 SETERRNO(ERANGE, LIB_INVARG);
edd309b7 1068 break;
7c1815b7 1069 }
edd309b7
JH
1070 }
1071 break;
7c1815b7
KW
1072
1073# endif
5baa389e
KW
1074# ifdef USE_SPENT_BUFFER
1075
1076 case KEY_getspnam:
1077 {
1078 char * name;
1079
1080# ifdef PERL_REENTRANT_MAXSIZE
1081 if (PL_reentrant_buffer->_spent_size <=
1082 PERL_REENTRANT_MAXSIZE / 2)
1083
1084# endif
1085 RenewDouble(PL_reentrant_buffer->_spent_buffer,
1086 &PL_reentrant_buffer->_spent_size, char);
1087 switch (key) {
1088 case KEY_getspnam:
1089 name = va_arg(ap, char *);
1090 retptr = getspnam(name); break;
1091 default:
1092 SETERRNO(ERANGE, LIB_INVARG);
1093 break;
1094 }
1095 }
1096 break;
1097
1098# endif
7c1815b7
KW
1099# ifdef USE_PROTOENT_BUFFER
1100
5f478816
KW
1101 case KEY_getprotobyname:
1102 case KEY_getprotobynumber:
1103 case KEY_getprotoent:
edd309b7 1104 {
72761345
KW
1105 char * name;
1106 int anint;
7c1815b7
KW
1107
1108# ifdef PERL_REENTRANT_MAXSIZE
af685957
JH
1109 if (PL_reentrant_buffer->_protoent_size <=
1110 PERL_REENTRANT_MAXSIZE / 2)
7c1815b7 1111# endif
7c1815b7
KW
1112 RenewDouble(PL_reentrant_buffer->_protoent_buffer,
1113 &PL_reentrant_buffer->_protoent_size, char);
5f478816
KW
1114 switch (key) {
1115 case KEY_getprotobyname:
72761345
KW
1116 name = va_arg(ap, char *);
1117 retptr = getprotobyname(name); break;
5f478816 1118 case KEY_getprotobynumber:
edd309b7
JH
1119 anint = va_arg(ap, int);
1120 retptr = getprotobynumber(anint); break;
5f478816 1121 case KEY_getprotoent:
edd309b7
JH
1122 retptr = getprotoent(); break;
1123 default:
0de8cad8 1124 SETERRNO(ERANGE, LIB_INVARG);
edd309b7 1125 break;
7c1815b7 1126 }
edd309b7
JH
1127 }
1128 break;
7c1815b7
KW
1129
1130# endif
1131# ifdef USE_SERVENT_BUFFER
1132
5f478816
KW
1133 case KEY_getservbyname:
1134 case KEY_getservbyport:
1135 case KEY_getservent:
edd309b7 1136 {
72761345
KW
1137 char * name;
1138 char * proto;
1139 int anint;
7c1815b7
KW
1140
1141# ifdef PERL_REENTRANT_MAXSIZE
af685957
JH
1142 if (PL_reentrant_buffer->_servent_size <=
1143 PERL_REENTRANT_MAXSIZE / 2)
7c1815b7 1144# endif
7c1815b7
KW
1145 RenewDouble(PL_reentrant_buffer->_servent_buffer,
1146 &PL_reentrant_buffer->_servent_size, char);
5f478816
KW
1147 switch (key) {
1148 case KEY_getservbyname:
72761345
KW
1149 name = va_arg(ap, char *);
1150 proto = va_arg(ap, char *);
1151 retptr = getservbyname(name, proto); break;
5f478816 1152 case KEY_getservbyport:
edd309b7 1153 anint = va_arg(ap, int);
72761345
KW
1154 name = va_arg(ap, char *);
1155 retptr = getservbyport(anint, name); break;
5f478816 1156 case KEY_getservent:
edd309b7
JH
1157 retptr = getservent(); break;
1158 default:
0de8cad8 1159 SETERRNO(ERANGE, LIB_INVARG);
edd309b7 1160 break;
edd309b7
JH
1161 }
1162 }
1163 break;
7c1815b7
KW
1164
1165# endif
1166
edd309b7
JH
1167 default:
1168 /* Not known how to retry, so just fail. */
1169 break;
1170 }
7c1815b7 1171
6148ee25 1172#else
7c1815b7 1173
6148ee25 1174 PERL_UNUSED_ARG(f);
7c1815b7 1175
edd309b7 1176#endif
7c1815b7 1177
fe5bfecd 1178 va_end(ap);
edd309b7
JH
1179 return retptr;
1180}
10bc17b6
JH
1181EOF
1182
ce716c52 1183read_only_bottom_close_and_rename($c);
b6b9a099 1184
3d7d42a3
KW
1185# As of March 2020, the config.h entries that have reentrant prototypes that
1186# aren't in this file are:
1187# drand48
1188# random
1189# srand48
1190# srandom
1191
0917d9b3
KW
1192# The meanings of the flags are derivable from %map above
1193# Fnc, arg flags| hdr | ? struct type | prototypes...
10bc17b6
JH
1194__DATA__
1195asctime S |time |const struct tm|B_SB|B_SBI|I_SB|I_SBI
b430fd04 1196crypt CC |crypt |struct crypt_data|B_CCS|B_CCD|D=CRYPTD*
10bc17b6
JH
1197ctermid B |stdio | |B_B
1198ctime S |time |const time_t |B_SB|B_SBI|I_SB|I_SBI
10bc17b6 1199endgrent |grp | |I_H|V_H
31ee0cb7
JH
1200endhostent |netdb | |I_D|V_D|D=struct hostent_data*
1201endnetent |netdb | |I_D|V_D|D=struct netent_data*
1202endprotoent |netdb | |I_D|V_D|D=struct protoent_data*
10bc17b6 1203endpwent |pwd | |I_H|V_H
31ee0cb7 1204endservent |netdb | |I_D|V_D|D=struct servent_data*
10bc17b6
JH
1205getgrent |grp |struct group |I_SBWR|I_SBIR|S_SBW|S_SBI|I_SBI|I_SBIH
1206getgrgid T |grp |struct group |I_TSBWR|I_TSBIR|I_TSBI|S_TSBI|T=gid_t
1207getgrnam C |grp |struct group |I_CSBWR|I_CSBIR|S_CBI|I_CSBI|S_CSBI
a845a0d4 1208gethostbyaddr 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
10bc17b6
JH
1209gethostbyname C |netdb |struct hostent |I_CSBWRE|S_CSBIE|I_CSD|D=struct hostent_data*
1210gethostent |netdb |struct hostent |I_SBWRE|I_SBIE|S_SBIE|S_SBI|I_SBI|I_SD|D=struct hostent_data*
f6f0b69b 1211getlogin |unistd |char |I_BW|I_BI|B_BW|B_BI
a845a0d4 1212getnetbyaddr 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
10bc17b6
JH
1213getnetbyname C |netdb |struct netent |I_CSBWRE|I_CSBI|S_CSBI|I_CSD|D=struct netent_data*
1214getnetent |netdb |struct netent |I_SBWRE|I_SBIE|S_SBIE|S_SBI|I_SBI|I_SD|D=struct netent_data*
1215getprotobyname C|netdb |struct protoent|I_CSBWR|S_CSBI|I_CSD|D=struct protoent_data*
1216getprotobynumber I |netdb |struct protoent|I_ISBWR|S_ISBI|I_ISD|D=struct protoent_data*
1217getprotoent |netdb |struct protoent|I_SBWR|I_SBI|S_SBI|I_SD|D=struct protoent_data*
1218getpwent |pwd |struct passwd |I_SBWR|I_SBIR|S_SBW|S_SBI|I_SBI|I_SBIH
1219getpwnam C |pwd |struct passwd |I_CSBWR|I_CSBIR|S_CSBI|I_CSBI
1220getpwuid T |pwd |struct passwd |I_TSBWR|I_TSBIR|I_TSBI|S_TSBI|T=uid_t
1221getservbyname CC|netdb |struct servent |I_CCSBWR|S_CCSBI|I_CCSD|D=struct servent_data*
1222getservbyport IC|netdb |struct servent |I_ICSBWR|S_ICSBI|I_ICSD|D=struct servent_data*
1223getservent |netdb |struct servent |I_SBWR|I_SBI|S_SBI|I_SD|D=struct servent_data*
1224getspnam C |shadow |struct spwd |I_CSBWR|S_CSBI
e63f5cd5
KW
1225gmtime T |time |struct tm |S_TS|T=time_t*
1226localtime T |time |struct tm |S_TS|T=time_t*
10bc17b6
JH
1227readdir T |dirent |struct dirent |I_TSR|I_TS|T=DIR*
1228readdir64 T |dirent |struct dirent64|I_TSR|I_TS|T=DIR*
1229setgrent |grp | |I_H|V_H
1230sethostent I |netdb | |I_ID|V_ID|D=struct hostent_data*
1231setlocale IC |locale | |I_ICBI
1232setnetent I |netdb | |I_ID|V_ID|D=struct netent_data*
1233setprotoent I |netdb | |I_ID|V_ID|D=struct protoent_data*
1234setpwent |pwd | |I_H|V_H
1235setservent I |netdb | |I_ID|V_ID|D=struct servent_data*
10bc17b6
JH
1236strerror I |string | |I_IBW|I_IBI|B_IBW
1237tmpnam B |stdio | |B_B
1238ttyname I |unistd | |I_IBW|I_IBI|B_IBI