4 * Copyright (c) 1997-2002, Larry Wall
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->_getgrent_size = sysconf(_SC_GETGR_R_SIZE_MAX);
40 if (PL_reentrant_buffer->_getgrent_size == -1)
41 PL_reentrant_buffer->_getgrent_size = REENTRANTUSUALSIZE;
43 # if defined(__osf__) && defined(__alpha) && defined(SIABUFSIZ)
44 PL_reentrant_buffer->_getgrent_size = SIABUFSIZ;
47 PL_reentrant_buffer->_getgrent_size = BUFSIZ;
49 PL_reentrant_buffer->_getgrent_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->_gethostent_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->_getnetent_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->_getprotoent_size = REENTRANTUSUALSIZE;
71 #endif /* HAS_GETPROTOBYNAME_R */
73 # if defined(HAS_SYSCONF) && defined(_SC_GETPW_R_SIZE_MAX) && !defined(__GLIBC__)
74 PL_reentrant_buffer->_getpwent_size = sysconf(_SC_GETPW_R_SIZE_MAX);
75 if (PL_reentrant_buffer->_getpwent_size == -1)
76 PL_reentrant_buffer->_getpwent_size = REENTRANTUSUALSIZE;
78 # if defined(__osf__) && defined(__alpha) && defined(SIABUFSIZ)
79 PL_reentrant_buffer->_getpwent_size = SIABUFSIZ;
82 PL_reentrant_buffer->_getpwent_size = BUFSIZ;
84 PL_reentrant_buffer->_getpwent_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->_getservent_size = REENTRANTUSUALSIZE;
93 #endif /* HAS_GETSERVBYNAME_R */
95 PL_reentrant_buffer->_getspent_size = 1024;
96 #endif /* HAS_GETSPNAM_R */
98 #endif /* HAS_GMTIME_R */
99 #ifdef HAS_LOCALTIME_R
100 #endif /* HAS_LOCALTIME_R */
102 #endif /* HAS_RANDOM_R */
104 /* This is the size Solaris recommends.
105 * (though we go static, should use pathconf() instead) */
106 PL_reentrant_buffer->_readdir_size = sizeof(struct dirent) + MAXPATHLEN + 1;
107 #endif /* HAS_READDIR_R */
108 #ifdef HAS_READDIR64_R
109 /* This is the size Solaris recommends.
110 * (though we go static, should use pathconf() instead) */
111 PL_reentrant_buffer->_readdir64_size = sizeof(struct dirent64) + MAXPATHLEN + 1;
112 #endif /* HAS_READDIR64_R */
113 #ifdef HAS_SETLOCALE_R
114 PL_reentrant_buffer->_setlocale_size = REENTRANTSMALLSIZE;
115 #endif /* HAS_SETLOCALE_R */
116 #ifdef HAS_STRERROR_R
117 PL_reentrant_buffer->_strerror_size = REENTRANTSMALLSIZE;
118 #endif /* HAS_STRERROR_R */
120 PL_reentrant_buffer->_ttyname_size = REENTRANTSMALLSIZE;
121 #endif /* HAS_TTYNAME_R */
123 #endif /* USE_REENTRANT_API */
127 Perl_reentrant_init(pTHX) {
128 #ifdef USE_REENTRANT_API
129 New(31337, PL_reentrant_buffer, 1, REENTR);
130 Perl_reentrant_size(aTHX);
132 New(31338, PL_reentrant_buffer->_asctime_buffer, PL_reentrant_buffer->_asctime_size, char);
133 #endif /* HAS_ASCTIME_R */
136 PL_reentrant_buffer->_crypt_struct.initialized = 0;
138 #endif /* HAS_CRYPT_R */
140 New(31338, PL_reentrant_buffer->_ctime_buffer, PL_reentrant_buffer->_ctime_size, char);
141 #endif /* HAS_CTIME_R */
143 #endif /* HAS_DRAND48_R */
144 #ifdef HAS_GETGRNAM_R
145 # ifdef USE_GETGRENT_FPTR
146 PL_reentrant_buffer->_getgrent_fptr = NULL;
148 New(31338, PL_reentrant_buffer->_getgrent_buffer, PL_reentrant_buffer->_getgrent_size, char);
149 #endif /* HAS_GETGRNAM_R */
150 #ifdef HAS_GETHOSTBYNAME_R
151 #if !(GETHOSTBYNAME_R_PROTO == REENTRANT_PROTO_I_CSD)
152 New(31338, PL_reentrant_buffer->_gethostent_buffer, PL_reentrant_buffer->_gethostent_size, char);
154 #endif /* HAS_GETHOSTBYNAME_R */
155 #ifdef HAS_GETLOGIN_R
156 New(31338, PL_reentrant_buffer->_getlogin_buffer, PL_reentrant_buffer->_getlogin_size, char);
157 #endif /* HAS_GETLOGIN_R */
158 #ifdef HAS_GETNETBYNAME_R
159 #if !(GETNETBYNAME_R_PROTO == REENTRANT_PROTO_I_CSD)
160 New(31338, PL_reentrant_buffer->_getnetent_buffer, PL_reentrant_buffer->_getnetent_size, char);
162 #endif /* HAS_GETNETBYNAME_R */
163 #ifdef HAS_GETPROTOBYNAME_R
164 #if !(GETPROTOBYNAME_R_PROTO == REENTRANT_PROTO_I_CSD)
165 New(31338, PL_reentrant_buffer->_getprotoent_buffer, PL_reentrant_buffer->_getprotoent_size, char);
167 #endif /* HAS_GETPROTOBYNAME_R */
168 #ifdef HAS_GETPWNAM_R
169 # ifdef USE_GETPWENT_FPTR
170 PL_reentrant_buffer->_getpwent_fptr = NULL;
172 New(31338, PL_reentrant_buffer->_getpwent_buffer, PL_reentrant_buffer->_getpwent_size, char);
173 #endif /* HAS_GETPWNAM_R */
174 #ifdef HAS_GETSERVBYNAME_R
175 #if !(GETSERVBYNAME_R_PROTO == REENTRANT_PROTO_I_CCSD)
176 New(31338, PL_reentrant_buffer->_getservent_buffer, PL_reentrant_buffer->_getservent_size, char);
178 #endif /* HAS_GETSERVBYNAME_R */
179 #ifdef HAS_GETSPNAM_R
180 New(31338, PL_reentrant_buffer->_getspent_buffer, PL_reentrant_buffer->_getspent_size, char);
181 #endif /* HAS_GETSPNAM_R */
183 #endif /* HAS_GMTIME_R */
184 #ifdef HAS_LOCALTIME_R
185 #endif /* HAS_LOCALTIME_R */
187 #endif /* HAS_RANDOM_R */
189 PL_reentrant_buffer->_readdir_struct = (struct dirent*)safemalloc(PL_reentrant_buffer->_readdir_size);
190 #endif /* HAS_READDIR_R */
191 #ifdef HAS_READDIR64_R
192 PL_reentrant_buffer->_readdir64_struct = (struct dirent64*)safemalloc(PL_reentrant_buffer->_readdir64_size);
193 #endif /* HAS_READDIR64_R */
194 #ifdef HAS_SETLOCALE_R
195 New(31338, PL_reentrant_buffer->_setlocale_buffer, PL_reentrant_buffer->_setlocale_size, char);
196 #endif /* HAS_SETLOCALE_R */
197 #ifdef HAS_STRERROR_R
198 New(31338, PL_reentrant_buffer->_strerror_buffer, PL_reentrant_buffer->_strerror_size, char);
199 #endif /* HAS_STRERROR_R */
201 New(31338, PL_reentrant_buffer->_ttyname_buffer, PL_reentrant_buffer->_ttyname_size, char);
202 #endif /* HAS_TTYNAME_R */
204 #endif /* USE_REENTRANT_API */
208 Perl_reentrant_free(pTHX) {
209 #ifdef USE_REENTRANT_API
211 Safefree(PL_reentrant_buffer->_asctime_buffer);
212 #endif /* HAS_ASCTIME_R */
214 #endif /* HAS_CRYPT_R */
216 Safefree(PL_reentrant_buffer->_ctime_buffer);
217 #endif /* HAS_CTIME_R */
219 #endif /* HAS_DRAND48_R */
220 #ifdef HAS_GETGRNAM_R
221 Safefree(PL_reentrant_buffer->_getgrent_buffer);
222 #endif /* HAS_GETGRNAM_R */
223 #ifdef HAS_GETHOSTBYNAME_R
224 #if !(GETHOSTBYNAME_R_PROTO == REENTRANT_PROTO_I_CSD)
225 Safefree(PL_reentrant_buffer->_gethostent_buffer);
227 #endif /* HAS_GETHOSTBYNAME_R */
228 #ifdef HAS_GETLOGIN_R
229 Safefree(PL_reentrant_buffer->_getlogin_buffer);
230 #endif /* HAS_GETLOGIN_R */
231 #ifdef HAS_GETNETBYNAME_R
232 #if !(GETNETBYNAME_R_PROTO == REENTRANT_PROTO_I_CSD)
233 Safefree(PL_reentrant_buffer->_getnetent_buffer);
235 #endif /* HAS_GETNETBYNAME_R */
236 #ifdef HAS_GETPROTOBYNAME_R
237 #if !(GETPROTOBYNAME_R_PROTO == REENTRANT_PROTO_I_CSD)
238 Safefree(PL_reentrant_buffer->_getprotoent_buffer);
240 #endif /* HAS_GETPROTOBYNAME_R */
241 #ifdef HAS_GETPWNAM_R
242 Safefree(PL_reentrant_buffer->_getpwent_buffer);
243 #endif /* HAS_GETPWNAM_R */
244 #ifdef HAS_GETSERVBYNAME_R
245 #if !(GETSERVBYNAME_R_PROTO == REENTRANT_PROTO_I_CCSD)
246 Safefree(PL_reentrant_buffer->_getservent_buffer);
248 #endif /* HAS_GETSERVBYNAME_R */
249 #ifdef HAS_GETSPNAM_R
250 Safefree(PL_reentrant_buffer->_getspent_buffer);
251 #endif /* HAS_GETSPNAM_R */
253 #endif /* HAS_GMTIME_R */
254 #ifdef HAS_LOCALTIME_R
255 #endif /* HAS_LOCALTIME_R */
257 #endif /* HAS_RANDOM_R */
259 Safefree(PL_reentrant_buffer->_readdir_struct);
260 #endif /* HAS_READDIR_R */
261 #ifdef HAS_READDIR64_R
262 Safefree(PL_reentrant_buffer->_readdir64_struct);
263 #endif /* HAS_READDIR64_R */
264 #ifdef HAS_SETLOCALE_R
265 Safefree(PL_reentrant_buffer->_setlocale_buffer);
266 #endif /* HAS_SETLOCALE_R */
267 #ifdef HAS_STRERROR_R
268 Safefree(PL_reentrant_buffer->_strerror_buffer);
269 #endif /* HAS_STRERROR_R */
271 Safefree(PL_reentrant_buffer->_ttyname_buffer);
272 #endif /* HAS_TTYNAME_R */
274 Safefree(PL_reentrant_buffer);
275 #endif /* USE_REENTRANT_API */
279 Perl_reentrant_retry(const char *f, ...)
283 #ifdef USE_REENTRANT_API
284 # if defined(USE_GETHOSTENT_BUFFER) || defined(USE_GETGRENT_BUFFER) || defined(USE_GETNETENT_BUFFER) || defined(USE_GETPWENT_BUFFER) || defined(USE_GETPROTOENT_BUFFER) || defined(USE_GETSERVENT_BUFFER)
287 # if defined(USE_GETSERVENT_BUFFER)
290 # if defined(USE_GETHOSTENT_BUFFER)
293 # if defined(USE_GETHOSTENT_BUFFER) || defined(USE_GETNETENT_BUFFER) || defined(USE_GETPROTOENT_BUFFER) || defined(USE_GETSERVENT_BUFFER)
300 #define REENTRANTHALFMAXSIZE 32768 /* The maximum may end up twice this. */
302 switch (PL_op->op_type) {
303 #ifdef USE_GETHOSTENT_BUFFER
308 if (PL_reentrant_buffer->_gethostent_size <= REENTRANTHALFMAXSIZE) {
309 PL_reentrant_buffer->_gethostent_size *= 2;
310 Renew(PL_reentrant_buffer->_gethostent_buffer,
311 PL_reentrant_buffer->_gethostent_size, char);
312 switch (PL_op->op_type) {
314 p0 = va_arg(ap, void *);
315 asize = va_arg(ap, size_t);
316 anint = va_arg(ap, int);
317 retptr = gethostbyaddr(p0, asize, anint); break;
319 p0 = va_arg(ap, void *);
320 retptr = gethostbyname(p0); break;
322 retptr = gethostent(); break;
330 #ifdef USE_GETGRENT_BUFFER
335 if (PL_reentrant_buffer->_getgrent_size <= REENTRANTHALFMAXSIZE) {
337 PL_reentrant_buffer->_getgrent_size *= 2;
338 Renew(PL_reentrant_buffer->_getgrent_buffer,
339 PL_reentrant_buffer->_getgrent_size, char);
340 switch (PL_op->op_type) {
342 p0 = va_arg(ap, void *);
343 retptr = getgrnam(p0); break;
345 gid = va_arg(ap, Gid_t);
346 retptr = getgrgid(gid); break;
348 retptr = getgrent(); break;
356 #ifdef USE_GETNETENT_BUFFER
361 if (PL_reentrant_buffer->_getnetent_size <= REENTRANTHALFMAXSIZE) {
363 PL_reentrant_buffer->_getnetent_size *= 2;
364 Renew(PL_reentrant_buffer->_getnetent_buffer,
365 PL_reentrant_buffer->_getnetent_size, char);
366 switch (PL_op->op_type) {
368 net = va_arg(ap, Netdb_net_t);
369 anint = va_arg(ap, int);
370 retptr = getnetbyaddr(net, anint); break;
372 p0 = va_arg(ap, void *);
373 retptr = getnetbyname(p0); break;
375 retptr = getnetent(); break;
383 #ifdef USE_GETPWENT_BUFFER
388 if (PL_reentrant_buffer->_getpwent_size <= REENTRANTHALFMAXSIZE) {
390 PL_reentrant_buffer->_getpwent_size *= 2;
391 Renew(PL_reentrant_buffer->_getpwent_buffer,
392 PL_reentrant_buffer->_getpwent_size, char);
393 switch (PL_op->op_type) {
395 p0 = va_arg(ap, void *);
396 retptr = getpwnam(p0); break;
398 uid = va_arg(ap, Uid_t);
399 retptr = getpwuid(uid); break;
401 retptr = getpwent(); break;
409 #ifdef USE_GETPROTOENT_BUFFER
414 if (PL_reentrant_buffer->_getprotoent_size <= REENTRANTHALFMAXSIZE) {
415 PL_reentrant_buffer->_getprotoent_size *= 2;
416 Renew(PL_reentrant_buffer->_getprotoent_buffer,
417 PL_reentrant_buffer->_getprotoent_size, char);
418 switch (PL_op->op_type) {
420 p0 = va_arg(ap, void *);
421 retptr = getprotobyname(p0); break;
423 anint = va_arg(ap, int);
424 retptr = getprotobynumber(anint); break;
426 retptr = getprotoent(); break;
434 #ifdef USE_GETSERVENT_BUFFER
439 if (PL_reentrant_buffer->_getservent_size <= REENTRANTHALFMAXSIZE) {
440 PL_reentrant_buffer->_getservent_size *= 2;
441 Renew(PL_reentrant_buffer->_getservent_buffer,
442 PL_reentrant_buffer->_getservent_size, char);
443 switch (PL_op->op_type) {
445 p0 = va_arg(ap, void *);
446 p1 = va_arg(ap, void *);
447 retptr = getservbyname(p0, p1); break;
449 anint = va_arg(ap, int);
450 p0 = va_arg(ap, void *);
451 retptr = getservbyport(anint, p0); break;
453 retptr = getservent(); break;
462 /* Not known how to retry, so just fail. */