Commit | Line | Data |
10bc17b6 |
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 | |
8 | use strict; |
9 | use Getopt::Std; |
10 | my %opts; |
11 | getopts('U', \%opts); |
12 | |
13 | my %map = ( |
14 | V => "void", |
15 | A => "char*", # as an input argument |
16 | B => "char*", # as an output argument |
17 | C => "const char*", # as a read-only input argument |
18 | I => "int", |
19 | L => "long", |
20 | W => "size_t", |
21 | H => "FILE**", |
22 | E => "int*", |
23 | ); |
24 | |
25 | # (See the definitions after __DATA__.) |
26 | # In func|inc|type|... a "S" means "type*", and a "R" means "type**". |
27 | # (The "types" are often structs, such as "struct passwd".) |
28 | # |
29 | # After the prototypes one can have |X=...|Y=... to define more types. |
30 | # A commonly used extra type is to define D to be equal to "type_data", |
31 | # for example "struct_hostent_data to" go with "struct hostent". |
32 | # |
33 | # Example #1: I_XSBWR means int func_r(X, type, char*, size_t, type**) |
34 | # Example #2: S_SBIE means type func_r(type, char*, int, int*) |
35 | # Example #3: S_CBI means type func_r(const char*, char*, int) |
36 | |
37 | |
38 | die "reentr.h: $!" unless open(H, ">reentr.h"); |
39 | select H; |
40 | print <<EOF; |
41 | /* |
42 | * reentr.h |
43 | * |
44 | * Copyright (c) 1997-2002, Larry Wall |
45 | * |
46 | * You may distribute under the terms of either the GNU General Public |
47 | * License or the Artistic License, as specified in the README file. |
48 | * |
49 | * !!!!!!! DO NOT EDIT THIS FILE !!!!!!! |
50 | * This file is built by reentrl.pl from data in reentr.pl. |
51 | */ |
52 | |
53 | #ifndef REENTR_H |
54 | #define REENTR_H |
55 | |
56 | #ifdef USE_REENTRANT_API |
57 | |
58 | /* Deprecations: some platforms have the said reentrant interfaces |
59 | * but they are declared obsolete and are not to be used. Often this |
60 | * means that the platform has threadsafed the interfaces (hopefully). |
61 | * All this is OS version dependent, so we are of course fooling ourselves. |
62 | * If you know of more deprecations on some platforms, please add your own. */ |
63 | |
64 | #ifdef __hpux |
65 | # undef HAS_CRYPT_R |
66 | # undef HAS_DRAND48_R |
efa45b01 |
67 | # undef HAS_ENDGRENT_R |
68 | # undef HAS_ENDPWENT_R |
10bc17b6 |
69 | # undef HAS_GETGRENT_R |
70 | # undef HAS_GETPWENT_R |
71 | # undef HAS_SETLOCALE_R |
72 | # undef HAS_SRAND48_R |
73 | # undef HAS_STRERROR_R |
74 | # define NETDB_R_OBSOLETE |
75 | #endif |
76 | |
77 | #if defined(__osf__) && defined(__alpha) /* Tru64 aka Digital UNIX */ |
78 | # undef HAS_CRYPT_R |
79 | # undef HAS_STRERROR_R |
80 | # define NETDB_R_OBSOLETE |
81 | #endif |
82 | |
83 | #ifdef NETDB_R_OBSOLETE |
84 | # undef HAS_ENDHOSTENT_R |
85 | # undef HAS_ENDNETENT_R |
86 | # undef HAS_ENDPROTOENT_R |
87 | # undef HAS_ENDSERVENT_R |
88 | # undef HAS_GETHOSTBYADDR_R |
89 | # undef HAS_GETHOSTBYNAME_R |
90 | # undef HAS_GETHOSTENT_R |
91 | # undef HAS_GETNETBYADDR_R |
92 | # undef HAS_GETNETBYNAME_R |
93 | # undef HAS_GETNETENT_R |
94 | # undef HAS_GETPROTOBYNAME_R |
95 | # undef HAS_GETPROTOBYNUMBER_R |
96 | # undef HAS_GETPROTOENT_R |
97 | # undef HAS_GETSERVBYNAME_R |
98 | # undef HAS_GETSERVBYPORT_R |
99 | # undef HAS_GETSERVENT_R |
100 | # undef HAS_SETHOSTENT_R |
101 | # undef HAS_SETNETENT_R |
102 | # undef HAS_SETPROTOENT_R |
103 | # undef HAS_SETSERVENT_R |
104 | #endif |
105 | |
106 | #ifdef I_PWD |
107 | # include <pwd.h> |
108 | #endif |
109 | #ifdef I_GRP |
110 | # include <grp.h> |
111 | #endif |
112 | #ifdef I_NETDB |
113 | # include <netdb.h> |
114 | #endif |
115 | #ifdef I_STDLIB |
116 | # include <stdlib.h> /* drand48_data */ |
117 | #endif |
118 | #ifdef I_CRYPT |
119 | # ifdef I_CRYPT |
120 | # include <crypt.h> |
121 | # endif |
122 | #endif |
123 | #ifdef HAS_GETSPNAM_R |
124 | # ifdef I_SHADOW |
125 | # include <shadow.h> |
126 | # endif |
127 | #endif |
128 | |
129 | EOF |
130 | |
131 | my %seenh; |
132 | my %seena; |
133 | my @seenf; |
134 | my %seenp; |
135 | my %seent; |
136 | my %seens; |
137 | my %seend; |
138 | my %seenu; |
139 | |
140 | while (<DATA>) { |
141 | next if /^\s+$/; |
142 | chomp; |
143 | my ($f, $h, $t, @p) = split(/\s*\|\s*/, $_, -1); |
144 | my $u; |
145 | ($f, $u) = split(' ', $f); |
146 | $seenu{$f} = defined $u ? length $u : 0; |
147 | my $F = uc $f; |
148 | push @seenf, $f; |
149 | my %m = %map; |
150 | if ($t) { |
151 | $m{S} = "$t*"; |
152 | $m{R} = "$t**"; |
153 | } |
154 | if (@p) { |
155 | while ($p[-1] =~ /=/) { |
156 | my ($k, $v) = ($p[-1] =~ /^([A-Za-z])\s*=\s*(.*)/); |
157 | $m{$k} = $v; |
158 | pop @p; |
159 | } |
160 | } |
161 | if ($opts{U} && open(U, ">d_${f}_r.U")) { |
162 | select U; |
163 | } |
164 | my $prereqh = $h eq 'stdio' ? '' : "i_$h"; # There's no i_stdio. |
165 | print <<EOF if $opts{U}; |
166 | ?RCS: \$Id: d_${f}_r.U,v $ |
167 | ?RCS: |
168 | ?RCS: Copyright (c) 2002 Jarkko Hietaniemi |
169 | ?RCS: |
170 | ?RCS: You may distribute under the terms of either the GNU General Public |
171 | ?RCS: License or the Artistic License, as specified in the README file. |
172 | ?RCS: |
173 | ?RCS: Generated by the reentr.pl from the Perl 5.8 distribution. |
174 | ?RCS: |
c18e646a |
175 | ?MAKE:d_${f}_r ${f}_r_proto: Inlibc Protochk Hasproto i_systypes $prereqh usethreads |
10bc17b6 |
176 | ?MAKE: -pick add \$@ %< |
177 | ?S:d_${f}_r: |
178 | ?S: This variable conditionally defines the HAS_${F}_R symbol, |
179 | ?S: which indicates to the C program that the ${f}_r() |
180 | ?S: routine is available. |
181 | ?S:. |
182 | ?S:${f}_r_proto: |
183 | ?S: This variable encodes the prototype of ${f}_r. |
184 | ?S:. |
185 | ?C:HAS_${F}_R: |
186 | ?C: This symbol, if defined, indicates that the ${f}_r routine |
187 | ?C: is available to ${f} re-entrantly. |
188 | ?C:. |
189 | ?C:${F}_R_PROTO: |
190 | ?C: This symbol encodes the prototype of ${f}_r. |
191 | ?C:. |
192 | ?H:#\$d_${f}_r HAS_${F}_R /**/ |
193 | ?H:#define ${F}_R_PROTO \$${f}_r_proto /**/ |
194 | ?H:. |
a48ec845 |
195 | ?T:try hdrs d_${f}_r_proto |
10bc17b6 |
196 | ?LINT:set d_${f}_r |
197 | ?LINT:set ${f}_r_proto |
198 | : see if ${f}_r exists |
199 | set ${f}_r d_${f}_r |
200 | eval \$inlibc |
201 | case "\$d_${f}_r" in |
202 | "\$define") |
203 | hdrs="\$i_systypes sys/types.h define stdio.h \$i_${h} $h.h" |
c18e646a |
204 | case "\$d_${f}_r_proto:\$usethreads" in |
205 | ":define") d_${f}_r_proto=define |
a48ec845 |
206 | set d_${f}_r_proto ${f}_r \$hdrs |
207 | eval \$hasproto ;; |
208 | *) ;; |
209 | esac |
210 | case "\$d_${f}_r_proto" in |
211 | define) |
10bc17b6 |
212 | EOF |
213 | for my $p (@p) { |
214 | my ($r, $a) = ($p =~ /^(.)_(.+)/); |
215 | my $v = join(", ", map { $m{$_} } split '', $a); |
216 | if ($opts{U}) { |
217 | print <<EOF ; |
218 | case "\$${f}_r_proto" in |
219 | ''|0) try='$m{$r} ${f}_r($v);' |
220 | ./protochk "extern \$try" \$hdrs && ${f}_r_proto=$p ;; |
221 | esac |
222 | EOF |
223 | } |
224 | $seenh{$f}->{$p}++; |
225 | push @{$seena{$f}}, $p; |
226 | $seenp{$p}++; |
227 | $seent{$f} = $t; |
228 | $seens{$f} = $m{S}; |
229 | $seend{$f} = $m{D}; |
230 | } |
231 | if ($opts{U}) { |
232 | print <<EOF; |
233 | case "\$${f}_r_proto" in |
234 | '') d_${f}_r=undef |
235 | ${f}_r_proto=0 |
a48ec845 |
236 | echo "Disabling ${f}_r, cannot determine prototype." >&4 ;; |
10bc17b6 |
237 | * ) case "\$${f}_r_proto" in |
238 | REENTRANT_PROTO*) ;; |
239 | *) ${f}_r_proto="REENTRANT_PROTO_\$${f}_r_proto" ;; |
240 | esac |
241 | echo "Prototype: \$try" ;; |
242 | esac |
243 | ;; |
c18e646a |
244 | *) case "\$usethreads" in |
245 | define) echo "${f}_r has no prototype, not using it." >&4 ;; |
246 | esac |
247 | ;; |
a48ec845 |
248 | esac |
249 | ;; |
10bc17b6 |
250 | *) ${f}_r_proto=0 |
251 | ;; |
252 | esac |
253 | |
254 | EOF |
255 | close(U); |
256 | } |
257 | } |
258 | |
259 | close DATA; |
260 | |
261 | select H; |
262 | |
263 | { |
264 | my $i = 1; |
265 | for my $p (sort keys %seenp) { |
266 | print "#define REENTRANT_PROTO_${p} ${i}\n"; |
267 | $i++; |
268 | } |
269 | } |
270 | |
271 | sub ifprotomatch { |
272 | my $F = shift; |
273 | join " || ", map { "${F}_R_PROTO == REENTRANT_PROTO_$_" } @_; |
274 | } |
275 | |
276 | my @struct; |
277 | my @size; |
278 | my @init; |
279 | my @free; |
280 | my @wrap; |
281 | my @define; |
282 | |
283 | sub pushssif { |
284 | push @struct, @_; |
285 | push @size, @_; |
286 | push @init, @_; |
287 | push @free, @_; |
288 | } |
289 | |
290 | sub pushinitfree { |
291 | my $f = shift; |
292 | push @init, <<EOF; |
293 | New(31338, PL_reentrant_buffer->_${f}_buffer, PL_reentrant_buffer->_${f}_size, char); |
294 | EOF |
295 | push @free, <<EOF; |
296 | Safefree(PL_reentrant_buffer->_${f}_buffer); |
297 | EOF |
298 | } |
299 | |
300 | sub define { |
301 | my ($n, $p, @F) = @_; |
302 | my @H; |
303 | my $H = uc $F[0]; |
304 | push @define, <<EOF; |
305 | /* The @F using \L$n? */ |
306 | |
307 | EOF |
308 | for my $f (@F) { |
309 | my $F = uc $f; |
310 | my $h = "${F}_R_HAS_$n"; |
311 | push @H, $h; |
312 | my @h = grep { /$p/ } @{$seena{$f}}; |
313 | if (@h) { |
09310450 |
314 | push @define, "#if defined(HAS_${F}_R) && (" . join(" || ", map { "${F}_R_PROTO == REENTRANT_PROTO_$_" } @h) . ")\n"; |
10bc17b6 |
315 | |
316 | push @define, <<EOF; |
317 | # define $h |
318 | #else |
319 | # undef $h |
320 | #endif |
321 | EOF |
322 | } |
323 | } |
324 | push @define, <<EOF; |
325 | |
326 | /* Any of the @F using \L$n? */ |
327 | |
328 | EOF |
329 | push @define, "#if (" . join(" || ", map { "defined($_)" } @H) . ")\n"; |
330 | push @define, <<EOF; |
331 | # define USE_${H}_$n |
332 | #else |
333 | # undef USE_${H}_$n |
334 | #endif |
335 | |
336 | EOF |
337 | } |
338 | |
edd309b7 |
339 | define('BUFFER', 'B', |
340 | qw(getgrent getgrgid getgrnam)); |
341 | |
10bc17b6 |
342 | define('PTR', 'R', |
343 | qw(getgrent getgrgid getgrnam)); |
344 | define('PTR', 'R', |
345 | qw(getpwent getpwnam getpwuid)); |
346 | define('PTR', 'R', |
347 | qw(getspent getspnam)); |
348 | |
349 | define('FPTR', 'H', |
350 | qw(getgrent getgrgid getgrnam)); |
351 | define('FPTR', 'H', |
352 | qw(getpwent getpwnam getpwuid)); |
353 | |
edd309b7 |
354 | define('BUFFER', 'B', |
355 | qw(getpwent getpwgid getpwnam)); |
356 | |
10bc17b6 |
357 | define('PTR', 'R', |
358 | qw(gethostent gethostbyaddr gethostbyname)); |
359 | define('PTR', 'R', |
360 | qw(getnetent getnetbyaddr getnetbyname)); |
361 | define('PTR', 'R', |
362 | qw(getprotoent getprotobyname getprotobynumber)); |
363 | define('PTR', 'R', |
364 | qw(getservent getservbyname getservbyport)); |
365 | |
edd309b7 |
366 | define('BUFFER', 'B', |
367 | qw(gethostent gethostbyaddr gethostbyname)); |
368 | define('BUFFER', 'B', |
369 | qw(getnetent getnetbyaddr getnetbyname)); |
370 | define('BUFFER', 'B', |
371 | qw(getprotoent getprotobyname getprotobynumber)); |
372 | define('BUFFER', 'B', |
373 | qw(getservent getservbyname getservbyport)); |
374 | |
10bc17b6 |
375 | define('ERRNO', 'E', |
376 | qw(gethostent gethostbyaddr gethostbyname)); |
377 | define('ERRNO', 'E', |
378 | qw(getnetent getnetbyaddr getnetbyname)); |
379 | |
380 | for my $f (@seenf) { |
381 | my $F = uc $f; |
382 | my $ifdef = "#ifdef HAS_${F}_R\n"; |
383 | my $endif = "#endif /* HAS_${F}_R */\n"; |
384 | if (exists $seena{$f}) { |
385 | my @p = @{$seena{$f}}; |
386 | if ($f =~ /^(asctime|ctime|getlogin|setlocale|strerror|ttyname)$/) { |
387 | pushssif $ifdef; |
388 | push @struct, <<EOF; |
389 | char* _${f}_buffer; |
390 | size_t _${f}_size; |
391 | EOF |
392 | push @size, <<EOF; |
393 | PL_reentrant_buffer->_${f}_size = 256; /* Make something up. */ |
394 | EOF |
395 | pushinitfree $f; |
396 | pushssif $endif; |
397 | } |
b430fd04 |
398 | elsif ($f =~ /^(crypt)$/) { |
10bc17b6 |
399 | pushssif $ifdef; |
400 | push @struct, <<EOF; |
b430fd04 |
401 | #if CRYPT_R_PROTO == REENTRANT_PROTO_B_CCD |
402 | $seend{$f} _${f}_data; |
403 | #else |
10bc17b6 |
404 | $seent{$f} _${f}_struct; |
b430fd04 |
405 | #endif |
10bc17b6 |
406 | EOF |
b430fd04 |
407 | push @init, <<EOF; |
10bc17b6 |
408 | #ifdef __GLIBC__ |
409 | PL_reentrant_buffer->_${f}_struct.initialized = 0; |
410 | #endif |
411 | EOF |
b430fd04 |
412 | pushssif $endif; |
413 | } |
414 | elsif ($f =~ /^(drand48|gmtime|localtime|random)$/) { |
415 | pushssif $ifdef; |
416 | push @struct, <<EOF; |
417 | $seent{$f} _${f}_struct; |
418 | EOF |
10bc17b6 |
419 | if ($1 eq 'drand48') { |
420 | push @struct, <<EOF; |
421 | double _${f}_double; |
422 | EOF |
423 | } |
424 | pushssif $endif; |
425 | } |
426 | elsif ($f =~ /^(getgrnam|getpwnam|getspnam)$/) { |
427 | pushssif $ifdef; |
428 | my $g = $f; |
429 | $g =~ s/nam/ent/g; |
430 | my $G = uc $g; |
431 | push @struct, <<EOF; |
432 | $seent{$f} _${g}_struct; |
433 | char* _${g}_buffer; |
434 | size_t _${g}_size; |
435 | EOF |
436 | push @struct, <<EOF; |
437 | # ifdef USE_${G}_PTR |
438 | $seent{$f}* _${g}_ptr; |
439 | # endif |
440 | EOF |
441 | if ($g eq 'getspent') { |
442 | push @size, <<EOF; |
443 | PL_reentrant_buffer->_${g}_size = 1024; |
444 | EOF |
445 | } else { |
446 | push @struct, <<EOF; |
447 | # ifdef USE_${G}_FPTR |
448 | FILE* _${g}_fptr; |
449 | # endif |
450 | EOF |
451 | push @init, <<EOF; |
452 | # ifdef USE_${G}_FPTR |
453 | PL_reentrant_buffer->_${g}_fptr = NULL; |
454 | # endif |
455 | EOF |
456 | my $sc = $g eq 'getgrent' ? |
457 | '_SC_GETGR_R_SIZE_MAX' : '_SC_GETPW_R_SIZE_MAX'; |
458 | push @size, <<EOF; |
459 | # if defined(HAS_SYSCONF) && defined($sc) && !defined(__GLIBC__) |
460 | PL_reentrant_buffer->_${g}_size = sysconf($sc); |
461 | # else |
462 | # if defined(__osf__) && defined(__alpha) && defined(SIABUFSIZ) |
463 | PL_reentrant_buffer->_${g}_size = SIABUFSIZ; |
464 | # else |
465 | # ifdef __sgi |
466 | PL_reentrant_buffer->_${g}_size = BUFSIZ; |
467 | # else |
edd309b7 |
468 | PL_reentrant_buffer->_${g}_size = 256; |
10bc17b6 |
469 | # endif |
470 | # endif |
471 | # endif |
472 | EOF |
473 | } |
474 | pushinitfree $g; |
475 | pushssif $endif; |
476 | } |
477 | elsif ($f =~ /^(gethostbyname|getnetbyname|getservbyname|getprotobyname)$/) { |
478 | pushssif $ifdef; |
479 | my $g = $f; |
480 | $g =~ s/byname/ent/; |
481 | my $G = uc $g; |
482 | my $D = ifprotomatch($F, grep {/D/} @p); |
483 | my $d = $seend{$f}; |
484 | push @struct, <<EOF; |
485 | $seent{$f} _${g}_struct; |
486 | # if $D |
487 | $d _${g}_data; |
488 | # else |
489 | char* _${g}_buffer; |
490 | size_t _${g}_size; |
491 | # endif |
492 | # ifdef USE_${G}_PTR |
493 | $seent{$f}* _${g}_ptr; |
494 | # endif |
495 | EOF |
496 | push @struct, <<EOF; |
497 | # ifdef USE_${G}_ERRNO |
498 | int _${g}_errno; |
499 | # endif |
500 | EOF |
501 | push @size, <<EOF; |
502 | #if !($D) |
503 | PL_reentrant_buffer->_${g}_size = 2048; /* Any better ideas? */ |
504 | #endif |
505 | EOF |
506 | push @init, <<EOF; |
507 | #if !($D) |
508 | New(31338, PL_reentrant_buffer->_${g}_buffer, PL_reentrant_buffer->_${g}_size, char); |
509 | #endif |
510 | EOF |
511 | push @free, <<EOF; |
512 | #if !($D) |
513 | Safefree(PL_reentrant_buffer->_${g}_buffer); |
514 | #endif |
515 | EOF |
516 | pushssif $endif; |
517 | } |
518 | elsif ($f =~ /^(readdir|readdir64)$/) { |
519 | pushssif $ifdef; |
520 | my $R = ifprotomatch($F, grep {/R/} @p); |
521 | push @struct, <<EOF; |
522 | $seent{$f}* _${f}_struct; |
523 | size_t _${f}_size; |
524 | # if $R |
525 | $seent{$f}* _${f}_ptr; |
526 | # endif |
527 | EOF |
528 | push @size, <<EOF; |
529 | /* This is the size Solaris recommends. |
530 | * (though we go static, should use pathconf() instead) */ |
531 | PL_reentrant_buffer->_${f}_size = sizeof($seent{$f}) + MAXPATHLEN + 1; |
532 | EOF |
533 | push @init, <<EOF; |
534 | PL_reentrant_buffer->_${f}_struct = ($seent{$f}*)safemalloc(PL_reentrant_buffer->_${f}_size); |
535 | EOF |
536 | push @free, <<EOF; |
537 | Safefree(PL_reentrant_buffer->_${f}_struct); |
538 | EOF |
539 | pushssif $endif; |
540 | } |
541 | |
542 | push @wrap, $ifdef; |
543 | |
544 | # Doesn't implement the buffer growth loop for glibc gethostby*(). |
545 | push @wrap, <<EOF; |
546 | # undef $f |
547 | EOF |
548 | my @v = 'a'..'z'; |
549 | my $v = join(", ", @v[0..$seenu{$f}-1]); |
550 | for my $p (@p) { |
551 | my ($r, $a) = split '_', $p; |
552 | my $test = $r eq 'I' ? ' == 0' : ''; |
553 | my $true = 1; |
10bc17b6 |
554 | my $g = $f; |
555 | if ($g =~ /^(?:get|set|end)(pw|gr|host|net|proto|serv|sp)/) { |
556 | $g = "get$1ent"; |
557 | } elsif ($g eq 'srand48') { |
558 | $g = "drand48"; |
559 | } |
560 | my $b = $a; |
561 | my $w = ''; |
562 | substr($b, 0, $seenu{$f}) = ''; |
563 | if ($b =~ /R/) { |
564 | $true = "PL_reentrant_buffer->_${g}_ptr"; |
565 | } elsif ($b =~ /T/ && $f eq 'drand48') { |
566 | $true = "PL_reentrant_buffer->_${g}_double"; |
567 | } elsif ($b =~ /S/) { |
568 | if ($f =~ /^readdir/) { |
569 | $true = "PL_reentrant_buffer->_${g}_struct"; |
570 | } else { |
571 | $true = "&PL_reentrant_buffer->_${g}_struct"; |
572 | } |
573 | } elsif ($b =~ /B/) { |
574 | $true = "PL_reentrant_buffer->_${g}_buffer"; |
575 | } |
576 | if (length $b) { |
577 | $w = join ", ", |
578 | map { |
579 | $_ eq 'R' ? |
580 | "&PL_reentrant_buffer->_${g}_ptr" : |
581 | $_ eq 'E' ? |
582 | "&PL_reentrant_buffer->_${g}_errno" : |
583 | $_ eq 'B' ? |
584 | "PL_reentrant_buffer->_${g}_buffer" : |
585 | $_ =~ /^[WI]$/ ? |
586 | "PL_reentrant_buffer->_${g}_size" : |
587 | $_ eq 'H' ? |
588 | "&PL_reentrant_buffer->_${g}_fptr" : |
589 | $_ eq 'D' ? |
590 | "&PL_reentrant_buffer->_${g}_data" : |
591 | $_ eq 'S' ? |
592 | ($f =~ /^readdir/ ? |
593 | "PL_reentrant_buffer->_${g}_struct" : |
594 | "&PL_reentrant_buffer->_${g}_struct" ) : |
595 | $_ eq 'T' && $f eq 'drand48' ? |
596 | "&PL_reentrant_buffer->_${g}_double" : |
597 | $_ |
598 | } split '', $b; |
599 | $w = ", $w" if length $v; |
600 | } |
601 | my $call = "${f}_r($v$w)"; |
602 | $call = "((errno = $call))" if $r eq 'I'; |
603 | push @wrap, <<EOF; |
604 | # if !defined($f) && ${F}_R_PROTO == REENTRANT_PROTO_$p |
605 | EOF |
606 | if ($r eq 'V' || $r eq 'B') { |
607 | push @wrap, <<EOF; |
608 | # define $f($v) $call |
609 | EOF |
610 | } else { |
edd309b7 |
611 | if ($f =~ /^get/) { |
612 | my $rv = $v ? ", $v" : ""; |
613 | push @wrap, <<EOF; |
614 | # define $f($v) ($call$test ? $true : (errno == ERANGE ? Perl_reentrant_retry("$f"$rv) : 0)) |
10bc17b6 |
615 | EOF |
edd309b7 |
616 | } else { |
617 | push @wrap, <<EOF; |
618 | # define $f($v) ($call$test ? $true : 0) |
619 | EOF |
620 | } |
10bc17b6 |
621 | } |
622 | push @wrap, <<EOF; |
623 | # endif |
624 | EOF |
625 | } |
626 | |
627 | push @wrap, $endif, "\n"; |
628 | } |
629 | } |
630 | |
631 | local $" = ''; |
632 | |
633 | print <<EOF; |
634 | |
635 | /* Defines for indicating which special features are supported. */ |
636 | |
637 | @define |
638 | typedef struct { |
639 | @struct |
640 | } REENTR; |
641 | |
642 | /* The wrappers. */ |
643 | |
644 | @wrap |
645 | #endif /* USE_REENTRANT_API */ |
646 | |
647 | #endif |
648 | |
649 | EOF |
650 | |
651 | close(H); |
652 | |
653 | die "reentr.c: $!" unless open(C, ">reentr.c"); |
654 | select C; |
655 | print <<EOF; |
656 | /* |
657 | * reentr.c |
658 | * |
659 | * Copyright (c) 1997-2002, Larry Wall |
660 | * |
661 | * You may distribute under the terms of either the GNU General Public |
662 | * License or the Artistic License, as specified in the README file. |
663 | * |
664 | * !!!!!!! DO NOT EDIT THIS FILE !!!!!!! |
665 | * This file is built by reentrl.pl from data in reentr.pl. |
666 | * |
667 | * "Saruman," I said, standing away from him, "only one hand at a time can |
668 | * wield the One, and you know that well, so do not trouble to say we!" |
669 | * |
670 | */ |
671 | |
672 | #include "EXTERN.h" |
673 | #define PERL_IN_REENTR_C |
674 | #include "perl.h" |
675 | #include "reentr.h" |
676 | |
677 | void |
678 | Perl_reentrant_size(pTHX) { |
679 | #ifdef USE_REENTRANT_API |
680 | @size |
681 | #endif /* USE_REENTRANT_API */ |
682 | } |
683 | |
684 | void |
685 | Perl_reentrant_init(pTHX) { |
686 | #ifdef USE_REENTRANT_API |
687 | New(31337, PL_reentrant_buffer, 1, REENTR); |
688 | Perl_reentrant_size(aTHX); |
689 | @init |
690 | #endif /* USE_REENTRANT_API */ |
691 | } |
692 | |
693 | void |
694 | Perl_reentrant_free(pTHX) { |
695 | #ifdef USE_REENTRANT_API |
696 | @free |
697 | Safefree(PL_reentrant_buffer); |
698 | #endif /* USE_REENTRANT_API */ |
699 | } |
700 | |
edd309b7 |
701 | void* |
702 | Perl_reentrant_retry(const char *f, ...) |
703 | { |
704 | dTHX; |
705 | void *retptr = NULL; |
706 | #ifdef USE_REENTRANT_API |
707 | void *p0, *p1; |
708 | size_t asize; |
709 | int anint; |
710 | va_list ap; |
711 | |
712 | va_start(ap, f); |
713 | |
714 | #define REENTRANTHALFMAXSIZE 32768 /* The maximum may end up twice this. */ |
715 | |
716 | switch (PL_op->op_type) { |
717 | #ifdef USE_GETHOSTENT_BUFFER |
718 | case OP_GHBYADDR: |
719 | case OP_GHBYNAME: |
720 | case OP_GHOSTENT: |
721 | { |
722 | if (PL_reentrant_buffer->_gethostent_size <= REENTRANTHALFMAXSIZE) { |
723 | PL_reentrant_buffer->_gethostent_size *= 2; |
724 | Renew(PL_reentrant_buffer->_gethostent_buffer, |
725 | PL_reentrant_buffer->_gethostent_size, char); |
726 | switch (PL_op->op_type) { |
727 | case OP_GHBYADDR: |
728 | p0 = va_arg(ap, void *); |
729 | asize = va_arg(ap, size_t); |
730 | anint = va_arg(ap, int); |
731 | retptr = gethostbyaddr(p0, asize, anint); break; |
732 | case OP_GHBYNAME: |
733 | p0 = va_arg(ap, void *); |
734 | retptr = gethostbyname(p0); break; |
735 | case OP_GHOSTENT: |
736 | retptr = gethostent(); break; |
737 | default: |
738 | break; |
739 | } |
740 | } |
741 | } |
742 | break; |
743 | #endif |
744 | #ifdef USE_GETGRENT_BUFFER |
745 | case OP_GGRNAM: |
746 | case OP_GGRGID: |
747 | case OP_GGRENT: |
748 | { |
749 | if (PL_reentrant_buffer->_getgrent_size <= REENTRANTHALFMAXSIZE) { |
750 | Gid_t gid; |
751 | PL_reentrant_buffer->_getgrent_size *= 2; |
752 | Renew(PL_reentrant_buffer->_getgrent_buffer, |
753 | PL_reentrant_buffer->_getgrent_size, char); |
754 | switch (PL_op->op_type) { |
755 | case OP_GGRNAM: |
756 | p0 = va_arg(ap, void *); |
757 | retptr = getgrnam(p0); break; |
758 | case OP_GGRGID: |
759 | gid = va_arg(ap, Gid_t); |
760 | retptr = getgrgid(gid); break; |
761 | case OP_GGRENT: |
762 | retptr = getgrent(); break; |
763 | default: |
764 | break; |
765 | } |
766 | } |
767 | } |
768 | break; |
769 | #endif |
770 | #ifdef USE_GETNETENT_BUFFER |
771 | case OP_GNBYADDR: |
772 | case OP_GNBYNAME: |
773 | case OP_GNETENT: |
774 | { |
775 | if (PL_reentrant_buffer->_getnetent_size <= REENTRANTHALFMAXSIZE) { |
776 | Netdb_net_t net; |
777 | PL_reentrant_buffer->_getnetent_size *= 2; |
778 | Renew(PL_reentrant_buffer->_getnetent_buffer, |
779 | PL_reentrant_buffer->_getnetent_size, char); |
780 | switch (PL_op->op_type) { |
781 | case OP_GNBYADDR: |
782 | net = va_arg(ap, Netdb_net_t); |
783 | anint = va_arg(ap, int); |
784 | retptr = getnetbyaddr(net, anint); break; |
785 | case OP_GNBYNAME: |
786 | p0 = va_arg(ap, void *); |
787 | retptr = getnetbyname(p0); break; |
788 | case OP_GNETENT: |
789 | retptr = getnetent(); break; |
790 | default: |
791 | break; |
792 | } |
793 | } |
794 | } |
795 | break; |
796 | #endif |
797 | #ifdef USE_GETPWENT_BUFFER |
798 | case OP_GPWNAM: |
799 | case OP_GPWUID: |
800 | case OP_GPWENT: |
801 | { |
802 | if (PL_reentrant_buffer->_getpwent_size <= REENTRANTHALFMAXSIZE) { |
803 | Uid_t uid; |
804 | PL_reentrant_buffer->_getpwent_size *= 2; |
805 | Renew(PL_reentrant_buffer->_getpwent_buffer, |
806 | PL_reentrant_buffer->_getpwent_size, char); |
807 | switch (PL_op->op_type) { |
808 | case OP_GPWNAM: |
809 | p0 = va_arg(ap, void *); |
810 | retptr = getpwnam(p0); break; |
811 | case OP_GPWUID: |
812 | uid = va_arg(ap, Uid_t); |
813 | retptr = getpwuid(uid); break; |
814 | case OP_GPWENT: |
815 | retptr = getpwent(); break; |
816 | default: |
817 | break; |
818 | } |
819 | } |
820 | } |
821 | break; |
822 | #endif |
823 | #ifdef USE_GETPROTOENT_BUFFER |
824 | case OP_GPBYNAME: |
825 | case OP_GPBYNUMBER: |
826 | case OP_GPROTOENT: |
827 | { |
828 | if (PL_reentrant_buffer->_getprotoent_size <= REENTRANTHALFMAXSIZE) { |
829 | PL_reentrant_buffer->_getprotoent_size *= 2; |
830 | Renew(PL_reentrant_buffer->_getprotoent_buffer, |
831 | PL_reentrant_buffer->_getprotoent_size, char); |
832 | switch (PL_op->op_type) { |
833 | case OP_GPBYNAME: |
834 | p0 = va_arg(ap, void *); |
835 | retptr = getprotobyname(p0); break; |
836 | case OP_GPBYNUMBER: |
837 | anint = va_arg(ap, int); |
838 | retptr = getprotobynumber(anint); break; |
839 | case OP_GPROTOENT: |
840 | retptr = getprotoent(); break; |
841 | default: |
842 | break; |
843 | } |
844 | } |
845 | } |
846 | break; |
847 | #endif |
848 | #ifdef USE_GETSERVENT_BUFFER |
849 | case OP_GSBYNAME: |
850 | case OP_GSBYPORT: |
851 | case OP_GSERVENT: |
852 | { |
853 | if (PL_reentrant_buffer->_getservent_size <= REENTRANTHALFMAXSIZE) { |
854 | PL_reentrant_buffer->_getservent_size *= 2; |
855 | Renew(PL_reentrant_buffer->_getservent_buffer, |
856 | PL_reentrant_buffer->_getservent_size, char); |
857 | switch (PL_op->op_type) { |
858 | case OP_GSBYNAME: |
859 | p0 = va_arg(ap, void *); |
860 | p1 = va_arg(ap, void *); |
861 | retptr = getservbyname(p0, p1); break; |
862 | case OP_GSBYPORT: |
863 | anint = va_arg(ap, int); |
864 | p0 = va_arg(ap, void *); |
865 | retptr = getservbyport(anint, p0); break; |
866 | case OP_GSERVENT: |
867 | retptr = getservent(); break; |
868 | default: |
869 | break; |
870 | } |
871 | } |
872 | } |
873 | break; |
874 | #endif |
875 | default: |
876 | /* Not known how to retry, so just fail. */ |
877 | break; |
878 | } |
879 | |
880 | va_end(ap); |
881 | #endif |
882 | return retptr; |
883 | } |
884 | |
10bc17b6 |
885 | EOF |
886 | |
887 | __DATA__ |
888 | asctime S |time |const struct tm|B_SB|B_SBI|I_SB|I_SBI |
b430fd04 |
889 | crypt CC |crypt |struct crypt_data|B_CCS|B_CCD|D=CRYPTD* |
10bc17b6 |
890 | ctermid B |stdio | |B_B |
891 | ctime S |time |const time_t |B_SB|B_SBI|I_SB|I_SBI |
892 | drand48 |stdlib |struct drand48_data |I_ST|T=double* |
893 | endgrent |grp | |I_H|V_H |
894 | endhostent |netdb |struct hostent_data |I_S|V_S |
895 | endnetent |netdb |struct netent_data |I_S|V_S |
896 | endprotoent |netdb |struct protoent_data |I_S|V_S |
897 | endpwent |pwd | |I_H|V_H |
898 | endservent |netdb |struct servent_data |I_S|V_S |
899 | getgrent |grp |struct group |I_SBWR|I_SBIR|S_SBW|S_SBI|I_SBI|I_SBIH |
900 | getgrgid T |grp |struct group |I_TSBWR|I_TSBIR|I_TSBI|S_TSBI|T=gid_t |
901 | getgrnam C |grp |struct group |I_CSBWR|I_CSBIR|S_CBI|I_CSBI|S_CSBI |
902 | gethostbyaddr CWI |netdb |struct hostent |I_CWISBWRE|S_CWISBWIE|S_CWISBIE|S_TWISBIE|S_CIISBIE|S_CSBIE|S_TSBIE|I_CWISD|I_CIISD|I_CII|D=struct hostent_data*|T=const void* |
903 | gethostbyname C |netdb |struct hostent |I_CSBWRE|S_CSBIE|I_CSD|D=struct hostent_data* |
904 | gethostent |netdb |struct hostent |I_SBWRE|I_SBIE|S_SBIE|S_SBI|I_SBI|I_SD|D=struct hostent_data* |
905 | getlogin |unistd | |I_BW|I_BI|B_BW|B_BI |
906 | getnetbyaddr LI |netdb |struct netent |I_UISBWRE|I_LISBI|S_TISBI|S_LISBI|I_TISD|I_LISD|I_IISD|D=struct netent_data*|T=in_addr_t|U=unsigned long |
907 | getnetbyname C |netdb |struct netent |I_CSBWRE|I_CSBI|S_CSBI|I_CSD|D=struct netent_data* |
908 | getnetent |netdb |struct netent |I_SBWRE|I_SBIE|S_SBIE|S_SBI|I_SBI|I_SD|D=struct netent_data* |
909 | getprotobyname C|netdb |struct protoent|I_CSBWR|S_CSBI|I_CSD|D=struct protoent_data* |
910 | getprotobynumber I |netdb |struct protoent|I_ISBWR|S_ISBI|I_ISD|D=struct protoent_data* |
911 | getprotoent |netdb |struct protoent|I_SBWR|I_SBI|S_SBI|I_SD|D=struct protoent_data* |
912 | getpwent |pwd |struct passwd |I_SBWR|I_SBIR|S_SBW|S_SBI|I_SBI|I_SBIH |
913 | getpwnam C |pwd |struct passwd |I_CSBWR|I_CSBIR|S_CSBI|I_CSBI |
914 | getpwuid T |pwd |struct passwd |I_TSBWR|I_TSBIR|I_TSBI|S_TSBI|T=uid_t |
915 | getservbyname CC|netdb |struct servent |I_CCSBWR|S_CCSBI|I_CCSD|D=struct servent_data* |
916 | getservbyport IC|netdb |struct servent |I_ICSBWR|S_ICSBI|I_ICSD|D=struct servent_data* |
917 | getservent |netdb |struct servent |I_SBWR|I_SBI|S_SBI|I_SD|D=struct servent_data* |
918 | getspnam C |shadow |struct spwd |I_CSBWR|S_CSBI |
919 | gmtime T |time |struct tm |S_TS|I_TS|T=const time_t* |
920 | localtime T |time |struct tm |S_TS|I_TS|T=const time_t* |
921 | random |stdlib |struct random_data|I_TS|T=int* |
922 | readdir T |dirent |struct dirent |I_TSR|I_TS|T=DIR* |
923 | readdir64 T |dirent |struct dirent64|I_TSR|I_TS|T=DIR* |
924 | setgrent |grp | |I_H|V_H |
925 | sethostent I |netdb | |I_ID|V_ID|D=struct hostent_data* |
926 | setlocale IC |locale | |I_ICBI |
927 | setnetent I |netdb | |I_ID|V_ID|D=struct netent_data* |
928 | setprotoent I |netdb | |I_ID|V_ID|D=struct protoent_data* |
929 | setpwent |pwd | |I_H|V_H |
930 | setservent I |netdb | |I_ID|V_ID|D=struct servent_data* |
931 | srand48 L |stdlib |struct drand48_data |I_LS |
932 | srandom T |stdlib |struct random_data|I_TS|T=unsigned int |
933 | strerror I |string | |I_IBW|I_IBI|B_IBW |
934 | tmpnam B |stdio | |B_B |
935 | ttyname I |unistd | |I_IBW|I_IBI|B_IBI |