4 # Generate the reentr.c and reentr.h,
5 # and optionally also the relevant metaconfig units (-U option).
15 A => "char*", # as an input argument
16 B => "char*", # as an output argument
17 C => "const char*", # as a read-only input argument
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".)
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".
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)
38 die "reentr.h: $!" unless open(H, ">reentr.h");
44 * Copyright (c) 1997-2002, Larry Wall
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.
49 * !!!!!!! DO NOT EDIT THIS FILE !!!!!!!
50 * This file is built by reentrl.pl from data in reentr.pl.
56 #ifdef USE_REENTRANT_API
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. */
67 # undef HAS_GETGRENT_R
68 # undef HAS_GETPWENT_R
69 # undef HAS_SETLOCALE_R
71 # undef HAS_STRERROR_R
72 # define NETDB_R_OBSOLETE
75 #if defined(__osf__) && defined(__alpha) /* Tru64 aka Digital UNIX */
77 # undef HAS_STRERROR_R
78 # define NETDB_R_OBSOLETE
81 #ifdef NETDB_R_OBSOLETE
82 # undef HAS_ENDHOSTENT_R
83 # undef HAS_ENDNETENT_R
84 # undef HAS_ENDPROTOENT_R
85 # undef HAS_ENDSERVENT_R
86 # undef HAS_GETHOSTBYADDR_R
87 # undef HAS_GETHOSTBYNAME_R
88 # undef HAS_GETHOSTENT_R
89 # undef HAS_GETNETBYADDR_R
90 # undef HAS_GETNETBYNAME_R
91 # undef HAS_GETNETENT_R
92 # undef HAS_GETPROTOBYNAME_R
93 # undef HAS_GETPROTOBYNUMBER_R
94 # undef HAS_GETPROTOENT_R
95 # undef HAS_GETSERVBYNAME_R
96 # undef HAS_GETSERVBYPORT_R
97 # undef HAS_GETSERVENT_R
98 # undef HAS_SETHOSTENT_R
99 # undef HAS_SETNETENT_R
100 # undef HAS_SETPROTOENT_R
101 # undef HAS_SETSERVENT_R
114 # include <stdlib.h> /* drand48_data */
121 #ifdef HAS_GETSPNAM_R
141 my ($f, $h, $t, @p) = split(/\s*\|\s*/, $_, -1);
143 ($f, $u) = split(' ', $f);
144 $seenu{$f} = defined $u ? length $u : 0;
153 while ($p[-1] =~ /=/) {
154 my ($k, $v) = ($p[-1] =~ /^([A-Za-z])\s*=\s*(.*)/);
159 if ($opts{U} && open(U, ">d_${f}_r.U")) {
162 my $prereqh = $h eq 'stdio' ? '' : "i_$h"; # There's no i_stdio.
163 print <<EOF if $opts{U};
164 ?RCS: \$Id: d_${f}_r.U,v $
166 ?RCS: Copyright (c) 2002 Jarkko Hietaniemi
168 ?RCS: You may distribute under the terms of either the GNU General Public
169 ?RCS: License or the Artistic License, as specified in the README file.
171 ?RCS: Generated by the reentr.pl from the Perl 5.8 distribution.
173 ?MAKE:d_${f}_r ${f}_r_proto: Inlibc Protochk i_systypes $prereqh
174 ?MAKE: -pick add \$@ %<
176 ?S: This variable conditionally defines the HAS_${F}_R symbol,
177 ?S: which indicates to the C program that the ${f}_r()
178 ?S: routine is available.
181 ?S: This variable encodes the prototype of ${f}_r.
184 ?C: This symbol, if defined, indicates that the ${f}_r routine
185 ?C: is available to ${f} re-entrantly.
188 ?C: This symbol encodes the prototype of ${f}_r.
190 ?H:#\$d_${f}_r HAS_${F}_R /**/
191 ?H:#define ${F}_R_PROTO \$${f}_r_proto /**/
195 ?LINT:set ${f}_r_proto
196 : see if ${f}_r exists
201 hdrs="\$i_systypes sys/types.h define stdio.h \$i_${h} $h.h"
204 my ($r, $a) = ($p =~ /^(.)_(.+)/);
205 my $v = join(", ", map { $m{$_} } split '', $a);
208 case "\$${f}_r_proto" in
209 ''|0) try='$m{$r} ${f}_r($v);'
210 ./protochk "extern \$try" \$hdrs && ${f}_r_proto=$p ;;
215 push @{$seena{$f}}, $p;
223 case "\$${f}_r_proto" in
226 echo "Disabling ${f}_r, cannot determine prototype." ;;
227 * ) case "\$${f}_r_proto" in
229 *) ${f}_r_proto="REENTRANT_PROTO_\$${f}_r_proto" ;;
231 echo "Prototype: \$try" ;;
249 for my $p (sort keys %seenp) {
250 print "#define REENTRANT_PROTO_${p} ${i}\n";
257 join " || ", map { "${F}_R_PROTO == REENTRANT_PROTO_$_" } @_;
277 New(31338, PL_reentrant_buffer->_${f}_buffer, PL_reentrant_buffer->_${f}_size, char);
280 Safefree(PL_reentrant_buffer->_${f}_buffer);
285 my ($n, $p, @F) = @_;
289 /* The @F using \L$n? */
294 my $h = "${F}_R_HAS_$n";
296 my @h = grep { /$p/ } @{$seena{$f}};
298 push @define, "#if (" . join(" || ", map { "${F}_R_PROTO == REENTRANT_PROTO_$_" } @h) . ")\n";
310 /* Any of the @F using \L$n? */
313 push @define, "#if (" . join(" || ", map { "defined($_)" } @H) . ")\n";
324 qw(getgrent getgrgid getgrnam));
326 qw(getpwent getpwnam getpwuid));
328 qw(getspent getspnam));
331 qw(getgrent getgrgid getgrnam));
333 qw(getpwent getpwnam getpwuid));
336 qw(gethostent gethostbyaddr gethostbyname));
338 qw(getnetent getnetbyaddr getnetbyname));
340 qw(getprotoent getprotobyname getprotobynumber));
342 qw(getservent getservbyname getservbyport));
345 qw(gethostent gethostbyaddr gethostbyname));
347 qw(getnetent getnetbyaddr getnetbyname));
351 my $ifdef = "#ifdef HAS_${F}_R\n";
352 my $endif = "#endif /* HAS_${F}_R */\n";
353 if (exists $seena{$f}) {
354 my @p = @{$seena{$f}};
355 if ($f =~ /^(asctime|ctime|getlogin|setlocale|strerror|ttyname)$/) {
362 PL_reentrant_buffer->_${f}_size = 256; /* Make something up. */
367 elsif ($f =~ /^(crypt|drand48|gmtime|localtime|random)$/) {
370 $seent{$f} _${f}_struct;
375 PL_reentrant_buffer->_${f}_struct.initialized = 0;
379 if ($1 eq 'drand48') {
386 elsif ($f =~ /^(getgrnam|getpwnam|getspnam)$/) {
392 $seent{$f} _${g}_struct;
398 $seent{$f}* _${g}_ptr;
401 if ($g eq 'getspent') {
403 PL_reentrant_buffer->_${g}_size = 1024;
407 # ifdef USE_${G}_FPTR
412 # ifdef USE_${G}_FPTR
413 PL_reentrant_buffer->_${g}_fptr = NULL;
416 my $sc = $g eq 'getgrent' ?
417 '_SC_GETGR_R_SIZE_MAX' : '_SC_GETPW_R_SIZE_MAX';
419 # if defined(HAS_SYSCONF) && defined($sc) && !defined(__GLIBC__)
420 PL_reentrant_buffer->_${g}_size = sysconf($sc);
422 # if defined(__osf__) && defined(__alpha) && defined(SIABUFSIZ)
423 PL_reentrant_buffer->_${g}_size = SIABUFSIZ;
426 PL_reentrant_buffer->_${g}_size = BUFSIZ;
428 PL_reentrant_buffer->_${g}_size = 2048;
437 elsif ($f =~ /^(gethostbyname|getnetbyname|getservbyname|getprotobyname)$/) {
442 my $D = ifprotomatch($F, grep {/D/} @p);
445 $seent{$f} _${g}_struct;
453 $seent{$f}* _${g}_ptr;
457 # ifdef USE_${G}_ERRNO
463 PL_reentrant_buffer->_${g}_size = 2048; /* Any better ideas? */
468 New(31338, PL_reentrant_buffer->_${g}_buffer, PL_reentrant_buffer->_${g}_size, char);
473 Safefree(PL_reentrant_buffer->_${g}_buffer);
478 elsif ($f =~ /^(readdir|readdir64)$/) {
480 my $R = ifprotomatch($F, grep {/R/} @p);
482 $seent{$f}* _${f}_struct;
485 $seent{$f}* _${f}_ptr;
489 /* This is the size Solaris recommends.
490 * (though we go static, should use pathconf() instead) */
491 PL_reentrant_buffer->_${f}_size = sizeof($seent{$f}) + MAXPATHLEN + 1;
494 PL_reentrant_buffer->_${f}_struct = ($seent{$f}*)safemalloc(PL_reentrant_buffer->_${f}_size);
497 Safefree(PL_reentrant_buffer->_${f}_struct);
504 # Doesn't implement the buffer growth loop for glibc gethostby*().
509 my $v = join(", ", @v[0..$seenu{$f}-1]);
511 my ($r, $a) = split '_', $p;
512 my $test = $r eq 'I' ? ' == 0' : '';
516 if ($g =~ /^(?:get|set|end)(pw|gr|host|net|proto|serv|sp)/) {
518 } elsif ($g eq 'srand48') {
523 substr($b, 0, $seenu{$f}) = '';
525 $true = "PL_reentrant_buffer->_${g}_ptr";
526 } elsif ($b =~ /T/ && $f eq 'drand48') {
527 $true = "PL_reentrant_buffer->_${g}_double";
528 } elsif ($b =~ /S/) {
529 if ($f =~ /^readdir/) {
530 $true = "PL_reentrant_buffer->_${g}_struct";
532 $true = "&PL_reentrant_buffer->_${g}_struct";
534 } elsif ($b =~ /B/) {
535 $true = "PL_reentrant_buffer->_${g}_buffer";
541 "&PL_reentrant_buffer->_${g}_ptr" :
543 "&PL_reentrant_buffer->_${g}_errno" :
545 "PL_reentrant_buffer->_${g}_buffer" :
547 "PL_reentrant_buffer->_${g}_size" :
549 "&PL_reentrant_buffer->_${g}_fptr" :
551 "&PL_reentrant_buffer->_${g}_data" :
554 "PL_reentrant_buffer->_${g}_struct" :
555 "&PL_reentrant_buffer->_${g}_struct" ) :
556 $_ eq 'T' && $f eq 'drand48' ?
557 "&PL_reentrant_buffer->_${g}_double" :
560 $w = ", $w" if length $v;
562 my $call = "${f}_r($v$w)";
563 $call = "((errno = $call))" if $r eq 'I';
565 # if !defined($f) && ${F}_R_PROTO == REENTRANT_PROTO_$p
567 if ($r eq 'V' || $r eq 'B') {
569 # define $f($v) $call
573 # define $f($v) ($call$test ? $true : $false)
581 push @wrap, $endif, "\n";
589 /* Defines for indicating which special features are supported. */
599 #endif /* USE_REENTRANT_API */
607 die "reentr.c: $!" unless open(C, ">reentr.c");
613 * Copyright (c) 1997-2002, Larry Wall
615 * You may distribute under the terms of either the GNU General Public
616 * License or the Artistic License, as specified in the README file.
618 * !!!!!!! DO NOT EDIT THIS FILE !!!!!!!
619 * This file is built by reentrl.pl from data in reentr.pl.
621 * "Saruman," I said, standing away from him, "only one hand at a time can
622 * wield the One, and you know that well, so do not trouble to say we!"
627 #define PERL_IN_REENTR_C
632 Perl_reentrant_size(pTHX) {
633 #ifdef USE_REENTRANT_API
635 #endif /* USE_REENTRANT_API */
639 Perl_reentrant_init(pTHX) {
640 #ifdef USE_REENTRANT_API
641 New(31337, PL_reentrant_buffer, 1, REENTR);
642 Perl_reentrant_size(aTHX);
644 #endif /* USE_REENTRANT_API */
648 Perl_reentrant_free(pTHX) {
649 #ifdef USE_REENTRANT_API
651 Safefree(PL_reentrant_buffer);
652 #endif /* USE_REENTRANT_API */
658 asctime S |time |const struct tm|B_SB|B_SBI|I_SB|I_SBI
659 crypt CC |crypt |struct crypt_data|B_CCS
660 ctermid B |stdio | |B_B
661 ctime S |time |const time_t |B_SB|B_SBI|I_SB|I_SBI
662 drand48 |stdlib |struct drand48_data |I_ST|T=double*
663 endgrent |grp | |I_H|V_H
664 endhostent |netdb |struct hostent_data |I_S|V_S
665 endnetent |netdb |struct netent_data |I_S|V_S
666 endprotoent |netdb |struct protoent_data |I_S|V_S
667 endpwent |pwd | |I_H|V_H
668 endservent |netdb |struct servent_data |I_S|V_S
669 getgrent |grp |struct group |I_SBWR|I_SBIR|S_SBW|S_SBI|I_SBI|I_SBIH
670 getgrgid T |grp |struct group |I_TSBWR|I_TSBIR|I_TSBI|S_TSBI|T=gid_t
671 getgrnam C |grp |struct group |I_CSBWR|I_CSBIR|S_CBI|I_CSBI|S_CSBI
672 gethostbyaddr 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*
673 gethostbyname C |netdb |struct hostent |I_CSBWRE|S_CSBIE|I_CSD|D=struct hostent_data*
674 gethostent |netdb |struct hostent |I_SBWRE|I_SBIE|S_SBIE|S_SBI|I_SBI|I_SD|D=struct hostent_data*
675 getlogin |unistd | |I_BW|I_BI|B_BW|B_BI
676 getnetbyaddr 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
677 getnetbyname C |netdb |struct netent |I_CSBWRE|I_CSBI|S_CSBI|I_CSD|D=struct netent_data*
678 getnetent |netdb |struct netent |I_SBWRE|I_SBIE|S_SBIE|S_SBI|I_SBI|I_SD|D=struct netent_data*
679 getprotobyname C|netdb |struct protoent|I_CSBWR|S_CSBI|I_CSD|D=struct protoent_data*
680 getprotobynumber I |netdb |struct protoent|I_ISBWR|S_ISBI|I_ISD|D=struct protoent_data*
681 getprotoent |netdb |struct protoent|I_SBWR|I_SBI|S_SBI|I_SD|D=struct protoent_data*
682 getpwent |pwd |struct passwd |I_SBWR|I_SBIR|S_SBW|S_SBI|I_SBI|I_SBIH
683 getpwnam C |pwd |struct passwd |I_CSBWR|I_CSBIR|S_CSBI|I_CSBI
684 getpwuid T |pwd |struct passwd |I_TSBWR|I_TSBIR|I_TSBI|S_TSBI|T=uid_t
685 getservbyname CC|netdb |struct servent |I_CCSBWR|S_CCSBI|I_CCSD|D=struct servent_data*
686 getservbyport IC|netdb |struct servent |I_ICSBWR|S_ICSBI|I_ICSD|D=struct servent_data*
687 getservent |netdb |struct servent |I_SBWR|I_SBI|S_SBI|I_SD|D=struct servent_data*
688 getspnam C |shadow |struct spwd |I_CSBWR|S_CSBI
689 gmtime T |time |struct tm |S_TS|I_TS|T=const time_t*
690 localtime T |time |struct tm |S_TS|I_TS|T=const time_t*
691 random |stdlib |struct random_data|I_TS|T=int*
692 readdir T |dirent |struct dirent |I_TSR|I_TS|T=DIR*
693 readdir64 T |dirent |struct dirent64|I_TSR|I_TS|T=DIR*
694 setgrent |grp | |I_H|V_H
695 sethostent I |netdb | |I_ID|V_ID|D=struct hostent_data*
696 setlocale IC |locale | |I_ICBI
697 setnetent I |netdb | |I_ID|V_ID|D=struct netent_data*
698 setprotoent I |netdb | |I_ID|V_ID|D=struct protoent_data*
699 setpwent |pwd | |I_H|V_H
700 setservent I |netdb | |I_ID|V_ID|D=struct servent_data*
701 srand48 L |stdlib |struct drand48_data |I_LS
702 srandom T |stdlib |struct random_data|I_TS|T=unsigned int
703 strerror I |string | |I_IBW|I_IBI|B_IBW
704 tmpnam B |stdio | |B_B
705 ttyname I |unistd | |I_IBW|I_IBI|B_IBI