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