4 * Copyright (C) 2002, 2003, by Larry Wall and others
6 * You may distribute under the terms of either the GNU General Public
7 * License or the Artistic License, as specified in the README file.
9 * !!!!!!! DO NOT EDIT THIS FILE !!!!!!!
10 * This file is built by reentrl.pl from data in reentr.pl.
12 * "Saruman," I said, standing away from him, "only one hand at a time can
13 * wield the One, and you know that well, so do not trouble to say we!"
18 #define PERL_IN_REENTR_C
23 Perl_reentrant_size(pTHX) {
24 #ifdef USE_REENTRANT_API
25 #define REENTRANTSMALLSIZE 256 /* Make something up. */
26 #define REENTRANTUSUALSIZE 4096 /* Make something up. */
28 PL_reentrant_buffer->_asctime_size = REENTRANTSMALLSIZE;
29 #endif /* HAS_ASCTIME_R */
31 #endif /* HAS_CRYPT_R */
33 PL_reentrant_buffer->_ctime_size = REENTRANTSMALLSIZE;
34 #endif /* HAS_CTIME_R */
36 #endif /* HAS_DRAND48_R */
38 # if defined(HAS_SYSCONF) && defined(_SC_GETGR_R_SIZE_MAX) && !defined(__GLIBC__)
39 PL_reentrant_buffer->_grent_size = sysconf(_SC_GETGR_R_SIZE_MAX);
40 if (PL_reentrant_buffer->_grent_size == -1)
41 PL_reentrant_buffer->_grent_size = REENTRANTUSUALSIZE;
43 # if defined(__osf__) && defined(__alpha) && defined(SIABUFSIZ)
44 PL_reentrant_buffer->_grent_size = SIABUFSIZ;
47 PL_reentrant_buffer->_grent_size = BUFSIZ;
49 PL_reentrant_buffer->_grent_size = REENTRANTUSUALSIZE;
53 #endif /* HAS_GETGRNAM_R */
54 #ifdef HAS_GETHOSTBYNAME_R
55 #if !(GETHOSTBYNAME_R_PROTO == REENTRANT_PROTO_I_CSD)
56 PL_reentrant_buffer->_hostent_size = REENTRANTUSUALSIZE;
58 #endif /* HAS_GETHOSTBYNAME_R */
60 PL_reentrant_buffer->_getlogin_size = REENTRANTSMALLSIZE;
61 #endif /* HAS_GETLOGIN_R */
62 #ifdef HAS_GETNETBYNAME_R
63 #if !(GETNETBYNAME_R_PROTO == REENTRANT_PROTO_I_CSD)
64 PL_reentrant_buffer->_netent_size = REENTRANTUSUALSIZE;
66 #endif /* HAS_GETNETBYNAME_R */
67 #ifdef HAS_GETPROTOBYNAME_R
68 #if !(GETPROTOBYNAME_R_PROTO == REENTRANT_PROTO_I_CSD)
69 PL_reentrant_buffer->_protoent_size = REENTRANTUSUALSIZE;
71 #endif /* HAS_GETPROTOBYNAME_R */
73 # if defined(HAS_SYSCONF) && defined(_SC_GETPW_R_SIZE_MAX) && !defined(__GLIBC__)
74 PL_reentrant_buffer->_pwent_size = sysconf(_SC_GETPW_R_SIZE_MAX);
75 if (PL_reentrant_buffer->_pwent_size == -1)
76 PL_reentrant_buffer->_pwent_size = REENTRANTUSUALSIZE;
78 # if defined(__osf__) && defined(__alpha) && defined(SIABUFSIZ)
79 PL_reentrant_buffer->_pwent_size = SIABUFSIZ;
82 PL_reentrant_buffer->_pwent_size = BUFSIZ;
84 PL_reentrant_buffer->_pwent_size = REENTRANTUSUALSIZE;
88 #endif /* HAS_GETPWNAM_R */
89 #ifdef HAS_GETSERVBYNAME_R
90 #if !(GETSERVBYNAME_R_PROTO == REENTRANT_PROTO_I_CCSD)
91 PL_reentrant_buffer->_servent_size = REENTRANTUSUALSIZE;
93 #endif /* HAS_GETSERVBYNAME_R */
95 # if defined(HAS_SYSCONF) && defined(_SC_GETPW_R_SIZE_MAX) && !defined(__GLIBC__)
96 PL_reentrant_buffer->_spent_size = sysconf(_SC_GETPW_R_SIZE_MAX);
97 if (PL_reentrant_buffer->_spent_size == -1)
98 PL_reentrant_buffer->_spent_size = REENTRANTUSUALSIZE;
100 # if defined(__osf__) && defined(__alpha) && defined(SIABUFSIZ)
101 PL_reentrant_buffer->_spent_size = SIABUFSIZ;
104 PL_reentrant_buffer->_spent_size = BUFSIZ;
106 PL_reentrant_buffer->_spent_size = REENTRANTUSUALSIZE;
110 #endif /* HAS_GETSPNAM_R */
112 #endif /* HAS_GMTIME_R */
113 #ifdef HAS_LOCALTIME_R
114 #endif /* HAS_LOCALTIME_R */
116 #endif /* HAS_RANDOM_R */
118 /* This is the size Solaris recommends.
119 * (though we go static, should use pathconf() instead) */
120 PL_reentrant_buffer->_readdir_size = sizeof(struct dirent) + MAXPATHLEN + 1;
121 #endif /* HAS_READDIR_R */
122 #ifdef HAS_READDIR64_R
123 /* This is the size Solaris recommends.
124 * (though we go static, should use pathconf() instead) */
125 PL_reentrant_buffer->_readdir64_size = sizeof(struct dirent64) + MAXPATHLEN + 1;
126 #endif /* HAS_READDIR64_R */
127 #ifdef HAS_SETLOCALE_R
128 PL_reentrant_buffer->_setlocale_size = REENTRANTSMALLSIZE;
129 #endif /* HAS_SETLOCALE_R */
131 #endif /* HAS_SRANDOM_R */
132 #ifdef HAS_STRERROR_R
133 PL_reentrant_buffer->_strerror_size = REENTRANTSMALLSIZE;
134 #endif /* HAS_STRERROR_R */
136 PL_reentrant_buffer->_ttyname_size = REENTRANTSMALLSIZE;
137 #endif /* HAS_TTYNAME_R */
139 #endif /* USE_REENTRANT_API */
143 Perl_reentrant_init(pTHX) {
144 #ifdef USE_REENTRANT_API
145 New(31337, PL_reentrant_buffer, 1, REENTR);
146 Perl_reentrant_size(aTHX);
148 New(31338, PL_reentrant_buffer->_asctime_buffer, PL_reentrant_buffer->_asctime_size, char);
149 #endif /* HAS_ASCTIME_R */
151 #if CRYPT_R_PROTO != REENTRANT_PROTO_B_CCD
152 PL_reentrant_buffer->_crypt_struct_buffer = 0;
154 #endif /* HAS_CRYPT_R */
156 New(31338, PL_reentrant_buffer->_ctime_buffer, PL_reentrant_buffer->_ctime_size, char);
157 #endif /* HAS_CTIME_R */
159 #endif /* HAS_DRAND48_R */
160 #ifdef HAS_GETGRNAM_R
161 # ifdef USE_GRENT_FPTR
162 PL_reentrant_buffer->_grent_fptr = NULL;
164 New(31338, PL_reentrant_buffer->_grent_buffer, PL_reentrant_buffer->_grent_size, char);
165 #endif /* HAS_GETGRNAM_R */
166 #ifdef HAS_GETHOSTBYNAME_R
167 #if !(GETHOSTBYNAME_R_PROTO == REENTRANT_PROTO_I_CSD)
168 New(31338, PL_reentrant_buffer->_hostent_buffer, PL_reentrant_buffer->_hostent_size, char);
170 #endif /* HAS_GETHOSTBYNAME_R */
171 #ifdef HAS_GETLOGIN_R
172 New(31338, PL_reentrant_buffer->_getlogin_buffer, PL_reentrant_buffer->_getlogin_size, char);
173 #endif /* HAS_GETLOGIN_R */
174 #ifdef HAS_GETNETBYNAME_R
175 #if !(GETNETBYNAME_R_PROTO == REENTRANT_PROTO_I_CSD)
176 New(31338, PL_reentrant_buffer->_netent_buffer, PL_reentrant_buffer->_netent_size, char);
178 #endif /* HAS_GETNETBYNAME_R */
179 #ifdef HAS_GETPROTOBYNAME_R
180 #if !(GETPROTOBYNAME_R_PROTO == REENTRANT_PROTO_I_CSD)
181 New(31338, PL_reentrant_buffer->_protoent_buffer, PL_reentrant_buffer->_protoent_size, char);
183 #endif /* HAS_GETPROTOBYNAME_R */
184 #ifdef HAS_GETPWNAM_R
185 # ifdef USE_PWENT_FPTR
186 PL_reentrant_buffer->_pwent_fptr = NULL;
188 New(31338, PL_reentrant_buffer->_pwent_buffer, PL_reentrant_buffer->_pwent_size, char);
189 #endif /* HAS_GETPWNAM_R */
190 #ifdef HAS_GETSERVBYNAME_R
191 #if !(GETSERVBYNAME_R_PROTO == REENTRANT_PROTO_I_CCSD)
192 New(31338, PL_reentrant_buffer->_servent_buffer, PL_reentrant_buffer->_servent_size, char);
194 #endif /* HAS_GETSERVBYNAME_R */
195 #ifdef HAS_GETSPNAM_R
196 # ifdef USE_SPENT_FPTR
197 PL_reentrant_buffer->_spent_fptr = NULL;
199 New(31338, PL_reentrant_buffer->_spent_buffer, PL_reentrant_buffer->_spent_size, char);
200 #endif /* HAS_GETSPNAM_R */
202 #endif /* HAS_GMTIME_R */
203 #ifdef HAS_LOCALTIME_R
204 #endif /* HAS_LOCALTIME_R */
206 #endif /* HAS_RANDOM_R */
208 PL_reentrant_buffer->_readdir_struct = (struct dirent*)safemalloc(PL_reentrant_buffer->_readdir_size);
209 #endif /* HAS_READDIR_R */
210 #ifdef HAS_READDIR64_R
211 PL_reentrant_buffer->_readdir64_struct = (struct dirent64*)safemalloc(PL_reentrant_buffer->_readdir64_size);
212 #endif /* HAS_READDIR64_R */
213 #ifdef HAS_SETLOCALE_R
214 New(31338, PL_reentrant_buffer->_setlocale_buffer, PL_reentrant_buffer->_setlocale_size, char);
215 #endif /* HAS_SETLOCALE_R */
217 #endif /* HAS_SRANDOM_R */
218 #ifdef HAS_STRERROR_R
219 New(31338, PL_reentrant_buffer->_strerror_buffer, PL_reentrant_buffer->_strerror_size, char);
220 #endif /* HAS_STRERROR_R */
222 New(31338, PL_reentrant_buffer->_ttyname_buffer, PL_reentrant_buffer->_ttyname_size, char);
223 #endif /* HAS_TTYNAME_R */
225 #endif /* USE_REENTRANT_API */
229 Perl_reentrant_free(pTHX) {
230 #ifdef USE_REENTRANT_API
232 Safefree(PL_reentrant_buffer->_asctime_buffer);
233 #endif /* HAS_ASCTIME_R */
235 #if CRYPT_R_PROTO != REENTRANT_PROTO_B_CCD
236 Safefree(PL_reentrant_buffer->_crypt_struct_buffer);
238 #endif /* HAS_CRYPT_R */
240 Safefree(PL_reentrant_buffer->_ctime_buffer);
241 #endif /* HAS_CTIME_R */
243 #endif /* HAS_DRAND48_R */
244 #ifdef HAS_GETGRNAM_R
245 Safefree(PL_reentrant_buffer->_grent_buffer);
246 #endif /* HAS_GETGRNAM_R */
247 #ifdef HAS_GETHOSTBYNAME_R
248 #if !(GETHOSTBYNAME_R_PROTO == REENTRANT_PROTO_I_CSD)
249 Safefree(PL_reentrant_buffer->_hostent_buffer);
251 #endif /* HAS_GETHOSTBYNAME_R */
252 #ifdef HAS_GETLOGIN_R
253 Safefree(PL_reentrant_buffer->_getlogin_buffer);
254 #endif /* HAS_GETLOGIN_R */
255 #ifdef HAS_GETNETBYNAME_R
256 #if !(GETNETBYNAME_R_PROTO == REENTRANT_PROTO_I_CSD)
257 Safefree(PL_reentrant_buffer->_netent_buffer);
259 #endif /* HAS_GETNETBYNAME_R */
260 #ifdef HAS_GETPROTOBYNAME_R
261 #if !(GETPROTOBYNAME_R_PROTO == REENTRANT_PROTO_I_CSD)
262 Safefree(PL_reentrant_buffer->_protoent_buffer);
264 #endif /* HAS_GETPROTOBYNAME_R */
265 #ifdef HAS_GETPWNAM_R
266 Safefree(PL_reentrant_buffer->_pwent_buffer);
267 #endif /* HAS_GETPWNAM_R */
268 #ifdef HAS_GETSERVBYNAME_R
269 #if !(GETSERVBYNAME_R_PROTO == REENTRANT_PROTO_I_CCSD)
270 Safefree(PL_reentrant_buffer->_servent_buffer);
272 #endif /* HAS_GETSERVBYNAME_R */
273 #ifdef HAS_GETSPNAM_R
274 Safefree(PL_reentrant_buffer->_spent_buffer);
275 #endif /* HAS_GETSPNAM_R */
277 #endif /* HAS_GMTIME_R */
278 #ifdef HAS_LOCALTIME_R
279 #endif /* HAS_LOCALTIME_R */
281 #endif /* HAS_RANDOM_R */
283 Safefree(PL_reentrant_buffer->_readdir_struct);
284 #endif /* HAS_READDIR_R */
285 #ifdef HAS_READDIR64_R
286 Safefree(PL_reentrant_buffer->_readdir64_struct);
287 #endif /* HAS_READDIR64_R */
288 #ifdef HAS_SETLOCALE_R
289 Safefree(PL_reentrant_buffer->_setlocale_buffer);
290 #endif /* HAS_SETLOCALE_R */
292 #endif /* HAS_SRANDOM_R */
293 #ifdef HAS_STRERROR_R
294 Safefree(PL_reentrant_buffer->_strerror_buffer);
295 #endif /* HAS_STRERROR_R */
297 Safefree(PL_reentrant_buffer->_ttyname_buffer);
298 #endif /* HAS_TTYNAME_R */
300 Safefree(PL_reentrant_buffer);
301 #endif /* USE_REENTRANT_API */
305 Perl_reentrant_retry(const char *f, ...)
309 #ifdef USE_REENTRANT_API
310 # 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)
313 # if defined(USE_SERVENT_BUFFER)
316 # if defined(USE_HOSTENT_BUFFER)
319 # if defined(USE_HOSTENT_BUFFER) || defined(USE_NETENT_BUFFER) || defined(USE_PROTOENT_BUFFER) || defined(USE_SERVENT_BUFFER)
326 switch (PL_op->op_type) {
327 #ifdef USE_HOSTENT_BUFFER
332 #ifdef PERL_REENTRANT_MAXSIZE
333 if (PL_reentrant_buffer->_hostent_size <=
334 PERL_REENTRANT_MAXSIZE / 2)
337 PL_reentrant_buffer->_hostent_size *= 2;
338 Renew(PL_reentrant_buffer->_hostent_buffer,
339 PL_reentrant_buffer->_hostent_size, char);
340 switch (PL_op->op_type) {
342 p0 = va_arg(ap, void *);
343 asize = va_arg(ap, size_t);
344 anint = va_arg(ap, int);
345 retptr = gethostbyaddr(p0, asize, anint); break;
347 p0 = va_arg(ap, void *);
348 retptr = gethostbyname(p0); break;
350 retptr = gethostent(); break;
352 SETERRNO(ERANGE, LIB_INVARG);
359 #ifdef USE_GRENT_BUFFER
364 #ifdef PERL_REENTRANT_MAXSIZE
365 if (PL_reentrant_buffer->_grent_size <=
366 PERL_REENTRANT_MAXSIZE / 2)
370 PL_reentrant_buffer->_grent_size *= 2;
371 Renew(PL_reentrant_buffer->_grent_buffer,
372 PL_reentrant_buffer->_grent_size, char);
373 switch (PL_op->op_type) {
375 p0 = va_arg(ap, void *);
376 retptr = getgrnam(p0); break;
378 #if Gid_t_size < INTSIZE
379 gid = (Gid_t)va_arg(ap, int);
381 gid = va_arg(ap, Gid_t);
383 retptr = getgrgid(gid); break;
385 retptr = getgrent(); break;
387 SETERRNO(ERANGE, LIB_INVARG);
394 #ifdef USE_NETENT_BUFFER
399 #ifdef PERL_REENTRANT_MAXSIZE
400 if (PL_reentrant_buffer->_netent_size <=
401 PERL_REENTRANT_MAXSIZE / 2)
405 PL_reentrant_buffer->_netent_size *= 2;
406 Renew(PL_reentrant_buffer->_netent_buffer,
407 PL_reentrant_buffer->_netent_size, char);
408 switch (PL_op->op_type) {
410 net = va_arg(ap, Netdb_net_t);
411 anint = va_arg(ap, int);
412 retptr = getnetbyaddr(net, anint); break;
414 p0 = va_arg(ap, void *);
415 retptr = getnetbyname(p0); break;
417 retptr = getnetent(); break;
419 SETERRNO(ERANGE, LIB_INVARG);
426 #ifdef USE_PWENT_BUFFER
431 #ifdef PERL_REENTRANT_MAXSIZE
432 if (PL_reentrant_buffer->_pwent_size <=
433 PERL_REENTRANT_MAXSIZE / 2)
437 PL_reentrant_buffer->_pwent_size *= 2;
438 Renew(PL_reentrant_buffer->_pwent_buffer,
439 PL_reentrant_buffer->_pwent_size, char);
440 switch (PL_op->op_type) {
442 p0 = va_arg(ap, void *);
443 retptr = getpwnam(p0); break;
445 #if Uid_t_size < INTSIZE
446 uid = (Uid_t)va_arg(ap, int);
448 uid = va_arg(ap, Uid_t);
450 retptr = getpwuid(uid); break;
452 retptr = getpwent(); break;
454 SETERRNO(ERANGE, LIB_INVARG);
461 #ifdef USE_PROTOENT_BUFFER
466 #ifdef PERL_REENTRANT_MAXSIZE
467 if (PL_reentrant_buffer->_protoent_size <=
468 PERL_REENTRANT_MAXSIZE / 2)
471 PL_reentrant_buffer->_protoent_size *= 2;
472 Renew(PL_reentrant_buffer->_protoent_buffer,
473 PL_reentrant_buffer->_protoent_size, char);
474 switch (PL_op->op_type) {
476 p0 = va_arg(ap, void *);
477 retptr = getprotobyname(p0); break;
479 anint = va_arg(ap, int);
480 retptr = getprotobynumber(anint); break;
482 retptr = getprotoent(); break;
484 SETERRNO(ERANGE, LIB_INVARG);
491 #ifdef USE_SERVENT_BUFFER
496 #ifdef PERL_REENTRANT_MAXSIZE
497 if (PL_reentrant_buffer->_servent_size <=
498 PERL_REENTRANT_MAXSIZE / 2)
501 PL_reentrant_buffer->_servent_size *= 2;
502 Renew(PL_reentrant_buffer->_servent_buffer,
503 PL_reentrant_buffer->_servent_size, char);
504 switch (PL_op->op_type) {
506 p0 = va_arg(ap, void *);
507 p1 = va_arg(ap, void *);
508 retptr = getservbyname(p0, p1); break;
510 anint = va_arg(ap, int);
511 p0 = va_arg(ap, void *);
512 retptr = getservbyport(anint, p0); break;
514 retptr = getservent(); break;
516 SETERRNO(ERANGE, LIB_INVARG);
524 /* Not known how to retry, so just fail. */