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