This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
MANIFEST: Add ext/POSIX/t/iv_const.t
[perl5.git] / reentr.c
CommitLineData
37442d52
RGS
1/* -*- buffer-read-only: t -*-
2 *
10bc17b6
JH
3 * reentr.c
4 *
922adc66 5 * Copyright (C) 2002, 2003, 2005, 2006, 2007 by Larry Wall and others
10bc17b6
JH
6 *
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.
9 *
78102347
NC
10 * !!!!!!! DO NOT EDIT THIS FILE !!!!!!!
11 * This file is built by regen/reentr.pl from data in regen/reentr.pl.
12 * Any changes made here will be lost!
23ce015e
JH
13 */
14
15/*
10bc17b6
JH
16 * "Saruman," I said, standing away from him, "only one hand at a time can
17 * wield the One, and you know that well, so do not trouble to say we!"
18 *
23ce015e
JH
19 * [p.260 of _The Lord of the Rings_, II/ii: "The Council of Elrond"]
20 */
21
22/*
61296642
DM
23 * This file contains a collection of automatically created wrappers
24 * (created by running reentr.pl) for reentrant (thread-safe) versions of
25 * various library calls, such as getpwent_r. The wrapping is done so
26 * that other files like pp_sys.c calling those library functions need not
27 * care about the differences between various platforms' idiosyncrasies
7c1815b7 28 * regarding these reentrant interfaces.
10bc17b6
JH
29 */
30
31#include "EXTERN.h"
32#define PERL_IN_REENTR_C
33#include "perl.h"
34#include "reentr.h"
5f478816 35#include "keywords.h"
10bc17b6 36
acfc2cc3
HS
37#define RenewDouble(data_pointer, size_pointer, type) \
38 STMT_START { \
981fbfc1 39 const size_t size = MAX(*(size_pointer), 1) * 2; \
acfc2cc3
HS
40 Renew((data_pointer), (size), type); \
41 *(size_pointer) = size; \
42 } STMT_END
43
10bc17b6
JH
44void
45Perl_reentrant_size(pTHX) {
23491f1d 46 PERL_UNUSED_CONTEXT;
0917d9b3
KW
47
48 /* Set the sizes of the reentrant buffers */
49
10bc17b6 50#ifdef USE_REENTRANT_API
7c1815b7
KW
51# define REENTRANTSMALLSIZE 256 /* Make something up. */
52# define REENTRANTUSUALSIZE 4096 /* Make something up. */
53
54# ifdef HAS_ASCTIME_R
81169c06 55 PL_reentrant_buffer->_asctime_size = 26;
7c1815b7
KW
56# endif /* HAS_ASCTIME_R */
57
58# ifdef HAS_CRYPT_R
59# endif /* HAS_CRYPT_R */
60
61# ifdef HAS_CTIME_R
81169c06 62 PL_reentrant_buffer->_ctime_size = 26;
7c1815b7
KW
63# endif /* HAS_CTIME_R */
64
65# ifdef HAS_GETGRNAM_R
66# if defined(HAS_SYSCONF) && defined(_SC_GETGR_R_SIZE_MAX) && !defined(__GLIBC__)
0de8cad8 67 PL_reentrant_buffer->_grent_size = sysconf(_SC_GETGR_R_SIZE_MAX);
a3dd3f83 68 if (PL_reentrant_buffer->_grent_size == (size_t) -1)
0de8cad8 69 PL_reentrant_buffer->_grent_size = REENTRANTUSUALSIZE;
7c1815b7 70# elif defined(__osf__) && defined(__alpha) && defined(SIABUFSIZ)
f7937171 71 PL_reentrant_buffer->_grent_size = SIABUFSIZ;
7c1815b7 72# elif defined(__sgi)
f7937171 73 PL_reentrant_buffer->_grent_size = BUFSIZ;
7c1815b7 74# else
f7937171 75 PL_reentrant_buffer->_grent_size = REENTRANTUSUALSIZE;
7c1815b7
KW
76# endif
77# endif /* HAS_GETGRNAM_R */
78
79# ifdef HAS_GETHOSTBYNAME_R
80# if !(GETHOSTBYNAME_R_PROTO == REENTRANT_PROTO_I_CSD)
f7937171 81 PL_reentrant_buffer->_hostent_size = REENTRANTUSUALSIZE;
7c1815b7
KW
82# endif
83# endif /* HAS_GETHOSTBYNAME_R */
84
85# ifdef HAS_GETLOGIN_R
8695fa85 86 PL_reentrant_buffer->_getlogin_size = REENTRANTSMALLSIZE;
7c1815b7
KW
87# endif /* HAS_GETLOGIN_R */
88
89# ifdef HAS_GETNETBYNAME_R
90# if !(GETNETBYNAME_R_PROTO == REENTRANT_PROTO_I_CSD)
f7937171 91 PL_reentrant_buffer->_netent_size = REENTRANTUSUALSIZE;
7c1815b7
KW
92# endif
93# endif /* HAS_GETNETBYNAME_R */
94
95# ifdef HAS_GETPROTOBYNAME_R
96# if !(GETPROTOBYNAME_R_PROTO == REENTRANT_PROTO_I_CSD)
f7937171 97 PL_reentrant_buffer->_protoent_size = REENTRANTUSUALSIZE;
7c1815b7
KW
98# endif
99# endif /* HAS_GETPROTOBYNAME_R */
100
101# ifdef HAS_GETPWNAM_R
102# if defined(HAS_SYSCONF) && defined(_SC_GETPW_R_SIZE_MAX) && !defined(__GLIBC__)
f7937171 103 PL_reentrant_buffer->_pwent_size = sysconf(_SC_GETPW_R_SIZE_MAX);
a3dd3f83 104 if (PL_reentrant_buffer->_pwent_size == (size_t) -1)
f7937171 105 PL_reentrant_buffer->_pwent_size = REENTRANTUSUALSIZE;
7c1815b7 106# elif defined(__osf__) && defined(__alpha) && defined(SIABUFSIZ)
f7937171 107 PL_reentrant_buffer->_pwent_size = SIABUFSIZ;
7c1815b7 108# elif defined(__sgi)
f7937171 109 PL_reentrant_buffer->_pwent_size = BUFSIZ;
7c1815b7 110# else
f7937171 111 PL_reentrant_buffer->_pwent_size = REENTRANTUSUALSIZE;
7c1815b7
KW
112# endif
113# endif /* HAS_GETPWNAM_R */
114
115# ifdef HAS_GETSERVBYNAME_R
116# if !(GETSERVBYNAME_R_PROTO == REENTRANT_PROTO_I_CCSD)
f7937171 117 PL_reentrant_buffer->_servent_size = REENTRANTUSUALSIZE;
7c1815b7
KW
118# endif
119# endif /* HAS_GETSERVBYNAME_R */
120
121# ifdef HAS_GETSPNAM_R
122# if defined(HAS_SYSCONF) && defined(_SC_GETPW_R_SIZE_MAX) && !defined(__GLIBC__)
f7937171 123 PL_reentrant_buffer->_spent_size = sysconf(_SC_GETPW_R_SIZE_MAX);
a3dd3f83 124 if (PL_reentrant_buffer->_spent_size == (size_t) -1)
0de8cad8 125 PL_reentrant_buffer->_spent_size = REENTRANTUSUALSIZE;
7c1815b7 126# elif defined(__osf__) && defined(__alpha) && defined(SIABUFSIZ)
f7937171 127 PL_reentrant_buffer->_spent_size = SIABUFSIZ;
7c1815b7 128# elif defined(__sgi)
f7937171 129 PL_reentrant_buffer->_spent_size = BUFSIZ;
7c1815b7 130# else
f7937171 131 PL_reentrant_buffer->_spent_size = REENTRANTUSUALSIZE;
7c1815b7
KW
132# endif
133# endif /* HAS_GETSPNAM_R */
134
e63f5cd5
KW
135# ifdef HAS_GMTIME_R
136# endif /* HAS_GMTIME_R */
137
138# ifdef HAS_LOCALTIME_R
139# endif /* HAS_LOCALTIME_R */
140
7c1815b7 141# ifdef HAS_READDIR_R
10bc17b6
JH
142 /* This is the size Solaris recommends.
143 * (though we go static, should use pathconf() instead) */
144 PL_reentrant_buffer->_readdir_size = sizeof(struct dirent) + MAXPATHLEN + 1;
7c1815b7
KW
145# endif /* HAS_READDIR_R */
146
147# ifdef HAS_READDIR64_R
10bc17b6
JH
148 /* This is the size Solaris recommends.
149 * (though we go static, should use pathconf() instead) */
150 PL_reentrant_buffer->_readdir64_size = sizeof(struct dirent64) + MAXPATHLEN + 1;
7c1815b7
KW
151# endif /* HAS_READDIR64_R */
152
153# ifdef HAS_SETLOCALE_R
8695fa85 154 PL_reentrant_buffer->_setlocale_size = REENTRANTSMALLSIZE;
7c1815b7
KW
155# endif /* HAS_SETLOCALE_R */
156
157# ifdef HAS_STRERROR_R
8695fa85 158 PL_reentrant_buffer->_strerror_size = REENTRANTSMALLSIZE;
7c1815b7
KW
159# endif /* HAS_STRERROR_R */
160
161# ifdef HAS_TTYNAME_R
8695fa85 162 PL_reentrant_buffer->_ttyname_size = REENTRANTSMALLSIZE;
7c1815b7
KW
163# endif /* HAS_TTYNAME_R */
164
10bc17b6
JH
165
166#endif /* USE_REENTRANT_API */
7c1815b7 167
10bc17b6
JH
168}
169
170void
171Perl_reentrant_init(pTHX) {
23491f1d 172 PERL_UNUSED_CONTEXT;
0917d9b3
KW
173
174 /* Initialize the whole thing */
175
10bc17b6 176#ifdef USE_REENTRANT_API
7c1815b7 177
a02a5408 178 Newx(PL_reentrant_buffer, 1, REENTR);
10bc17b6 179 Perl_reentrant_size(aTHX);
7c1815b7
KW
180
181# ifdef HAS_ASCTIME_R
a02a5408 182 Newx(PL_reentrant_buffer->_asctime_buffer, PL_reentrant_buffer->_asctime_size, char);
7c1815b7
KW
183# endif /* HAS_ASCTIME_R */
184
185# ifdef HAS_CRYPT_R
186# if CRYPT_R_PROTO != REENTRANT_PROTO_B_CCD
05404ffe 187 PL_reentrant_buffer->_crypt_struct_buffer = 0;
7c1815b7
KW
188# endif
189# endif /* HAS_CRYPT_R */
190
191# ifdef HAS_CTIME_R
a02a5408 192 Newx(PL_reentrant_buffer->_ctime_buffer, PL_reentrant_buffer->_ctime_size, char);
7c1815b7
KW
193# endif /* HAS_CTIME_R */
194
195# ifdef HAS_GETGRNAM_R
f7937171
JH
196# ifdef USE_GRENT_FPTR
197 PL_reentrant_buffer->_grent_fptr = NULL;
10bc17b6 198# endif
a02a5408 199 Newx(PL_reentrant_buffer->_grent_buffer, PL_reentrant_buffer->_grent_size, char);
7c1815b7
KW
200# endif /* HAS_GETGRNAM_R */
201
202# ifdef HAS_GETHOSTBYNAME_R
203# if !(GETHOSTBYNAME_R_PROTO == REENTRANT_PROTO_I_CSD)
a02a5408 204 Newx(PL_reentrant_buffer->_hostent_buffer, PL_reentrant_buffer->_hostent_size, char);
7c1815b7
KW
205# endif
206# endif /* HAS_GETHOSTBYNAME_R */
207
208# ifdef HAS_GETLOGIN_R
a02a5408 209 Newx(PL_reentrant_buffer->_getlogin_buffer, PL_reentrant_buffer->_getlogin_size, char);
7c1815b7
KW
210# endif /* HAS_GETLOGIN_R */
211
212# ifdef HAS_GETNETBYNAME_R
213# if !(GETNETBYNAME_R_PROTO == REENTRANT_PROTO_I_CSD)
a02a5408 214 Newx(PL_reentrant_buffer->_netent_buffer, PL_reentrant_buffer->_netent_size, char);
7c1815b7
KW
215# endif
216# endif /* HAS_GETNETBYNAME_R */
217
218# ifdef HAS_GETPROTOBYNAME_R
219# if !(GETPROTOBYNAME_R_PROTO == REENTRANT_PROTO_I_CSD)
a02a5408 220 Newx(PL_reentrant_buffer->_protoent_buffer, PL_reentrant_buffer->_protoent_size, char);
7c1815b7
KW
221# endif
222# endif /* HAS_GETPROTOBYNAME_R */
223
224# ifdef HAS_GETPWNAM_R
f7937171
JH
225# ifdef USE_PWENT_FPTR
226 PL_reentrant_buffer->_pwent_fptr = NULL;
10bc17b6 227# endif
a02a5408 228 Newx(PL_reentrant_buffer->_pwent_buffer, PL_reentrant_buffer->_pwent_size, char);
7c1815b7
KW
229# endif /* HAS_GETPWNAM_R */
230
231# ifdef HAS_GETSERVBYNAME_R
232# if !(GETSERVBYNAME_R_PROTO == REENTRANT_PROTO_I_CCSD)
a02a5408 233 Newx(PL_reentrant_buffer->_servent_buffer, PL_reentrant_buffer->_servent_size, char);
7c1815b7
KW
234# endif
235# endif /* HAS_GETSERVBYNAME_R */
236
237# ifdef HAS_GETSPNAM_R
f7937171
JH
238# ifdef USE_SPENT_FPTR
239 PL_reentrant_buffer->_spent_fptr = NULL;
240# endif
a02a5408 241 Newx(PL_reentrant_buffer->_spent_buffer, PL_reentrant_buffer->_spent_size, char);
7c1815b7
KW
242# endif /* HAS_GETSPNAM_R */
243
e63f5cd5
KW
244# ifdef HAS_GMTIME_R
245# endif /* HAS_GMTIME_R */
246
247# ifdef HAS_LOCALTIME_R
248# endif /* HAS_LOCALTIME_R */
249
7c1815b7 250# ifdef HAS_READDIR_R
10bc17b6 251 PL_reentrant_buffer->_readdir_struct = (struct dirent*)safemalloc(PL_reentrant_buffer->_readdir_size);
7c1815b7
KW
252# endif /* HAS_READDIR_R */
253
254# ifdef HAS_READDIR64_R
10bc17b6 255 PL_reentrant_buffer->_readdir64_struct = (struct dirent64*)safemalloc(PL_reentrant_buffer->_readdir64_size);
7c1815b7
KW
256# endif /* HAS_READDIR64_R */
257
258# ifdef HAS_SETLOCALE_R
a02a5408 259 Newx(PL_reentrant_buffer->_setlocale_buffer, PL_reentrant_buffer->_setlocale_size, char);
7c1815b7
KW
260# endif /* HAS_SETLOCALE_R */
261
262# ifdef HAS_STRERROR_R
a02a5408 263 Newx(PL_reentrant_buffer->_strerror_buffer, PL_reentrant_buffer->_strerror_size, char);
7c1815b7
KW
264# endif /* HAS_STRERROR_R */
265
266# ifdef HAS_TTYNAME_R
a02a5408 267 Newx(PL_reentrant_buffer->_ttyname_buffer, PL_reentrant_buffer->_ttyname_size, char);
7c1815b7
KW
268# endif /* HAS_TTYNAME_R */
269
10bc17b6
JH
270
271#endif /* USE_REENTRANT_API */
7c1815b7 272
10bc17b6
JH
273}
274
275void
276Perl_reentrant_free(pTHX) {
23491f1d 277 PERL_UNUSED_CONTEXT;
0917d9b3
KW
278
279 /* Tear down */
280
10bc17b6 281#ifdef USE_REENTRANT_API
7c1815b7
KW
282
283# ifdef HAS_ASCTIME_R
10bc17b6 284 Safefree(PL_reentrant_buffer->_asctime_buffer);
7c1815b7
KW
285# endif /* HAS_ASCTIME_R */
286
287# ifdef HAS_CRYPT_R
288# if CRYPT_R_PROTO != REENTRANT_PROTO_B_CCD
05404ffe 289 Safefree(PL_reentrant_buffer->_crypt_struct_buffer);
7c1815b7
KW
290# endif
291# endif /* HAS_CRYPT_R */
292
293# ifdef HAS_CTIME_R
10bc17b6 294 Safefree(PL_reentrant_buffer->_ctime_buffer);
7c1815b7
KW
295# endif /* HAS_CTIME_R */
296
297# ifdef HAS_GETGRNAM_R
f7937171 298 Safefree(PL_reentrant_buffer->_grent_buffer);
7c1815b7
KW
299# endif /* HAS_GETGRNAM_R */
300
301# ifdef HAS_GETHOSTBYNAME_R
302# if !(GETHOSTBYNAME_R_PROTO == REENTRANT_PROTO_I_CSD)
f7937171 303 Safefree(PL_reentrant_buffer->_hostent_buffer);
7c1815b7
KW
304# endif
305# endif /* HAS_GETHOSTBYNAME_R */
306
307# ifdef HAS_GETLOGIN_R
10bc17b6 308 Safefree(PL_reentrant_buffer->_getlogin_buffer);
7c1815b7
KW
309# endif /* HAS_GETLOGIN_R */
310
311# ifdef HAS_GETNETBYNAME_R
312# if !(GETNETBYNAME_R_PROTO == REENTRANT_PROTO_I_CSD)
f7937171 313 Safefree(PL_reentrant_buffer->_netent_buffer);
7c1815b7
KW
314# endif
315# endif /* HAS_GETNETBYNAME_R */
316
317# ifdef HAS_GETPROTOBYNAME_R
318# if !(GETPROTOBYNAME_R_PROTO == REENTRANT_PROTO_I_CSD)
f7937171 319 Safefree(PL_reentrant_buffer->_protoent_buffer);
7c1815b7
KW
320# endif
321# endif /* HAS_GETPROTOBYNAME_R */
322
323# ifdef HAS_GETPWNAM_R
f7937171 324 Safefree(PL_reentrant_buffer->_pwent_buffer);
7c1815b7
KW
325# endif /* HAS_GETPWNAM_R */
326
327# ifdef HAS_GETSERVBYNAME_R
328# if !(GETSERVBYNAME_R_PROTO == REENTRANT_PROTO_I_CCSD)
f7937171 329 Safefree(PL_reentrant_buffer->_servent_buffer);
7c1815b7
KW
330# endif
331# endif /* HAS_GETSERVBYNAME_R */
332
333# ifdef HAS_GETSPNAM_R
f7937171 334 Safefree(PL_reentrant_buffer->_spent_buffer);
7c1815b7
KW
335# endif /* HAS_GETSPNAM_R */
336
e63f5cd5
KW
337# ifdef HAS_GMTIME_R
338# endif /* HAS_GMTIME_R */
339
340# ifdef HAS_LOCALTIME_R
341# endif /* HAS_LOCALTIME_R */
342
7c1815b7 343# ifdef HAS_READDIR_R
10bc17b6 344 Safefree(PL_reentrant_buffer->_readdir_struct);
7c1815b7
KW
345# endif /* HAS_READDIR_R */
346
347# ifdef HAS_READDIR64_R
10bc17b6 348 Safefree(PL_reentrant_buffer->_readdir64_struct);
7c1815b7
KW
349# endif /* HAS_READDIR64_R */
350
351# ifdef HAS_SETLOCALE_R
10bc17b6 352 Safefree(PL_reentrant_buffer->_setlocale_buffer);
7c1815b7
KW
353# endif /* HAS_SETLOCALE_R */
354
355# ifdef HAS_STRERROR_R
10bc17b6 356 Safefree(PL_reentrant_buffer->_strerror_buffer);
7c1815b7
KW
357# endif /* HAS_STRERROR_R */
358
359# ifdef HAS_TTYNAME_R
10bc17b6 360 Safefree(PL_reentrant_buffer->_ttyname_buffer);
7c1815b7
KW
361# endif /* HAS_TTYNAME_R */
362
10bc17b6
JH
363
364 Safefree(PL_reentrant_buffer);
7c1815b7 365
10bc17b6
JH
366#endif /* USE_REENTRANT_API */
367}
368
edd309b7
JH
369void*
370Perl_reentrant_retry(const char *f, ...)
371{
0917d9b3
KW
372 /* This function is set up to be called if the normal function returns
373 * failure with errno ERANGE, which indicates the buffer is too small.
374 * This function calls the failing one again with a larger buffer.
375 *
376 * What has happened is that, due to the magic of C preprocessor macro
377 * expansion, when the original code called function 'foo(args)', it was
378 * instead compiled into something like a call of 'foo_r(args, buffer)'
379 * Below we retry with 'foo', but the preprocessor has changed that into
380 * 'foo_r', so this function will end up calling itself recursively, each
381 * time with a larger buffer. If PERL_REENTRANT_MAXSIZE is defined, it
382 * won't increase beyond that, instead failing. */
383
edd309b7 384 void *retptr = NULL;
fe5bfecd 385 va_list ap;
7c1815b7 386
5f478816
KW
387 I32 key = 0;
388
7918f24d 389#ifdef USE_REENTRANT_API
7c1815b7 390
dbf7dff6 391 dTHX;
7c1815b7 392
5f478816
KW
393 key = Perl_keyword (aTHX_ f, strlen(f), FALSE /* not feature enabled */);
394
7918f24d
NC
395 /* Easier to special case this here than in embed.pl. (Look at what it
396 generates for proto.h) */
397 PERL_ARGS_ASSERT_REENTRANT_RETRY;
7c1815b7 398
7918f24d 399#endif
7c1815b7 400
5f478816 401 if (key == 0) {
5baa389e
KW
402
403#ifdef HAS_GETSPNAM_R
404
405 /* This is a #define as has no corresponding keyword */
406 if (strEQ(f, "getspnam")) {
407 key = KEY_getspnam;
408 }
409
410#endif
411
5f478816
KW
412 }
413 else if (key < 0) {
414 key = -key;
415 }
416
fe5bfecd 417 va_start(ap, f);
7c1815b7 418
edd309b7 419#ifdef USE_REENTRANT_API
edd309b7 420
5f478816 421 switch (key) {
7c1815b7
KW
422
423# ifdef USE_HOSTENT_BUFFER
424
5f478816
KW
425 case KEY_gethostbyaddr:
426 case KEY_gethostbyname:
427 case KEY_endhostent:
edd309b7 428 {
72761345
KW
429 char * host_addr;
430 Size_t asize;
431 char * host_name;
432 int anint;
7c1815b7
KW
433
434# ifdef PERL_REENTRANT_MAXSIZE
af685957
JH
435 if (PL_reentrant_buffer->_hostent_size <=
436 PERL_REENTRANT_MAXSIZE / 2)
7c1815b7 437# endif
72761345
KW
438 RenewDouble(PL_reentrant_buffer->_hostent_buffer,
439 &PL_reentrant_buffer->_hostent_size, char);
5f478816 440 switch (key) {
72761345
KW
441 case KEY_gethostbyaddr:
442 host_addr = va_arg(ap, char *);
443 asize = va_arg(ap, Size_t);
edd309b7 444 anint = va_arg(ap, int);
0425a59a 445 /* socklen_t is what Posix 2001 says this should be */
72761345 446 retptr = gethostbyaddr(host_addr, (socklen_t) asize, anint); break;
5f478816 447 case KEY_gethostbyname:
72761345
KW
448 host_name = va_arg(ap, char *);
449 retptr = gethostbyname(host_name); break;
5f478816 450 case KEY_endhostent:
edd309b7
JH
451 retptr = gethostent(); break;
452 default:
0de8cad8 453 SETERRNO(ERANGE, LIB_INVARG);
edd309b7 454 break;
edd309b7
JH
455 }
456 }
457 break;
7c1815b7
KW
458
459# endif
460# ifdef USE_GRENT_BUFFER
461
5f478816
KW
462 case KEY_getgrent:
463 case KEY_getgrgid:
464 case KEY_getgrnam:
edd309b7 465 {
72761345
KW
466 char * name;
467 Gid_t gid;
7c1815b7
KW
468
469# ifdef PERL_REENTRANT_MAXSIZE
af685957
JH
470 if (PL_reentrant_buffer->_grent_size <=
471 PERL_REENTRANT_MAXSIZE / 2)
7c1815b7 472# endif
7c1815b7
KW
473 RenewDouble(PL_reentrant_buffer->_grent_buffer,
474 &PL_reentrant_buffer->_grent_size, char);
5f478816 475 switch (key) {
72761345
KW
476 case KEY_getgrnam:
477 name = va_arg(ap, char *);
478 retptr = getgrnam(name); break;
5f478816 479 case KEY_getgrgid:
7c1815b7
KW
480# if Gid_t_size < INTSIZE
481 gid = (Gid_t)va_arg(ap, int);
482# else
edd309b7 483 gid = va_arg(ap, Gid_t);
7c1815b7 484# endif
edd309b7 485 retptr = getgrgid(gid); break;
5f478816 486 case KEY_getgrent:
edd309b7
JH
487 retptr = getgrent(); break;
488 default:
0de8cad8 489 SETERRNO(ERANGE, LIB_INVARG);
edd309b7 490 break;
edd309b7
JH
491 }
492 }
493 break;
7c1815b7
KW
494
495# endif
496# ifdef USE_NETENT_BUFFER
497
5f478816
KW
498 case KEY_getnetbyaddr:
499 case KEY_getnetbyname:
500 case KEY_getnetent:
edd309b7 501 {
72761345
KW
502 char * name;
503 Netdb_net_t net;
504 int anint;
7c1815b7
KW
505
506# ifdef PERL_REENTRANT_MAXSIZE
af685957
JH
507 if (PL_reentrant_buffer->_netent_size <=
508 PERL_REENTRANT_MAXSIZE / 2)
7c1815b7 509# endif
7c1815b7
KW
510 RenewDouble(PL_reentrant_buffer->_netent_buffer,
511 &PL_reentrant_buffer->_netent_size, char);
5f478816 512 switch (key) {
72761345
KW
513 case KEY_getnetbyaddr:
514 net = va_arg(ap, Netdb_net_t);
515 anint = va_arg(ap, int);
516 retptr = getnetbyaddr(net, anint); break;
517 case KEY_getnetbyname:
518 name = va_arg(ap, char *);
519 retptr = getnetbyname(name); break;
520 case KEY_getnetent:
521 retptr = getnetent(); break;
522 default:
523 SETERRNO(ERANGE, LIB_INVARG);
524 break;
525 }
edd309b7
JH
526 }
527 break;
7c1815b7
KW
528
529# endif
530# ifdef USE_PWENT_BUFFER
531
5baa389e
KW
532 case KEY_getpwnam:
533 case KEY_getpwuid:
534 case KEY_getpwent:
edd309b7 535 {
72761345
KW
536 Uid_t uid;
537 char * name;
7c1815b7
KW
538
539# ifdef PERL_REENTRANT_MAXSIZE
af685957
JH
540 if (PL_reentrant_buffer->_pwent_size <=
541 PERL_REENTRANT_MAXSIZE / 2)
7c1815b7
KW
542
543# endif
7c1815b7
KW
544 RenewDouble(PL_reentrant_buffer->_pwent_buffer,
545 &PL_reentrant_buffer->_pwent_size, char);
5f478816
KW
546 switch (key) {
547 case KEY_getpwnam:
72761345
KW
548 name = va_arg(ap, char *);
549 retptr = getpwnam(name); break;
5f478816 550 case KEY_getpwuid:
7c1815b7
KW
551
552# if Uid_t_size < INTSIZE
ab2b559b 553 uid = (Uid_t)va_arg(ap, int);
7c1815b7 554# else
edd309b7 555 uid = va_arg(ap, Uid_t);
7c1815b7 556# endif
edd309b7 557 retptr = getpwuid(uid); break;
7c1815b7
KW
558
559# if defined(HAS_GETPWENT) || defined(HAS_GETPWENT_R)
5f478816
KW
560
561 case KEY_getpwent:
edd309b7 562 retptr = getpwent(); break;
7c1815b7 563# endif
edd309b7 564 default:
0de8cad8 565 SETERRNO(ERANGE, LIB_INVARG);
edd309b7 566 break;
7c1815b7 567 }
edd309b7
JH
568 }
569 break;
7c1815b7
KW
570
571# endif
5baa389e
KW
572# ifdef USE_SPENT_BUFFER
573
574 case KEY_getspnam:
575 {
576 char * name;
577
578# ifdef PERL_REENTRANT_MAXSIZE
579 if (PL_reentrant_buffer->_spent_size <=
580 PERL_REENTRANT_MAXSIZE / 2)
581
582# endif
583 RenewDouble(PL_reentrant_buffer->_spent_buffer,
584 &PL_reentrant_buffer->_spent_size, char);
585 switch (key) {
586 case KEY_getspnam:
587 name = va_arg(ap, char *);
588 retptr = getspnam(name); break;
589 default:
590 SETERRNO(ERANGE, LIB_INVARG);
591 break;
592 }
593 }
594 break;
595
596# endif
7c1815b7
KW
597# ifdef USE_PROTOENT_BUFFER
598
5f478816
KW
599 case KEY_getprotobyname:
600 case KEY_getprotobynumber:
601 case KEY_getprotoent:
edd309b7 602 {
72761345
KW
603 char * name;
604 int anint;
7c1815b7
KW
605
606# ifdef PERL_REENTRANT_MAXSIZE
af685957
JH
607 if (PL_reentrant_buffer->_protoent_size <=
608 PERL_REENTRANT_MAXSIZE / 2)
7c1815b7 609# endif
7c1815b7
KW
610 RenewDouble(PL_reentrant_buffer->_protoent_buffer,
611 &PL_reentrant_buffer->_protoent_size, char);
5f478816
KW
612 switch (key) {
613 case KEY_getprotobyname:
72761345
KW
614 name = va_arg(ap, char *);
615 retptr = getprotobyname(name); break;
5f478816 616 case KEY_getprotobynumber:
edd309b7
JH
617 anint = va_arg(ap, int);
618 retptr = getprotobynumber(anint); break;
5f478816 619 case KEY_getprotoent:
edd309b7
JH
620 retptr = getprotoent(); break;
621 default:
0de8cad8 622 SETERRNO(ERANGE, LIB_INVARG);
edd309b7 623 break;
7c1815b7 624 }
edd309b7
JH
625 }
626 break;
7c1815b7
KW
627
628# endif
629# ifdef USE_SERVENT_BUFFER
630
5f478816
KW
631 case KEY_getservbyname:
632 case KEY_getservbyport:
633 case KEY_getservent:
edd309b7 634 {
72761345
KW
635 char * name;
636 char * proto;
637 int anint;
7c1815b7
KW
638
639# ifdef PERL_REENTRANT_MAXSIZE
af685957
JH
640 if (PL_reentrant_buffer->_servent_size <=
641 PERL_REENTRANT_MAXSIZE / 2)
7c1815b7 642# endif
7c1815b7
KW
643 RenewDouble(PL_reentrant_buffer->_servent_buffer,
644 &PL_reentrant_buffer->_servent_size, char);
5f478816
KW
645 switch (key) {
646 case KEY_getservbyname:
72761345
KW
647 name = va_arg(ap, char *);
648 proto = va_arg(ap, char *);
649 retptr = getservbyname(name, proto); break;
5f478816 650 case KEY_getservbyport:
edd309b7 651 anint = va_arg(ap, int);
72761345
KW
652 name = va_arg(ap, char *);
653 retptr = getservbyport(anint, name); break;
5f478816 654 case KEY_getservent:
edd309b7
JH
655 retptr = getservent(); break;
656 default:
0de8cad8 657 SETERRNO(ERANGE, LIB_INVARG);
edd309b7 658 break;
edd309b7
JH
659 }
660 }
661 break;
7c1815b7
KW
662
663# endif
664
edd309b7
JH
665 default:
666 /* Not known how to retry, so just fail. */
667 break;
668 }
7c1815b7 669
6148ee25 670#else
7c1815b7 671
6148ee25 672 PERL_UNUSED_ARG(f);
7c1815b7 673
edd309b7 674#endif
7c1815b7 675
fe5bfecd 676 va_end(ap);
edd309b7
JH
677 return retptr;
678}
679
37442d52 680/* ex: set ro: */