This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
The I_CSD, I_S, and V_S had wrong recepting datatype.
[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
8use strict;
9use Getopt::Std;
10my %opts;
11getopts('U', \%opts);
12
13my %map = (
14 V => "void",
15 A => "char*", # as an input argument
16 B => "char*", # as an output argument
17 C => "const char*", # as a read-only input argument
18 I => "int",
19 L => "long",
20 W => "size_t",
21 H => "FILE**",
22 E => "int*",
23 );
24
25# (See the definitions after __DATA__.)
26# In func|inc|type|... a "S" means "type*", and a "R" means "type**".
27# (The "types" are often structs, such as "struct passwd".)
28#
29# After the prototypes one can have |X=...|Y=... to define more types.
30# A commonly used extra type is to define D to be equal to "type_data",
31# for example "struct_hostent_data to" go with "struct hostent".
32#
33# Example #1: I_XSBWR means int func_r(X, type, char*, size_t, type**)
34# Example #2: S_SBIE means type func_r(type, char*, int, int*)
35# Example #3: S_CBI means type func_r(const char*, char*, int)
36
37
38die "reentr.h: $!" unless open(H, ">reentr.h");
39select H;
40print <<EOF;
41/*
42 * reentr.h
43 *
44 * Copyright (c) 1997-2002, Larry Wall
45 *
46 * You may distribute under the terms of either the GNU General Public
47 * License or the Artistic License, as specified in the README file.
48 *
49 * !!!!!!! DO NOT EDIT THIS FILE !!!!!!!
50 * This file is built by reentrl.pl from data in reentr.pl.
51 */
52
53#ifndef REENTR_H
54#define REENTR_H
55
56#ifdef USE_REENTRANT_API
57
58/* Deprecations: some platforms have the said reentrant interfaces
59 * but they are declared obsolete and are not to be used. Often this
60 * means that the platform has threadsafed the interfaces (hopefully).
61 * All this is OS version dependent, so we are of course fooling ourselves.
62 * If you know of more deprecations on some platforms, please add your own. */
63
64#ifdef __hpux
65# undef HAS_CRYPT_R
66# undef HAS_DRAND48_R
efa45b01
JH
67# undef HAS_ENDGRENT_R
68# undef HAS_ENDPWENT_R
10bc17b6
JH
69# undef HAS_GETGRENT_R
70# undef HAS_GETPWENT_R
71# undef HAS_SETLOCALE_R
72# undef HAS_SRAND48_R
73# undef HAS_STRERROR_R
74# define NETDB_R_OBSOLETE
75#endif
76
77#if defined(__osf__) && defined(__alpha) /* Tru64 aka Digital UNIX */
78# undef HAS_CRYPT_R
79# undef HAS_STRERROR_R
80# define NETDB_R_OBSOLETE
81#endif
82
83#ifdef NETDB_R_OBSOLETE
84# undef HAS_ENDHOSTENT_R
85# undef HAS_ENDNETENT_R
86# undef HAS_ENDPROTOENT_R
87# undef HAS_ENDSERVENT_R
88# undef HAS_GETHOSTBYADDR_R
89# undef HAS_GETHOSTBYNAME_R
90# undef HAS_GETHOSTENT_R
91# undef HAS_GETNETBYADDR_R
92# undef HAS_GETNETBYNAME_R
93# undef HAS_GETNETENT_R
94# undef HAS_GETPROTOBYNAME_R
95# undef HAS_GETPROTOBYNUMBER_R
96# undef HAS_GETPROTOENT_R
97# undef HAS_GETSERVBYNAME_R
98# undef HAS_GETSERVBYPORT_R
99# undef HAS_GETSERVENT_R
100# undef HAS_SETHOSTENT_R
101# undef HAS_SETNETENT_R
102# undef HAS_SETPROTOENT_R
103# undef HAS_SETSERVENT_R
104#endif
105
106#ifdef I_PWD
107# include <pwd.h>
108#endif
109#ifdef I_GRP
110# include <grp.h>
111#endif
112#ifdef I_NETDB
113# include <netdb.h>
114#endif
115#ifdef I_STDLIB
116# include <stdlib.h> /* drand48_data */
117#endif
118#ifdef I_CRYPT
119# ifdef I_CRYPT
120# include <crypt.h>
121# endif
122#endif
123#ifdef HAS_GETSPNAM_R
124# ifdef I_SHADOW
125# include <shadow.h>
126# endif
127#endif
128
129EOF
130
131my %seenh;
132my %seena;
133my @seenf;
134my %seenp;
135my %seent;
136my %seens;
137my %seend;
138my %seenu;
139
140while (<DATA>) {
141 next if /^\s+$/;
142 chomp;
143 my ($f, $h, $t, @p) = split(/\s*\|\s*/, $_, -1);
144 my $u;
145 ($f, $u) = split(' ', $f);
146 $seenu{$f} = defined $u ? length $u : 0;
147 my $F = uc $f;
148 push @seenf, $f;
149 my %m = %map;
150 if ($t) {
151 $m{S} = "$t*";
152 $m{R} = "$t**";
153 }
154 if (@p) {
155 while ($p[-1] =~ /=/) {
156 my ($k, $v) = ($p[-1] =~ /^([A-Za-z])\s*=\s*(.*)/);
157 $m{$k} = $v;
158 pop @p;
159 }
160 }
161 if ($opts{U} && open(U, ">d_${f}_r.U")) {
162 select U;
163 }
31ee0cb7
JH
164 my $prereqs = '';
165 my $prereqh = '';
166 my $prereqsh = '';
167 if ($h ne 'stdio') { # There's no i_stdio.
168 $prereqs = "i_$h";
169 $prereqh = "$h.h";
170 $prereqsh = "\$$prereqs $prereqh";
171 }
10bc17b6
JH
172 print <<EOF if $opts{U};
173?RCS: \$Id: d_${f}_r.U,v $
174?RCS:
175?RCS: Copyright (c) 2002 Jarkko Hietaniemi
176?RCS:
177?RCS: You may distribute under the terms of either the GNU General Public
178?RCS: License or the Artistic License, as specified in the README file.
179?RCS:
180?RCS: Generated by the reentr.pl from the Perl 5.8 distribution.
181?RCS:
31ee0cb7 182?MAKE:d_${f}_r ${f}_r_proto: Inlibc Protochk Hasproto i_systypes i_systime $prereqs usethreads
10bc17b6
JH
183?MAKE: -pick add \$@ %<
184?S:d_${f}_r:
185?S: This variable conditionally defines the HAS_${F}_R symbol,
186?S: which indicates to the C program that the ${f}_r()
187?S: routine is available.
188?S:.
189?S:${f}_r_proto:
190?S: This variable encodes the prototype of ${f}_r.
191?S:.
192?C:HAS_${F}_R:
193?C: This symbol, if defined, indicates that the ${f}_r routine
194?C: is available to ${f} re-entrantly.
195?C:.
196?C:${F}_R_PROTO:
197?C: This symbol encodes the prototype of ${f}_r.
198?C:.
199?H:#\$d_${f}_r HAS_${F}_R /**/
200?H:#define ${F}_R_PROTO \$${f}_r_proto /**/
201?H:.
a48ec845 202?T:try hdrs d_${f}_r_proto
10bc17b6
JH
203?LINT:set d_${f}_r
204?LINT:set ${f}_r_proto
205: see if ${f}_r exists
206set ${f}_r d_${f}_r
207eval \$inlibc
208case "\$d_${f}_r" in
209"\$define")
31ee0cb7 210 hdrs="\$i_systypes sys/types.h define stdio.h $prereqsh"
90e831dc
SB
211 case "$h" in
212 time)
213 hdrs="\$hdrs \$i_systime sys/time.h"
214 ;;
215 esac
c18e646a
JH
216 case "\$d_${f}_r_proto:\$usethreads" in
217 ":define") d_${f}_r_proto=define
a48ec845
JH
218 set d_${f}_r_proto ${f}_r \$hdrs
219 eval \$hasproto ;;
220 *) ;;
221 esac
222 case "\$d_${f}_r_proto" in
223 define)
10bc17b6
JH
224EOF
225 for my $p (@p) {
226 my ($r, $a) = ($p =~ /^(.)_(.+)/);
227 my $v = join(", ", map { $m{$_} } split '', $a);
228 if ($opts{U}) {
229 print <<EOF ;
230 case "\$${f}_r_proto" in
231 ''|0) try='$m{$r} ${f}_r($v);'
232 ./protochk "extern \$try" \$hdrs && ${f}_r_proto=$p ;;
233 esac
234EOF
235 }
236 $seenh{$f}->{$p}++;
237 push @{$seena{$f}}, $p;
238 $seenp{$p}++;
239 $seent{$f} = $t;
240 $seens{$f} = $m{S};
241 $seend{$f} = $m{D};
242 }
243 if ($opts{U}) {
244 print <<EOF;
245 case "\$${f}_r_proto" in
90e831dc 246 ''|0) d_${f}_r=undef
10bc17b6 247 ${f}_r_proto=0
a48ec845 248 echo "Disabling ${f}_r, cannot determine prototype." >&4 ;;
10bc17b6
JH
249 * ) case "\$${f}_r_proto" in
250 REENTRANT_PROTO*) ;;
251 *) ${f}_r_proto="REENTRANT_PROTO_\$${f}_r_proto" ;;
252 esac
253 echo "Prototype: \$try" ;;
254 esac
255 ;;
c18e646a
JH
256 *) case "\$usethreads" in
257 define) echo "${f}_r has no prototype, not using it." >&4 ;;
258 esac
90e831dc
SB
259 d_${f}_r=undef
260 ${f}_r_proto=0
c18e646a 261 ;;
a48ec845
JH
262 esac
263 ;;
10bc17b6
JH
264*) ${f}_r_proto=0
265 ;;
266esac
267
268EOF
269 close(U);
270 }
271}
272
273close DATA;
274
275select H;
276
277{
278 my $i = 1;
279 for my $p (sort keys %seenp) {
280 print "#define REENTRANT_PROTO_${p} ${i}\n";
281 $i++;
282 }
283}
284
285sub ifprotomatch {
286 my $F = shift;
287 join " || ", map { "${F}_R_PROTO == REENTRANT_PROTO_$_" } @_;
288}
289
290my @struct;
291my @size;
292my @init;
293my @free;
294my @wrap;
295my @define;
296
297sub pushssif {
298 push @struct, @_;
299 push @size, @_;
300 push @init, @_;
301 push @free, @_;
302}
303
304sub pushinitfree {
305 my $f = shift;
306 push @init, <<EOF;
307 New(31338, PL_reentrant_buffer->_${f}_buffer, PL_reentrant_buffer->_${f}_size, char);
308EOF
309 push @free, <<EOF;
310 Safefree(PL_reentrant_buffer->_${f}_buffer);
311EOF
312}
313
314sub define {
315 my ($n, $p, @F) = @_;
316 my @H;
317 my $H = uc $F[0];
318 push @define, <<EOF;
319/* The @F using \L$n? */
320
321EOF
322 for my $f (@F) {
323 my $F = uc $f;
324 my $h = "${F}_R_HAS_$n";
325 push @H, $h;
326 my @h = grep { /$p/ } @{$seena{$f}};
327 if (@h) {
09310450 328 push @define, "#if defined(HAS_${F}_R) && (" . join(" || ", map { "${F}_R_PROTO == REENTRANT_PROTO_$_" } @h) . ")\n";
10bc17b6
JH
329
330 push @define, <<EOF;
331# define $h
332#else
333# undef $h
334#endif
335EOF
336 }
337 }
338 push @define, <<EOF;
339
340/* Any of the @F using \L$n? */
341
342EOF
343 push @define, "#if (" . join(" || ", map { "defined($_)" } @H) . ")\n";
344 push @define, <<EOF;
345# define USE_${H}_$n
346#else
347# undef USE_${H}_$n
348#endif
349
350EOF
351}
352
edd309b7
JH
353define('BUFFER', 'B',
354 qw(getgrent getgrgid getgrnam));
355
10bc17b6
JH
356define('PTR', 'R',
357 qw(getgrent getgrgid getgrnam));
358define('PTR', 'R',
359 qw(getpwent getpwnam getpwuid));
360define('PTR', 'R',
361 qw(getspent getspnam));
362
363define('FPTR', 'H',
364 qw(getgrent getgrgid getgrnam));
365define('FPTR', 'H',
366 qw(getpwent getpwnam getpwuid));
367
edd309b7
JH
368define('BUFFER', 'B',
369 qw(getpwent getpwgid getpwnam));
370
10bc17b6
JH
371define('PTR', 'R',
372 qw(gethostent gethostbyaddr gethostbyname));
373define('PTR', 'R',
374 qw(getnetent getnetbyaddr getnetbyname));
375define('PTR', 'R',
376 qw(getprotoent getprotobyname getprotobynumber));
377define('PTR', 'R',
378 qw(getservent getservbyname getservbyport));
379
edd309b7
JH
380define('BUFFER', 'B',
381 qw(gethostent gethostbyaddr gethostbyname));
382define('BUFFER', 'B',
383 qw(getnetent getnetbyaddr getnetbyname));
384define('BUFFER', 'B',
385 qw(getprotoent getprotobyname getprotobynumber));
386define('BUFFER', 'B',
387 qw(getservent getservbyname getservbyport));
388
10bc17b6
JH
389define('ERRNO', 'E',
390 qw(gethostent gethostbyaddr gethostbyname));
391define('ERRNO', 'E',
392 qw(getnetent getnetbyaddr getnetbyname));
393
394for my $f (@seenf) {
395 my $F = uc $f;
396 my $ifdef = "#ifdef HAS_${F}_R\n";
397 my $endif = "#endif /* HAS_${F}_R */\n";
398 if (exists $seena{$f}) {
399 my @p = @{$seena{$f}};
400 if ($f =~ /^(asctime|ctime|getlogin|setlocale|strerror|ttyname)$/) {
401 pushssif $ifdef;
402 push @struct, <<EOF;
403 char* _${f}_buffer;
404 size_t _${f}_size;
405EOF
406 push @size, <<EOF;
407 PL_reentrant_buffer->_${f}_size = 256; /* Make something up. */
408EOF
409 pushinitfree $f;
410 pushssif $endif;
411 }
b430fd04 412 elsif ($f =~ /^(crypt)$/) {
10bc17b6
JH
413 pushssif $ifdef;
414 push @struct, <<EOF;
b430fd04
JH
415#if CRYPT_R_PROTO == REENTRANT_PROTO_B_CCD
416 $seend{$f} _${f}_data;
417#else
10bc17b6 418 $seent{$f} _${f}_struct;
b430fd04 419#endif
10bc17b6 420EOF
b430fd04 421 push @init, <<EOF;
10bc17b6
JH
422#ifdef __GLIBC__
423 PL_reentrant_buffer->_${f}_struct.initialized = 0;
424#endif
425EOF
b430fd04
JH
426 pushssif $endif;
427 }
428 elsif ($f =~ /^(drand48|gmtime|localtime|random)$/) {
429 pushssif $ifdef;
430 push @struct, <<EOF;
431 $seent{$f} _${f}_struct;
432EOF
10bc17b6
JH
433 if ($1 eq 'drand48') {
434 push @struct, <<EOF;
435 double _${f}_double;
436EOF
437 }
438 pushssif $endif;
439 }
440 elsif ($f =~ /^(getgrnam|getpwnam|getspnam)$/) {
441 pushssif $ifdef;
442 my $g = $f;
443 $g =~ s/nam/ent/g;
444 my $G = uc $g;
445 push @struct, <<EOF;
446 $seent{$f} _${g}_struct;
447 char* _${g}_buffer;
448 size_t _${g}_size;
449EOF
450 push @struct, <<EOF;
451# ifdef USE_${G}_PTR
452 $seent{$f}* _${g}_ptr;
453# endif
454EOF
455 if ($g eq 'getspent') {
456 push @size, <<EOF;
457 PL_reentrant_buffer->_${g}_size = 1024;
458EOF
459 } else {
460 push @struct, <<EOF;
461# ifdef USE_${G}_FPTR
462 FILE* _${g}_fptr;
463# endif
464EOF
465 push @init, <<EOF;
466# ifdef USE_${G}_FPTR
467 PL_reentrant_buffer->_${g}_fptr = NULL;
468# endif
469EOF
470 my $sc = $g eq 'getgrent' ?
471 '_SC_GETGR_R_SIZE_MAX' : '_SC_GETPW_R_SIZE_MAX';
472 push @size, <<EOF;
473# if defined(HAS_SYSCONF) && defined($sc) && !defined(__GLIBC__)
474 PL_reentrant_buffer->_${g}_size = sysconf($sc);
475# else
476# if defined(__osf__) && defined(__alpha) && defined(SIABUFSIZ)
477 PL_reentrant_buffer->_${g}_size = SIABUFSIZ;
478# else
479# ifdef __sgi
480 PL_reentrant_buffer->_${g}_size = BUFSIZ;
481# else
edd309b7 482 PL_reentrant_buffer->_${g}_size = 256;
10bc17b6
JH
483# endif
484# endif
485# endif
486EOF
487 }
488 pushinitfree $g;
489 pushssif $endif;
490 }
491 elsif ($f =~ /^(gethostbyname|getnetbyname|getservbyname|getprotobyname)$/) {
492 pushssif $ifdef;
493 my $g = $f;
494 $g =~ s/byname/ent/;
495 my $G = uc $g;
496 my $D = ifprotomatch($F, grep {/D/} @p);
497 my $d = $seend{$f};
31ee0cb7 498 $d =~ s/\*$//; # snip: we need need the base type.
10bc17b6
JH
499 push @struct, <<EOF;
500 $seent{$f} _${g}_struct;
501# if $D
502 $d _${g}_data;
503# else
504 char* _${g}_buffer;
505 size_t _${g}_size;
506# endif
507# ifdef USE_${G}_PTR
508 $seent{$f}* _${g}_ptr;
509# endif
510EOF
511 push @struct, <<EOF;
512# ifdef USE_${G}_ERRNO
513 int _${g}_errno;
514# endif
515EOF
516 push @size, <<EOF;
517#if !($D)
518 PL_reentrant_buffer->_${g}_size = 2048; /* Any better ideas? */
519#endif
520EOF
521 push @init, <<EOF;
522#if !($D)
523 New(31338, PL_reentrant_buffer->_${g}_buffer, PL_reentrant_buffer->_${g}_size, char);
524#endif
525EOF
526 push @free, <<EOF;
527#if !($D)
528 Safefree(PL_reentrant_buffer->_${g}_buffer);
529#endif
530EOF
531 pushssif $endif;
532 }
533 elsif ($f =~ /^(readdir|readdir64)$/) {
534 pushssif $ifdef;
535 my $R = ifprotomatch($F, grep {/R/} @p);
536 push @struct, <<EOF;
537 $seent{$f}* _${f}_struct;
538 size_t _${f}_size;
539# if $R
540 $seent{$f}* _${f}_ptr;
541# endif
542EOF
543 push @size, <<EOF;
544 /* This is the size Solaris recommends.
545 * (though we go static, should use pathconf() instead) */
546 PL_reentrant_buffer->_${f}_size = sizeof($seent{$f}) + MAXPATHLEN + 1;
547EOF
548 push @init, <<EOF;
549 PL_reentrant_buffer->_${f}_struct = ($seent{$f}*)safemalloc(PL_reentrant_buffer->_${f}_size);
550EOF
551 push @free, <<EOF;
552 Safefree(PL_reentrant_buffer->_${f}_struct);
553EOF
554 pushssif $endif;
555 }
556
557 push @wrap, $ifdef;
558
10bc17b6
JH
559 push @wrap, <<EOF;
560# undef $f
561EOF
562 my @v = 'a'..'z';
563 my $v = join(", ", @v[0..$seenu{$f}-1]);
564 for my $p (@p) {
565 my ($r, $a) = split '_', $p;
566 my $test = $r eq 'I' ? ' == 0' : '';
567 my $true = 1;
10bc17b6
JH
568 my $g = $f;
569 if ($g =~ /^(?:get|set|end)(pw|gr|host|net|proto|serv|sp)/) {
570 $g = "get$1ent";
571 } elsif ($g eq 'srand48') {
572 $g = "drand48";
573 }
574 my $b = $a;
575 my $w = '';
576 substr($b, 0, $seenu{$f}) = '';
577 if ($b =~ /R/) {
578 $true = "PL_reentrant_buffer->_${g}_ptr";
579 } elsif ($b =~ /T/ && $f eq 'drand48') {
580 $true = "PL_reentrant_buffer->_${g}_double";
581 } elsif ($b =~ /S/) {
582 if ($f =~ /^readdir/) {
583 $true = "PL_reentrant_buffer->_${g}_struct";
584 } else {
585 $true = "&PL_reentrant_buffer->_${g}_struct";
586 }
587 } elsif ($b =~ /B/) {
588 $true = "PL_reentrant_buffer->_${g}_buffer";
589 }
590 if (length $b) {
591 $w = join ", ",
592 map {
593 $_ eq 'R' ?
594 "&PL_reentrant_buffer->_${g}_ptr" :
595 $_ eq 'E' ?
596 "&PL_reentrant_buffer->_${g}_errno" :
597 $_ eq 'B' ?
598 "PL_reentrant_buffer->_${g}_buffer" :
599 $_ =~ /^[WI]$/ ?
600 "PL_reentrant_buffer->_${g}_size" :
601 $_ eq 'H' ?
602 "&PL_reentrant_buffer->_${g}_fptr" :
603 $_ eq 'D' ?
604 "&PL_reentrant_buffer->_${g}_data" :
605 $_ eq 'S' ?
606 ($f =~ /^readdir/ ?
607 "PL_reentrant_buffer->_${g}_struct" :
608 "&PL_reentrant_buffer->_${g}_struct" ) :
609 $_ eq 'T' && $f eq 'drand48' ?
610 "&PL_reentrant_buffer->_${g}_double" :
611 $_
612 } split '', $b;
613 $w = ", $w" if length $v;
614 }
615 my $call = "${f}_r($v$w)";
616 $call = "((errno = $call))" if $r eq 'I';
617 push @wrap, <<EOF;
618# if !defined($f) && ${F}_R_PROTO == REENTRANT_PROTO_$p
619EOF
620 if ($r eq 'V' || $r eq 'B') {
621 push @wrap, <<EOF;
622# define $f($v) $call
623EOF
624 } else {
edd309b7
JH
625 if ($f =~ /^get/) {
626 my $rv = $v ? ", $v" : "";
627 push @wrap, <<EOF;
628# define $f($v) ($call$test ? $true : (errno == ERANGE ? Perl_reentrant_retry("$f"$rv) : 0))
10bc17b6 629EOF
edd309b7
JH
630 } else {
631 push @wrap, <<EOF;
632# define $f($v) ($call$test ? $true : 0)
633EOF
634 }
10bc17b6
JH
635 }
636 push @wrap, <<EOF;
637# endif
638EOF
639 }
640
641 push @wrap, $endif, "\n";
642 }
643}
644
645local $" = '';
646
647print <<EOF;
648
649/* Defines for indicating which special features are supported. */
650
651@define
652typedef struct {
653@struct
654} REENTR;
655
656/* The wrappers. */
657
658@wrap
659#endif /* USE_REENTRANT_API */
660
661#endif
662
663EOF
664
665close(H);
666
667die "reentr.c: $!" unless open(C, ">reentr.c");
668select C;
669print <<EOF;
670/*
671 * reentr.c
672 *
673 * Copyright (c) 1997-2002, Larry Wall
674 *
675 * You may distribute under the terms of either the GNU General Public
676 * License or the Artistic License, as specified in the README file.
677 *
678 * !!!!!!! DO NOT EDIT THIS FILE !!!!!!!
679 * This file is built by reentrl.pl from data in reentr.pl.
680 *
681 * "Saruman," I said, standing away from him, "only one hand at a time can
682 * wield the One, and you know that well, so do not trouble to say we!"
683 *
684 */
685
686#include "EXTERN.h"
687#define PERL_IN_REENTR_C
688#include "perl.h"
689#include "reentr.h"
690
691void
692Perl_reentrant_size(pTHX) {
693#ifdef USE_REENTRANT_API
694@size
695#endif /* USE_REENTRANT_API */
696}
697
698void
699Perl_reentrant_init(pTHX) {
700#ifdef USE_REENTRANT_API
701 New(31337, PL_reentrant_buffer, 1, REENTR);
702 Perl_reentrant_size(aTHX);
703@init
704#endif /* USE_REENTRANT_API */
705}
706
707void
708Perl_reentrant_free(pTHX) {
709#ifdef USE_REENTRANT_API
710@free
711 Safefree(PL_reentrant_buffer);
712#endif /* USE_REENTRANT_API */
713}
714
edd309b7
JH
715void*
716Perl_reentrant_retry(const char *f, ...)
717{
718 dTHX;
719 void *retptr = NULL;
720#ifdef USE_REENTRANT_API
721 void *p0, *p1;
722 size_t asize;
723 int anint;
724 va_list ap;
725
726 va_start(ap, f);
727
728#define REENTRANTHALFMAXSIZE 32768 /* The maximum may end up twice this. */
729
730 switch (PL_op->op_type) {
731#ifdef USE_GETHOSTENT_BUFFER
732 case OP_GHBYADDR:
733 case OP_GHBYNAME:
734 case OP_GHOSTENT:
735 {
736 if (PL_reentrant_buffer->_gethostent_size <= REENTRANTHALFMAXSIZE) {
737 PL_reentrant_buffer->_gethostent_size *= 2;
738 Renew(PL_reentrant_buffer->_gethostent_buffer,
739 PL_reentrant_buffer->_gethostent_size, char);
740 switch (PL_op->op_type) {
741 case OP_GHBYADDR:
742 p0 = va_arg(ap, void *);
743 asize = va_arg(ap, size_t);
744 anint = va_arg(ap, int);
745 retptr = gethostbyaddr(p0, asize, anint); break;
746 case OP_GHBYNAME:
747 p0 = va_arg(ap, void *);
748 retptr = gethostbyname(p0); break;
749 case OP_GHOSTENT:
750 retptr = gethostent(); break;
751 default:
752 break;
753 }
754 }
755 }
756 break;
757#endif
758#ifdef USE_GETGRENT_BUFFER
759 case OP_GGRNAM:
760 case OP_GGRGID:
761 case OP_GGRENT:
762 {
763 if (PL_reentrant_buffer->_getgrent_size <= REENTRANTHALFMAXSIZE) {
764 Gid_t gid;
765 PL_reentrant_buffer->_getgrent_size *= 2;
766 Renew(PL_reentrant_buffer->_getgrent_buffer,
767 PL_reentrant_buffer->_getgrent_size, char);
768 switch (PL_op->op_type) {
769 case OP_GGRNAM:
770 p0 = va_arg(ap, void *);
771 retptr = getgrnam(p0); break;
772 case OP_GGRGID:
773 gid = va_arg(ap, Gid_t);
774 retptr = getgrgid(gid); break;
775 case OP_GGRENT:
776 retptr = getgrent(); break;
777 default:
778 break;
779 }
780 }
781 }
782 break;
783#endif
784#ifdef USE_GETNETENT_BUFFER
785 case OP_GNBYADDR:
786 case OP_GNBYNAME:
787 case OP_GNETENT:
788 {
789 if (PL_reentrant_buffer->_getnetent_size <= REENTRANTHALFMAXSIZE) {
790 Netdb_net_t net;
791 PL_reentrant_buffer->_getnetent_size *= 2;
792 Renew(PL_reentrant_buffer->_getnetent_buffer,
793 PL_reentrant_buffer->_getnetent_size, char);
794 switch (PL_op->op_type) {
795 case OP_GNBYADDR:
796 net = va_arg(ap, Netdb_net_t);
797 anint = va_arg(ap, int);
798 retptr = getnetbyaddr(net, anint); break;
799 case OP_GNBYNAME:
800 p0 = va_arg(ap, void *);
801 retptr = getnetbyname(p0); break;
802 case OP_GNETENT:
803 retptr = getnetent(); break;
804 default:
805 break;
806 }
807 }
808 }
809 break;
810#endif
811#ifdef USE_GETPWENT_BUFFER
812 case OP_GPWNAM:
813 case OP_GPWUID:
814 case OP_GPWENT:
815 {
816 if (PL_reentrant_buffer->_getpwent_size <= REENTRANTHALFMAXSIZE) {
817 Uid_t uid;
818 PL_reentrant_buffer->_getpwent_size *= 2;
819 Renew(PL_reentrant_buffer->_getpwent_buffer,
820 PL_reentrant_buffer->_getpwent_size, char);
821 switch (PL_op->op_type) {
822 case OP_GPWNAM:
823 p0 = va_arg(ap, void *);
824 retptr = getpwnam(p0); break;
825 case OP_GPWUID:
826 uid = va_arg(ap, Uid_t);
827 retptr = getpwuid(uid); break;
828 case OP_GPWENT:
829 retptr = getpwent(); break;
830 default:
831 break;
832 }
833 }
834 }
835 break;
836#endif
837#ifdef USE_GETPROTOENT_BUFFER
838 case OP_GPBYNAME:
839 case OP_GPBYNUMBER:
840 case OP_GPROTOENT:
841 {
842 if (PL_reentrant_buffer->_getprotoent_size <= REENTRANTHALFMAXSIZE) {
843 PL_reentrant_buffer->_getprotoent_size *= 2;
844 Renew(PL_reentrant_buffer->_getprotoent_buffer,
845 PL_reentrant_buffer->_getprotoent_size, char);
846 switch (PL_op->op_type) {
847 case OP_GPBYNAME:
848 p0 = va_arg(ap, void *);
849 retptr = getprotobyname(p0); break;
850 case OP_GPBYNUMBER:
851 anint = va_arg(ap, int);
852 retptr = getprotobynumber(anint); break;
853 case OP_GPROTOENT:
854 retptr = getprotoent(); break;
855 default:
856 break;
857 }
858 }
859 }
860 break;
861#endif
862#ifdef USE_GETSERVENT_BUFFER
863 case OP_GSBYNAME:
864 case OP_GSBYPORT:
865 case OP_GSERVENT:
866 {
867 if (PL_reentrant_buffer->_getservent_size <= REENTRANTHALFMAXSIZE) {
868 PL_reentrant_buffer->_getservent_size *= 2;
869 Renew(PL_reentrant_buffer->_getservent_buffer,
870 PL_reentrant_buffer->_getservent_size, char);
871 switch (PL_op->op_type) {
872 case OP_GSBYNAME:
873 p0 = va_arg(ap, void *);
874 p1 = va_arg(ap, void *);
875 retptr = getservbyname(p0, p1); break;
876 case OP_GSBYPORT:
877 anint = va_arg(ap, int);
878 p0 = va_arg(ap, void *);
879 retptr = getservbyport(anint, p0); break;
880 case OP_GSERVENT:
881 retptr = getservent(); break;
882 default:
883 break;
884 }
885 }
886 }
887 break;
888#endif
889 default:
890 /* Not known how to retry, so just fail. */
891 break;
892 }
893
894 va_end(ap);
895#endif
896 return retptr;
897}
898
10bc17b6
JH
899EOF
900
901__DATA__
902asctime S |time |const struct tm|B_SB|B_SBI|I_SB|I_SBI
b430fd04 903crypt CC |crypt |struct crypt_data|B_CCS|B_CCD|D=CRYPTD*
10bc17b6
JH
904ctermid B |stdio | |B_B
905ctime S |time |const time_t |B_SB|B_SBI|I_SB|I_SBI
906drand48 |stdlib |struct drand48_data |I_ST|T=double*
907endgrent |grp | |I_H|V_H
31ee0cb7
JH
908endhostent |netdb | |I_D|V_D|D=struct hostent_data*
909endnetent |netdb | |I_D|V_D|D=struct netent_data*
910endprotoent |netdb | |I_D|V_D|D=struct protoent_data*
10bc17b6 911endpwent |pwd | |I_H|V_H
31ee0cb7 912endservent |netdb | |I_D|V_D|D=struct servent_data*
10bc17b6
JH
913getgrent |grp |struct group |I_SBWR|I_SBIR|S_SBW|S_SBI|I_SBI|I_SBIH
914getgrgid T |grp |struct group |I_TSBWR|I_TSBIR|I_TSBI|S_TSBI|T=gid_t
915getgrnam C |grp |struct group |I_CSBWR|I_CSBIR|S_CBI|I_CSBI|S_CSBI
916gethostbyaddr CWI |netdb |struct hostent |I_CWISBWRE|S_CWISBWIE|S_CWISBIE|S_TWISBIE|S_CIISBIE|S_CSBIE|S_TSBIE|I_CWISD|I_CIISD|I_CII|D=struct hostent_data*|T=const void*
917gethostbyname C |netdb |struct hostent |I_CSBWRE|S_CSBIE|I_CSD|D=struct hostent_data*
918gethostent |netdb |struct hostent |I_SBWRE|I_SBIE|S_SBIE|S_SBI|I_SBI|I_SD|D=struct hostent_data*
919getlogin |unistd | |I_BW|I_BI|B_BW|B_BI
920getnetbyaddr LI |netdb |struct netent |I_UISBWRE|I_LISBI|S_TISBI|S_LISBI|I_TISD|I_LISD|I_IISD|D=struct netent_data*|T=in_addr_t|U=unsigned long
921getnetbyname C |netdb |struct netent |I_CSBWRE|I_CSBI|S_CSBI|I_CSD|D=struct netent_data*
922getnetent |netdb |struct netent |I_SBWRE|I_SBIE|S_SBIE|S_SBI|I_SBI|I_SD|D=struct netent_data*
923getprotobyname C|netdb |struct protoent|I_CSBWR|S_CSBI|I_CSD|D=struct protoent_data*
924getprotobynumber I |netdb |struct protoent|I_ISBWR|S_ISBI|I_ISD|D=struct protoent_data*
925getprotoent |netdb |struct protoent|I_SBWR|I_SBI|S_SBI|I_SD|D=struct protoent_data*
926getpwent |pwd |struct passwd |I_SBWR|I_SBIR|S_SBW|S_SBI|I_SBI|I_SBIH
927getpwnam C |pwd |struct passwd |I_CSBWR|I_CSBIR|S_CSBI|I_CSBI
928getpwuid T |pwd |struct passwd |I_TSBWR|I_TSBIR|I_TSBI|S_TSBI|T=uid_t
929getservbyname CC|netdb |struct servent |I_CCSBWR|S_CCSBI|I_CCSD|D=struct servent_data*
930getservbyport IC|netdb |struct servent |I_ICSBWR|S_ICSBI|I_ICSD|D=struct servent_data*
931getservent |netdb |struct servent |I_SBWR|I_SBI|S_SBI|I_SD|D=struct servent_data*
932getspnam C |shadow |struct spwd |I_CSBWR|S_CSBI
933gmtime T |time |struct tm |S_TS|I_TS|T=const time_t*
934localtime T |time |struct tm |S_TS|I_TS|T=const time_t*
935random |stdlib |struct random_data|I_TS|T=int*
936readdir T |dirent |struct dirent |I_TSR|I_TS|T=DIR*
937readdir64 T |dirent |struct dirent64|I_TSR|I_TS|T=DIR*
938setgrent |grp | |I_H|V_H
939sethostent I |netdb | |I_ID|V_ID|D=struct hostent_data*
940setlocale IC |locale | |I_ICBI
941setnetent I |netdb | |I_ID|V_ID|D=struct netent_data*
942setprotoent I |netdb | |I_ID|V_ID|D=struct protoent_data*
943setpwent |pwd | |I_H|V_H
944setservent I |netdb | |I_ID|V_ID|D=struct servent_data*
945srand48 L |stdlib |struct drand48_data |I_LS
946srandom T |stdlib |struct random_data|I_TS|T=unsigned int
947strerror I |string | |I_IBW|I_IBI|B_IBW
948tmpnam B |stdio | |B_B
949ttyname I |unistd | |I_IBW|I_IBI|B_IBI