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