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
26 PL_reentrant_buffer->_asctime_size = 256; /* Make something up. */
27 #endif /* HAS_ASCTIME_R */
29 #endif /* HAS_CRYPT_R */
31 PL_reentrant_buffer->_ctime_size = 256; /* Make something up. */
32 #endif /* HAS_CTIME_R */
34 #endif /* HAS_DRAND48_R */
36 # if defined(HAS_SYSCONF) && defined(_SC_GETGR_R_SIZE_MAX) && !defined(__GLIBC__)
37 PL_reentrant_buffer->_getgrent_size = sysconf(_SC_GETGR_R_SIZE_MAX);
39 # if defined(__osf__) && defined(__alpha) && defined(SIABUFSIZ)
40 PL_reentrant_buffer->_getgrent_size = SIABUFSIZ;
43 PL_reentrant_buffer->_getgrent_size = BUFSIZ;
45 PL_reentrant_buffer->_getgrent_size = 256;
49 #endif /* HAS_GETGRNAM_R */
50 #ifdef HAS_GETHOSTBYNAME_R
51 #if !(GETHOSTBYNAME_R_PROTO == REENTRANT_PROTO_I_CSD)
52 PL_reentrant_buffer->_gethostent_size = 2048; /* Any better ideas? */
54 #endif /* HAS_GETHOSTBYNAME_R */
56 PL_reentrant_buffer->_getlogin_size = 256; /* Make something up. */
57 #endif /* HAS_GETLOGIN_R */
58 #ifdef HAS_GETNETBYNAME_R
59 #if !(GETNETBYNAME_R_PROTO == REENTRANT_PROTO_I_CSD)
60 PL_reentrant_buffer->_getnetent_size = 2048; /* Any better ideas? */
62 #endif /* HAS_GETNETBYNAME_R */
63 #ifdef HAS_GETPROTOBYNAME_R
64 #if !(GETPROTOBYNAME_R_PROTO == REENTRANT_PROTO_I_CSD)
65 PL_reentrant_buffer->_getprotoent_size = 2048; /* Any better ideas? */
67 #endif /* HAS_GETPROTOBYNAME_R */
69 # if defined(HAS_SYSCONF) && defined(_SC_GETPW_R_SIZE_MAX) && !defined(__GLIBC__)
70 PL_reentrant_buffer->_getpwent_size = sysconf(_SC_GETPW_R_SIZE_MAX);
72 # if defined(__osf__) && defined(__alpha) && defined(SIABUFSIZ)
73 PL_reentrant_buffer->_getpwent_size = SIABUFSIZ;
76 PL_reentrant_buffer->_getpwent_size = BUFSIZ;
78 PL_reentrant_buffer->_getpwent_size = 256;
82 #endif /* HAS_GETPWNAM_R */
83 #ifdef HAS_GETSERVBYNAME_R
84 #if !(GETSERVBYNAME_R_PROTO == REENTRANT_PROTO_I_CCSD)
85 PL_reentrant_buffer->_getservent_size = 2048; /* Any better ideas? */
87 #endif /* HAS_GETSERVBYNAME_R */
89 PL_reentrant_buffer->_getspent_size = 1024;
90 #endif /* HAS_GETSPNAM_R */
92 #endif /* HAS_GMTIME_R */
93 #ifdef HAS_LOCALTIME_R
94 #endif /* HAS_LOCALTIME_R */
96 #endif /* HAS_RANDOM_R */
98 /* This is the size Solaris recommends.
99 * (though we go static, should use pathconf() instead) */
100 PL_reentrant_buffer->_readdir_size = sizeof(struct dirent) + MAXPATHLEN + 1;
101 #endif /* HAS_READDIR_R */
102 #ifdef HAS_READDIR64_R
103 /* This is the size Solaris recommends.
104 * (though we go static, should use pathconf() instead) */
105 PL_reentrant_buffer->_readdir64_size = sizeof(struct dirent64) + MAXPATHLEN + 1;
106 #endif /* HAS_READDIR64_R */
107 #ifdef HAS_SETLOCALE_R
108 PL_reentrant_buffer->_setlocale_size = 256; /* Make something up. */
109 #endif /* HAS_SETLOCALE_R */
110 #ifdef HAS_STRERROR_R
111 PL_reentrant_buffer->_strerror_size = 256; /* Make something up. */
112 #endif /* HAS_STRERROR_R */
114 PL_reentrant_buffer->_ttyname_size = 256; /* Make something up. */
115 #endif /* HAS_TTYNAME_R */
117 #endif /* USE_REENTRANT_API */
121 Perl_reentrant_init(pTHX) {
122 #ifdef USE_REENTRANT_API
123 New(31337, PL_reentrant_buffer, 1, REENTR);
124 Perl_reentrant_size(aTHX);
126 New(31338, PL_reentrant_buffer->_asctime_buffer, PL_reentrant_buffer->_asctime_size, char);
127 #endif /* HAS_ASCTIME_R */
130 PL_reentrant_buffer->_crypt_struct.initialized = 0;
132 #endif /* HAS_CRYPT_R */
134 New(31338, PL_reentrant_buffer->_ctime_buffer, PL_reentrant_buffer->_ctime_size, char);
135 #endif /* HAS_CTIME_R */
137 #endif /* HAS_DRAND48_R */
138 #ifdef HAS_GETGRNAM_R
139 # ifdef USE_GETGRENT_FPTR
140 PL_reentrant_buffer->_getgrent_fptr = NULL;
142 New(31338, PL_reentrant_buffer->_getgrent_buffer, PL_reentrant_buffer->_getgrent_size, char);
143 #endif /* HAS_GETGRNAM_R */
144 #ifdef HAS_GETHOSTBYNAME_R
145 #if !(GETHOSTBYNAME_R_PROTO == REENTRANT_PROTO_I_CSD)
146 New(31338, PL_reentrant_buffer->_gethostent_buffer, PL_reentrant_buffer->_gethostent_size, char);
148 #endif /* HAS_GETHOSTBYNAME_R */
149 #ifdef HAS_GETLOGIN_R
150 New(31338, PL_reentrant_buffer->_getlogin_buffer, PL_reentrant_buffer->_getlogin_size, char);
151 #endif /* HAS_GETLOGIN_R */
152 #ifdef HAS_GETNETBYNAME_R
153 #if !(GETNETBYNAME_R_PROTO == REENTRANT_PROTO_I_CSD)
154 New(31338, PL_reentrant_buffer->_getnetent_buffer, PL_reentrant_buffer->_getnetent_size, char);
156 #endif /* HAS_GETNETBYNAME_R */
157 #ifdef HAS_GETPROTOBYNAME_R
158 #if !(GETPROTOBYNAME_R_PROTO == REENTRANT_PROTO_I_CSD)
159 New(31338, PL_reentrant_buffer->_getprotoent_buffer, PL_reentrant_buffer->_getprotoent_size, char);
161 #endif /* HAS_GETPROTOBYNAME_R */
162 #ifdef HAS_GETPWNAM_R
163 # ifdef USE_GETPWENT_FPTR
164 PL_reentrant_buffer->_getpwent_fptr = NULL;
166 New(31338, PL_reentrant_buffer->_getpwent_buffer, PL_reentrant_buffer->_getpwent_size, char);
167 #endif /* HAS_GETPWNAM_R */
168 #ifdef HAS_GETSERVBYNAME_R
169 #if !(GETSERVBYNAME_R_PROTO == REENTRANT_PROTO_I_CCSD)
170 New(31338, PL_reentrant_buffer->_getservent_buffer, PL_reentrant_buffer->_getservent_size, char);
172 #endif /* HAS_GETSERVBYNAME_R */
173 #ifdef HAS_GETSPNAM_R
174 New(31338, PL_reentrant_buffer->_getspent_buffer, PL_reentrant_buffer->_getspent_size, char);
175 #endif /* HAS_GETSPNAM_R */
177 #endif /* HAS_GMTIME_R */
178 #ifdef HAS_LOCALTIME_R
179 #endif /* HAS_LOCALTIME_R */
181 #endif /* HAS_RANDOM_R */
183 PL_reentrant_buffer->_readdir_struct = (struct dirent*)safemalloc(PL_reentrant_buffer->_readdir_size);
184 #endif /* HAS_READDIR_R */
185 #ifdef HAS_READDIR64_R
186 PL_reentrant_buffer->_readdir64_struct = (struct dirent64*)safemalloc(PL_reentrant_buffer->_readdir64_size);
187 #endif /* HAS_READDIR64_R */
188 #ifdef HAS_SETLOCALE_R
189 New(31338, PL_reentrant_buffer->_setlocale_buffer, PL_reentrant_buffer->_setlocale_size, char);
190 #endif /* HAS_SETLOCALE_R */
191 #ifdef HAS_STRERROR_R
192 New(31338, PL_reentrant_buffer->_strerror_buffer, PL_reentrant_buffer->_strerror_size, char);
193 #endif /* HAS_STRERROR_R */
195 New(31338, PL_reentrant_buffer->_ttyname_buffer, PL_reentrant_buffer->_ttyname_size, char);
196 #endif /* HAS_TTYNAME_R */
198 #endif /* USE_REENTRANT_API */
202 Perl_reentrant_free(pTHX) {
203 #ifdef USE_REENTRANT_API
205 Safefree(PL_reentrant_buffer->_asctime_buffer);
206 #endif /* HAS_ASCTIME_R */
208 #endif /* HAS_CRYPT_R */
210 Safefree(PL_reentrant_buffer->_ctime_buffer);
211 #endif /* HAS_CTIME_R */
213 #endif /* HAS_DRAND48_R */
214 #ifdef HAS_GETGRNAM_R
215 Safefree(PL_reentrant_buffer->_getgrent_buffer);
216 #endif /* HAS_GETGRNAM_R */
217 #ifdef HAS_GETHOSTBYNAME_R
218 #if !(GETHOSTBYNAME_R_PROTO == REENTRANT_PROTO_I_CSD)
219 Safefree(PL_reentrant_buffer->_gethostent_buffer);
221 #endif /* HAS_GETHOSTBYNAME_R */
222 #ifdef HAS_GETLOGIN_R
223 Safefree(PL_reentrant_buffer->_getlogin_buffer);
224 #endif /* HAS_GETLOGIN_R */
225 #ifdef HAS_GETNETBYNAME_R
226 #if !(GETNETBYNAME_R_PROTO == REENTRANT_PROTO_I_CSD)
227 Safefree(PL_reentrant_buffer->_getnetent_buffer);
229 #endif /* HAS_GETNETBYNAME_R */
230 #ifdef HAS_GETPROTOBYNAME_R
231 #if !(GETPROTOBYNAME_R_PROTO == REENTRANT_PROTO_I_CSD)
232 Safefree(PL_reentrant_buffer->_getprotoent_buffer);
234 #endif /* HAS_GETPROTOBYNAME_R */
235 #ifdef HAS_GETPWNAM_R
236 Safefree(PL_reentrant_buffer->_getpwent_buffer);
237 #endif /* HAS_GETPWNAM_R */
238 #ifdef HAS_GETSERVBYNAME_R
239 #if !(GETSERVBYNAME_R_PROTO == REENTRANT_PROTO_I_CCSD)
240 Safefree(PL_reentrant_buffer->_getservent_buffer);
242 #endif /* HAS_GETSERVBYNAME_R */
243 #ifdef HAS_GETSPNAM_R
244 Safefree(PL_reentrant_buffer->_getspent_buffer);
245 #endif /* HAS_GETSPNAM_R */
247 #endif /* HAS_GMTIME_R */
248 #ifdef HAS_LOCALTIME_R
249 #endif /* HAS_LOCALTIME_R */
251 #endif /* HAS_RANDOM_R */
253 Safefree(PL_reentrant_buffer->_readdir_struct);
254 #endif /* HAS_READDIR_R */
255 #ifdef HAS_READDIR64_R
256 Safefree(PL_reentrant_buffer->_readdir64_struct);
257 #endif /* HAS_READDIR64_R */
258 #ifdef HAS_SETLOCALE_R
259 Safefree(PL_reentrant_buffer->_setlocale_buffer);
260 #endif /* HAS_SETLOCALE_R */
261 #ifdef HAS_STRERROR_R
262 Safefree(PL_reentrant_buffer->_strerror_buffer);
263 #endif /* HAS_STRERROR_R */
265 Safefree(PL_reentrant_buffer->_ttyname_buffer);
266 #endif /* HAS_TTYNAME_R */
268 Safefree(PL_reentrant_buffer);
269 #endif /* USE_REENTRANT_API */
273 Perl_reentrant_retry(const char *f, ...)
277 #ifdef USE_REENTRANT_API
285 #define REENTRANTHALFMAXSIZE 32768 /* The maximum may end up twice this. */
287 switch (PL_op->op_type) {
288 #ifdef USE_GETHOSTENT_BUFFER
293 if (PL_reentrant_buffer->_gethostent_size <= REENTRANTHALFMAXSIZE) {
294 PL_reentrant_buffer->_gethostent_size *= 2;
295 Renew(PL_reentrant_buffer->_gethostent_buffer,
296 PL_reentrant_buffer->_gethostent_size, char);
297 switch (PL_op->op_type) {
299 p0 = va_arg(ap, void *);
300 asize = va_arg(ap, size_t);
301 anint = va_arg(ap, int);
302 retptr = gethostbyaddr(p0, asize, anint); break;
304 p0 = va_arg(ap, void *);
305 retptr = gethostbyname(p0); break;
307 retptr = gethostent(); break;
315 #ifdef USE_GETGRENT_BUFFER
320 if (PL_reentrant_buffer->_getgrent_size <= REENTRANTHALFMAXSIZE) {
322 PL_reentrant_buffer->_getgrent_size *= 2;
323 Renew(PL_reentrant_buffer->_getgrent_buffer,
324 PL_reentrant_buffer->_getgrent_size, char);
325 switch (PL_op->op_type) {
327 p0 = va_arg(ap, void *);
328 retptr = getgrnam(p0); break;
330 gid = va_arg(ap, Gid_t);
331 retptr = getgrgid(gid); break;
333 retptr = getgrent(); break;
341 #ifdef USE_GETNETENT_BUFFER
346 if (PL_reentrant_buffer->_getnetent_size <= REENTRANTHALFMAXSIZE) {
348 PL_reentrant_buffer->_getnetent_size *= 2;
349 Renew(PL_reentrant_buffer->_getnetent_buffer,
350 PL_reentrant_buffer->_getnetent_size, char);
351 switch (PL_op->op_type) {
353 net = va_arg(ap, Netdb_net_t);
354 anint = va_arg(ap, int);
355 retptr = getnetbyaddr(net, anint); break;
357 p0 = va_arg(ap, void *);
358 retptr = getnetbyname(p0); break;
360 retptr = getnetent(); break;
368 #ifdef USE_GETPWENT_BUFFER
373 if (PL_reentrant_buffer->_getpwent_size <= REENTRANTHALFMAXSIZE) {
375 PL_reentrant_buffer->_getpwent_size *= 2;
376 Renew(PL_reentrant_buffer->_getpwent_buffer,
377 PL_reentrant_buffer->_getpwent_size, char);
378 switch (PL_op->op_type) {
380 p0 = va_arg(ap, void *);
381 retptr = getpwnam(p0); break;
383 uid = va_arg(ap, Uid_t);
384 retptr = getpwuid(uid); break;
386 retptr = getpwent(); break;
394 #ifdef USE_GETPROTOENT_BUFFER
399 if (PL_reentrant_buffer->_getprotoent_size <= REENTRANTHALFMAXSIZE) {
400 PL_reentrant_buffer->_getprotoent_size *= 2;
401 Renew(PL_reentrant_buffer->_getprotoent_buffer,
402 PL_reentrant_buffer->_getprotoent_size, char);
403 switch (PL_op->op_type) {
405 p0 = va_arg(ap, void *);
406 retptr = getprotobyname(p0); break;
408 anint = va_arg(ap, int);
409 retptr = getprotobynumber(anint); break;
411 retptr = getprotoent(); break;
419 #ifdef USE_GETSERVENT_BUFFER
424 if (PL_reentrant_buffer->_getservent_size <= REENTRANTHALFMAXSIZE) {
425 PL_reentrant_buffer->_getservent_size *= 2;
426 Renew(PL_reentrant_buffer->_getservent_buffer,
427 PL_reentrant_buffer->_getservent_size, char);
428 switch (PL_op->op_type) {
430 p0 = va_arg(ap, void *);
431 p1 = va_arg(ap, void *);
432 retptr = getservbyname(p0, p1); break;
434 anint = va_arg(ap, int);
435 p0 = va_arg(ap, void *);
436 retptr = getservbyport(anint, p0); break;
438 retptr = getservent(); break;
447 /* Not known how to retry, so just fail. */