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