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