1 /* -*- buffer-read-only: t -*-
5 * Copyright (C) 2002, 2003, 2005, 2006, 2007 by Larry Wall and others
7 * You may distribute under the terms of either the GNU General Public
8 * License or the Artistic License, as specified in the README file.
10 * !!!!!!! DO NOT EDIT THIS FILE !!!!!!!
11 * This file is built by reentr.pl from data in reentr.pl.
13 * "Saruman," I said, standing away from him, "only one hand at a time can
14 * wield the One, and you know that well, so do not trouble to say we!"
16 * This file contains a collection of automatically created wrappers
17 * (created by running reentr.pl) for reentrant (thread-safe) versions of
18 * various library calls, such as getpwent_r. The wrapping is done so
19 * that other files like pp_sys.c calling those library functions need not
20 * care about the differences between various platforms' idiosyncrasies
21 * regarding these reentrant interfaces.
25 #define PERL_IN_REENTR_C
30 Perl_reentrant_size(pTHX) {
31 #ifdef USE_REENTRANT_API
32 #define REENTRANTSMALLSIZE 256 /* Make something up. */
33 #define REENTRANTUSUALSIZE 4096 /* Make something up. */
35 PL_reentrant_buffer->_asctime_size = REENTRANTSMALLSIZE;
36 #endif /* HAS_ASCTIME_R */
38 #endif /* HAS_CRYPT_R */
40 PL_reentrant_buffer->_ctime_size = REENTRANTSMALLSIZE;
41 #endif /* HAS_CTIME_R */
43 #endif /* HAS_DRAND48_R */
45 # if defined(HAS_SYSCONF) && defined(_SC_GETGR_R_SIZE_MAX) && !defined(__GLIBC__)
46 PL_reentrant_buffer->_grent_size = sysconf(_SC_GETGR_R_SIZE_MAX);
47 if (PL_reentrant_buffer->_grent_size == (size_t) -1)
48 PL_reentrant_buffer->_grent_size = REENTRANTUSUALSIZE;
50 # if defined(__osf__) && defined(__alpha) && defined(SIABUFSIZ)
51 PL_reentrant_buffer->_grent_size = SIABUFSIZ;
54 PL_reentrant_buffer->_grent_size = BUFSIZ;
56 PL_reentrant_buffer->_grent_size = REENTRANTUSUALSIZE;
60 #endif /* HAS_GETGRNAM_R */
61 #ifdef HAS_GETHOSTBYNAME_R
62 #if !(GETHOSTBYNAME_R_PROTO == REENTRANT_PROTO_I_CSD)
63 PL_reentrant_buffer->_hostent_size = REENTRANTUSUALSIZE;
65 #endif /* HAS_GETHOSTBYNAME_R */
67 PL_reentrant_buffer->_getlogin_size = REENTRANTSMALLSIZE;
68 #endif /* HAS_GETLOGIN_R */
69 #ifdef HAS_GETNETBYNAME_R
70 #if !(GETNETBYNAME_R_PROTO == REENTRANT_PROTO_I_CSD)
71 PL_reentrant_buffer->_netent_size = REENTRANTUSUALSIZE;
73 #endif /* HAS_GETNETBYNAME_R */
74 #ifdef HAS_GETPROTOBYNAME_R
75 #if !(GETPROTOBYNAME_R_PROTO == REENTRANT_PROTO_I_CSD)
76 PL_reentrant_buffer->_protoent_size = REENTRANTUSUALSIZE;
78 #endif /* HAS_GETPROTOBYNAME_R */
80 # if defined(HAS_SYSCONF) && defined(_SC_GETPW_R_SIZE_MAX) && !defined(__GLIBC__)
81 PL_reentrant_buffer->_pwent_size = sysconf(_SC_GETPW_R_SIZE_MAX);
82 if (PL_reentrant_buffer->_pwent_size == (size_t) -1)
83 PL_reentrant_buffer->_pwent_size = REENTRANTUSUALSIZE;
85 # if defined(__osf__) && defined(__alpha) && defined(SIABUFSIZ)
86 PL_reentrant_buffer->_pwent_size = SIABUFSIZ;
89 PL_reentrant_buffer->_pwent_size = BUFSIZ;
91 PL_reentrant_buffer->_pwent_size = REENTRANTUSUALSIZE;
95 #endif /* HAS_GETPWNAM_R */
96 #ifdef HAS_GETSERVBYNAME_R
97 #if !(GETSERVBYNAME_R_PROTO == REENTRANT_PROTO_I_CCSD)
98 PL_reentrant_buffer->_servent_size = REENTRANTUSUALSIZE;
100 #endif /* HAS_GETSERVBYNAME_R */
101 #ifdef HAS_GETSPNAM_R
102 # if defined(HAS_SYSCONF) && defined(_SC_GETPW_R_SIZE_MAX) && !defined(__GLIBC__)
103 PL_reentrant_buffer->_spent_size = sysconf(_SC_GETPW_R_SIZE_MAX);
104 if (PL_reentrant_buffer->_spent_size == (size_t) -1)
105 PL_reentrant_buffer->_spent_size = REENTRANTUSUALSIZE;
107 # if defined(__osf__) && defined(__alpha) && defined(SIABUFSIZ)
108 PL_reentrant_buffer->_spent_size = SIABUFSIZ;
111 PL_reentrant_buffer->_spent_size = BUFSIZ;
113 PL_reentrant_buffer->_spent_size = REENTRANTUSUALSIZE;
117 #endif /* HAS_GETSPNAM_R */
119 #endif /* HAS_RANDOM_R */
121 /* This is the size Solaris recommends.
122 * (though we go static, should use pathconf() instead) */
123 PL_reentrant_buffer->_readdir_size = sizeof(struct dirent) + MAXPATHLEN + 1;
124 #endif /* HAS_READDIR_R */
125 #ifdef HAS_READDIR64_R
126 /* This is the size Solaris recommends.
127 * (though we go static, should use pathconf() instead) */
128 PL_reentrant_buffer->_readdir64_size = sizeof(struct dirent64) + MAXPATHLEN + 1;
129 #endif /* HAS_READDIR64_R */
130 #ifdef HAS_SETLOCALE_R
131 PL_reentrant_buffer->_setlocale_size = REENTRANTSMALLSIZE;
132 #endif /* HAS_SETLOCALE_R */
134 #endif /* HAS_SRANDOM_R */
135 #ifdef HAS_STRERROR_R
136 PL_reentrant_buffer->_strerror_size = REENTRANTSMALLSIZE;
137 #endif /* HAS_STRERROR_R */
139 PL_reentrant_buffer->_ttyname_size = REENTRANTSMALLSIZE;
140 #endif /* HAS_TTYNAME_R */
142 #endif /* USE_REENTRANT_API */
146 Perl_reentrant_init(pTHX) {
147 #ifdef USE_REENTRANT_API
148 Newx(PL_reentrant_buffer, 1, REENTR);
149 Perl_reentrant_size(aTHX);
151 Newx(PL_reentrant_buffer->_asctime_buffer, PL_reentrant_buffer->_asctime_size, char);
152 #endif /* HAS_ASCTIME_R */
154 #if CRYPT_R_PROTO != REENTRANT_PROTO_B_CCD
155 PL_reentrant_buffer->_crypt_struct_buffer = 0;
157 #endif /* HAS_CRYPT_R */
159 Newx(PL_reentrant_buffer->_ctime_buffer, PL_reentrant_buffer->_ctime_size, char);
160 #endif /* HAS_CTIME_R */
162 #endif /* HAS_DRAND48_R */
163 #ifdef HAS_GETGRNAM_R
164 # ifdef USE_GRENT_FPTR
165 PL_reentrant_buffer->_grent_fptr = NULL;
167 Newx(PL_reentrant_buffer->_grent_buffer, PL_reentrant_buffer->_grent_size, char);
168 #endif /* HAS_GETGRNAM_R */
169 #ifdef HAS_GETHOSTBYNAME_R
170 #if !(GETHOSTBYNAME_R_PROTO == REENTRANT_PROTO_I_CSD)
171 Newx(PL_reentrant_buffer->_hostent_buffer, PL_reentrant_buffer->_hostent_size, char);
173 #endif /* HAS_GETHOSTBYNAME_R */
174 #ifdef HAS_GETLOGIN_R
175 Newx(PL_reentrant_buffer->_getlogin_buffer, PL_reentrant_buffer->_getlogin_size, char);
176 #endif /* HAS_GETLOGIN_R */
177 #ifdef HAS_GETNETBYNAME_R
178 #if !(GETNETBYNAME_R_PROTO == REENTRANT_PROTO_I_CSD)
179 Newx(PL_reentrant_buffer->_netent_buffer, PL_reentrant_buffer->_netent_size, char);
181 #endif /* HAS_GETNETBYNAME_R */
182 #ifdef HAS_GETPROTOBYNAME_R
183 #if !(GETPROTOBYNAME_R_PROTO == REENTRANT_PROTO_I_CSD)
184 Newx(PL_reentrant_buffer->_protoent_buffer, PL_reentrant_buffer->_protoent_size, char);
186 #endif /* HAS_GETPROTOBYNAME_R */
187 #ifdef HAS_GETPWNAM_R
188 # ifdef USE_PWENT_FPTR
189 PL_reentrant_buffer->_pwent_fptr = NULL;
191 Newx(PL_reentrant_buffer->_pwent_buffer, PL_reentrant_buffer->_pwent_size, char);
192 #endif /* HAS_GETPWNAM_R */
193 #ifdef HAS_GETSERVBYNAME_R
194 #if !(GETSERVBYNAME_R_PROTO == REENTRANT_PROTO_I_CCSD)
195 Newx(PL_reentrant_buffer->_servent_buffer, PL_reentrant_buffer->_servent_size, char);
197 #endif /* HAS_GETSERVBYNAME_R */
198 #ifdef HAS_GETSPNAM_R
199 # ifdef USE_SPENT_FPTR
200 PL_reentrant_buffer->_spent_fptr = NULL;
202 Newx(PL_reentrant_buffer->_spent_buffer, PL_reentrant_buffer->_spent_size, char);
203 #endif /* HAS_GETSPNAM_R */
205 #endif /* HAS_RANDOM_R */
207 PL_reentrant_buffer->_readdir_struct = (struct dirent*)safemalloc(PL_reentrant_buffer->_readdir_size);
208 #endif /* HAS_READDIR_R */
209 #ifdef HAS_READDIR64_R
210 PL_reentrant_buffer->_readdir64_struct = (struct dirent64*)safemalloc(PL_reentrant_buffer->_readdir64_size);
211 #endif /* HAS_READDIR64_R */
212 #ifdef HAS_SETLOCALE_R
213 Newx(PL_reentrant_buffer->_setlocale_buffer, PL_reentrant_buffer->_setlocale_size, char);
214 #endif /* HAS_SETLOCALE_R */
216 #endif /* HAS_SRANDOM_R */
217 #ifdef HAS_STRERROR_R
218 Newx(PL_reentrant_buffer->_strerror_buffer, PL_reentrant_buffer->_strerror_size, char);
219 #endif /* HAS_STRERROR_R */
221 Newx(PL_reentrant_buffer->_ttyname_buffer, PL_reentrant_buffer->_ttyname_size, char);
222 #endif /* HAS_TTYNAME_R */
224 #endif /* USE_REENTRANT_API */
228 Perl_reentrant_free(pTHX) {
229 #ifdef USE_REENTRANT_API
231 Safefree(PL_reentrant_buffer->_asctime_buffer);
232 #endif /* HAS_ASCTIME_R */
234 #if CRYPT_R_PROTO != REENTRANT_PROTO_B_CCD
235 Safefree(PL_reentrant_buffer->_crypt_struct_buffer);
237 #endif /* HAS_CRYPT_R */
239 Safefree(PL_reentrant_buffer->_ctime_buffer);
240 #endif /* HAS_CTIME_R */
242 #endif /* HAS_DRAND48_R */
243 #ifdef HAS_GETGRNAM_R
244 Safefree(PL_reentrant_buffer->_grent_buffer);
245 #endif /* HAS_GETGRNAM_R */
246 #ifdef HAS_GETHOSTBYNAME_R
247 #if !(GETHOSTBYNAME_R_PROTO == REENTRANT_PROTO_I_CSD)
248 Safefree(PL_reentrant_buffer->_hostent_buffer);
250 #endif /* HAS_GETHOSTBYNAME_R */
251 #ifdef HAS_GETLOGIN_R
252 Safefree(PL_reentrant_buffer->_getlogin_buffer);
253 #endif /* HAS_GETLOGIN_R */
254 #ifdef HAS_GETNETBYNAME_R
255 #if !(GETNETBYNAME_R_PROTO == REENTRANT_PROTO_I_CSD)
256 Safefree(PL_reentrant_buffer->_netent_buffer);
258 #endif /* HAS_GETNETBYNAME_R */
259 #ifdef HAS_GETPROTOBYNAME_R
260 #if !(GETPROTOBYNAME_R_PROTO == REENTRANT_PROTO_I_CSD)
261 Safefree(PL_reentrant_buffer->_protoent_buffer);
263 #endif /* HAS_GETPROTOBYNAME_R */
264 #ifdef HAS_GETPWNAM_R
265 Safefree(PL_reentrant_buffer->_pwent_buffer);
266 #endif /* HAS_GETPWNAM_R */
267 #ifdef HAS_GETSERVBYNAME_R
268 #if !(GETSERVBYNAME_R_PROTO == REENTRANT_PROTO_I_CCSD)
269 Safefree(PL_reentrant_buffer->_servent_buffer);
271 #endif /* HAS_GETSERVBYNAME_R */
272 #ifdef HAS_GETSPNAM_R
273 Safefree(PL_reentrant_buffer->_spent_buffer);
274 #endif /* HAS_GETSPNAM_R */
276 #endif /* HAS_RANDOM_R */
278 Safefree(PL_reentrant_buffer->_readdir_struct);
279 #endif /* HAS_READDIR_R */
280 #ifdef HAS_READDIR64_R
281 Safefree(PL_reentrant_buffer->_readdir64_struct);
282 #endif /* HAS_READDIR64_R */
283 #ifdef HAS_SETLOCALE_R
284 Safefree(PL_reentrant_buffer->_setlocale_buffer);
285 #endif /* HAS_SETLOCALE_R */
287 #endif /* HAS_SRANDOM_R */
288 #ifdef HAS_STRERROR_R
289 Safefree(PL_reentrant_buffer->_strerror_buffer);
290 #endif /* HAS_STRERROR_R */
292 Safefree(PL_reentrant_buffer->_ttyname_buffer);
293 #endif /* HAS_TTYNAME_R */
295 Safefree(PL_reentrant_buffer);
296 #endif /* USE_REENTRANT_API */
300 Perl_reentrant_retry(const char *f, ...)
305 #ifdef USE_REENTRANT_API
306 /* Easier to special case this here than in embed.pl. (Look at what it
307 generates for proto.h) */
308 PERL_ARGS_ASSERT_REENTRANT_RETRY;
312 #ifdef USE_REENTRANT_API
313 # 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)
316 # if defined(USE_SERVENT_BUFFER)
319 # if defined(USE_HOSTENT_BUFFER)
322 # 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((char *)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((char *)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((char *)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((char *)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((char *)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((char *)p0, (char *)p1); break;
510 anint = va_arg(ap, int);
511 p0 = va_arg(ap, void *);
512 retptr = getservbyport(anint, (char *)p0); break;
514 retptr = getservent(); break;
516 SETERRNO(ERANGE, LIB_INVARG);
524 /* Not known how to retry, so just fail. */