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