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