This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
regcomp.c: White-space only
[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
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"
35
acfc2cc3
HS
36#define RenewDouble(data_pointer, size_pointer, type) \
37 STMT_START { \
38 const size_t size = *(size_pointer) * 2; \
39 Renew((data_pointer), (size), type); \
40 *(size_pointer) = size; \
41 } STMT_END
42
10bc17b6
JH
43void
44Perl_reentrant_size(pTHX) {
23491f1d 45 PERL_UNUSED_CONTEXT;
10bc17b6 46#ifdef USE_REENTRANT_API
8695fa85
SR
47#define REENTRANTSMALLSIZE 256 /* Make something up. */
48#define REENTRANTUSUALSIZE 4096 /* Make something up. */
10bc17b6 49#ifdef HAS_ASCTIME_R
8695fa85 50 PL_reentrant_buffer->_asctime_size = REENTRANTSMALLSIZE;
10bc17b6
JH
51#endif /* HAS_ASCTIME_R */
52#ifdef HAS_CRYPT_R
53#endif /* HAS_CRYPT_R */
54#ifdef HAS_CTIME_R
8695fa85 55 PL_reentrant_buffer->_ctime_size = REENTRANTSMALLSIZE;
10bc17b6 56#endif /* HAS_CTIME_R */
10bc17b6 57#ifdef HAS_GETGRNAM_R
0de8cad8
RGS
58# if defined(HAS_SYSCONF) && defined(_SC_GETGR_R_SIZE_MAX) && !defined(__GLIBC__)
59 PL_reentrant_buffer->_grent_size = sysconf(_SC_GETGR_R_SIZE_MAX);
a3dd3f83 60 if (PL_reentrant_buffer->_grent_size == (size_t) -1)
0de8cad8 61 PL_reentrant_buffer->_grent_size = REENTRANTUSUALSIZE;
7ce6ba0f 62# elif defined(__osf__) && defined(__alpha) && defined(SIABUFSIZ)
f7937171 63 PL_reentrant_buffer->_grent_size = SIABUFSIZ;
7ce6ba0f 64# elif defined(__sgi)
f7937171 65 PL_reentrant_buffer->_grent_size = BUFSIZ;
7ce6ba0f 66# else
f7937171 67 PL_reentrant_buffer->_grent_size = REENTRANTUSUALSIZE;
10bc17b6
JH
68# endif
69#endif /* HAS_GETGRNAM_R */
70#ifdef HAS_GETHOSTBYNAME_R
71#if !(GETHOSTBYNAME_R_PROTO == REENTRANT_PROTO_I_CSD)
f7937171 72 PL_reentrant_buffer->_hostent_size = REENTRANTUSUALSIZE;
10bc17b6
JH
73#endif
74#endif /* HAS_GETHOSTBYNAME_R */
75#ifdef HAS_GETLOGIN_R
8695fa85 76 PL_reentrant_buffer->_getlogin_size = REENTRANTSMALLSIZE;
10bc17b6
JH
77#endif /* HAS_GETLOGIN_R */
78#ifdef HAS_GETNETBYNAME_R
79#if !(GETNETBYNAME_R_PROTO == REENTRANT_PROTO_I_CSD)
f7937171 80 PL_reentrant_buffer->_netent_size = REENTRANTUSUALSIZE;
10bc17b6
JH
81#endif
82#endif /* HAS_GETNETBYNAME_R */
83#ifdef HAS_GETPROTOBYNAME_R
84#if !(GETPROTOBYNAME_R_PROTO == REENTRANT_PROTO_I_CSD)
f7937171 85 PL_reentrant_buffer->_protoent_size = REENTRANTUSUALSIZE;
10bc17b6
JH
86#endif
87#endif /* HAS_GETPROTOBYNAME_R */
88#ifdef HAS_GETPWNAM_R
89# if defined(HAS_SYSCONF) && defined(_SC_GETPW_R_SIZE_MAX) && !defined(__GLIBC__)
f7937171 90 PL_reentrant_buffer->_pwent_size = sysconf(_SC_GETPW_R_SIZE_MAX);
a3dd3f83 91 if (PL_reentrant_buffer->_pwent_size == (size_t) -1)
f7937171 92 PL_reentrant_buffer->_pwent_size = REENTRANTUSUALSIZE;
7ce6ba0f 93# elif defined(__osf__) && defined(__alpha) && defined(SIABUFSIZ)
f7937171 94 PL_reentrant_buffer->_pwent_size = SIABUFSIZ;
7ce6ba0f 95# elif defined(__sgi)
f7937171 96 PL_reentrant_buffer->_pwent_size = BUFSIZ;
7ce6ba0f 97# else
f7937171 98 PL_reentrant_buffer->_pwent_size = REENTRANTUSUALSIZE;
10bc17b6
JH
99# endif
100#endif /* HAS_GETPWNAM_R */
101#ifdef HAS_GETSERVBYNAME_R
102#if !(GETSERVBYNAME_R_PROTO == REENTRANT_PROTO_I_CCSD)
f7937171 103 PL_reentrant_buffer->_servent_size = REENTRANTUSUALSIZE;
10bc17b6
JH
104#endif
105#endif /* HAS_GETSERVBYNAME_R */
106#ifdef HAS_GETSPNAM_R
f7937171
JH
107# if defined(HAS_SYSCONF) && defined(_SC_GETPW_R_SIZE_MAX) && !defined(__GLIBC__)
108 PL_reentrant_buffer->_spent_size = sysconf(_SC_GETPW_R_SIZE_MAX);
a3dd3f83 109 if (PL_reentrant_buffer->_spent_size == (size_t) -1)
0de8cad8 110 PL_reentrant_buffer->_spent_size = REENTRANTUSUALSIZE;
7ce6ba0f 111# elif defined(__osf__) && defined(__alpha) && defined(SIABUFSIZ)
f7937171 112 PL_reentrant_buffer->_spent_size = SIABUFSIZ;
7ce6ba0f 113# elif defined(__sgi)
f7937171 114 PL_reentrant_buffer->_spent_size = BUFSIZ;
7ce6ba0f 115# else
f7937171 116 PL_reentrant_buffer->_spent_size = REENTRANTUSUALSIZE;
f7937171 117# endif
10bc17b6 118#endif /* HAS_GETSPNAM_R */
10bc17b6
JH
119#ifdef HAS_READDIR_R
120 /* This is the size Solaris recommends.
121 * (though we go static, should use pathconf() instead) */
122 PL_reentrant_buffer->_readdir_size = sizeof(struct dirent) + MAXPATHLEN + 1;
123#endif /* HAS_READDIR_R */
124#ifdef HAS_READDIR64_R
125 /* This is the size Solaris recommends.
126 * (though we go static, should use pathconf() instead) */
127 PL_reentrant_buffer->_readdir64_size = sizeof(struct dirent64) + MAXPATHLEN + 1;
128#endif /* HAS_READDIR64_R */
129#ifdef HAS_SETLOCALE_R
8695fa85 130 PL_reentrant_buffer->_setlocale_size = REENTRANTSMALLSIZE;
10bc17b6
JH
131#endif /* HAS_SETLOCALE_R */
132#ifdef HAS_STRERROR_R
8695fa85 133 PL_reentrant_buffer->_strerror_size = REENTRANTSMALLSIZE;
10bc17b6
JH
134#endif /* HAS_STRERROR_R */
135#ifdef HAS_TTYNAME_R
8695fa85 136 PL_reentrant_buffer->_ttyname_size = REENTRANTSMALLSIZE;
10bc17b6
JH
137#endif /* HAS_TTYNAME_R */
138
139#endif /* USE_REENTRANT_API */
140}
141
142void
143Perl_reentrant_init(pTHX) {
23491f1d 144 PERL_UNUSED_CONTEXT;
10bc17b6 145#ifdef USE_REENTRANT_API
a02a5408 146 Newx(PL_reentrant_buffer, 1, REENTR);
10bc17b6
JH
147 Perl_reentrant_size(aTHX);
148#ifdef HAS_ASCTIME_R
a02a5408 149 Newx(PL_reentrant_buffer->_asctime_buffer, PL_reentrant_buffer->_asctime_size, char);
10bc17b6
JH
150#endif /* HAS_ASCTIME_R */
151#ifdef HAS_CRYPT_R
05404ffe
JH
152#if CRYPT_R_PROTO != REENTRANT_PROTO_B_CCD
153 PL_reentrant_buffer->_crypt_struct_buffer = 0;
10bc17b6
JH
154#endif
155#endif /* HAS_CRYPT_R */
156#ifdef HAS_CTIME_R
a02a5408 157 Newx(PL_reentrant_buffer->_ctime_buffer, PL_reentrant_buffer->_ctime_size, char);
10bc17b6 158#endif /* HAS_CTIME_R */
10bc17b6 159#ifdef HAS_GETGRNAM_R
f7937171
JH
160# ifdef USE_GRENT_FPTR
161 PL_reentrant_buffer->_grent_fptr = NULL;
10bc17b6 162# endif
a02a5408 163 Newx(PL_reentrant_buffer->_grent_buffer, PL_reentrant_buffer->_grent_size, char);
10bc17b6
JH
164#endif /* HAS_GETGRNAM_R */
165#ifdef HAS_GETHOSTBYNAME_R
166#if !(GETHOSTBYNAME_R_PROTO == REENTRANT_PROTO_I_CSD)
a02a5408 167 Newx(PL_reentrant_buffer->_hostent_buffer, PL_reentrant_buffer->_hostent_size, char);
10bc17b6
JH
168#endif
169#endif /* HAS_GETHOSTBYNAME_R */
170#ifdef HAS_GETLOGIN_R
a02a5408 171 Newx(PL_reentrant_buffer->_getlogin_buffer, PL_reentrant_buffer->_getlogin_size, char);
10bc17b6
JH
172#endif /* HAS_GETLOGIN_R */
173#ifdef HAS_GETNETBYNAME_R
174#if !(GETNETBYNAME_R_PROTO == REENTRANT_PROTO_I_CSD)
a02a5408 175 Newx(PL_reentrant_buffer->_netent_buffer, PL_reentrant_buffer->_netent_size, char);
10bc17b6
JH
176#endif
177#endif /* HAS_GETNETBYNAME_R */
178#ifdef HAS_GETPROTOBYNAME_R
179#if !(GETPROTOBYNAME_R_PROTO == REENTRANT_PROTO_I_CSD)
a02a5408 180 Newx(PL_reentrant_buffer->_protoent_buffer, PL_reentrant_buffer->_protoent_size, char);
10bc17b6
JH
181#endif
182#endif /* HAS_GETPROTOBYNAME_R */
183#ifdef HAS_GETPWNAM_R
f7937171
JH
184# ifdef USE_PWENT_FPTR
185 PL_reentrant_buffer->_pwent_fptr = NULL;
10bc17b6 186# endif
a02a5408 187 Newx(PL_reentrant_buffer->_pwent_buffer, PL_reentrant_buffer->_pwent_size, char);
10bc17b6
JH
188#endif /* HAS_GETPWNAM_R */
189#ifdef HAS_GETSERVBYNAME_R
190#if !(GETSERVBYNAME_R_PROTO == REENTRANT_PROTO_I_CCSD)
a02a5408 191 Newx(PL_reentrant_buffer->_servent_buffer, PL_reentrant_buffer->_servent_size, char);
10bc17b6
JH
192#endif
193#endif /* HAS_GETSERVBYNAME_R */
194#ifdef HAS_GETSPNAM_R
f7937171
JH
195# ifdef USE_SPENT_FPTR
196 PL_reentrant_buffer->_spent_fptr = NULL;
197# endif
a02a5408 198 Newx(PL_reentrant_buffer->_spent_buffer, PL_reentrant_buffer->_spent_size, char);
10bc17b6 199#endif /* HAS_GETSPNAM_R */
10bc17b6
JH
200#ifdef HAS_READDIR_R
201 PL_reentrant_buffer->_readdir_struct = (struct dirent*)safemalloc(PL_reentrant_buffer->_readdir_size);
202#endif /* HAS_READDIR_R */
203#ifdef HAS_READDIR64_R
204 PL_reentrant_buffer->_readdir64_struct = (struct dirent64*)safemalloc(PL_reentrant_buffer->_readdir64_size);
205#endif /* HAS_READDIR64_R */
206#ifdef HAS_SETLOCALE_R
a02a5408 207 Newx(PL_reentrant_buffer->_setlocale_buffer, PL_reentrant_buffer->_setlocale_size, char);
10bc17b6
JH
208#endif /* HAS_SETLOCALE_R */
209#ifdef HAS_STRERROR_R
a02a5408 210 Newx(PL_reentrant_buffer->_strerror_buffer, PL_reentrant_buffer->_strerror_size, char);
10bc17b6
JH
211#endif /* HAS_STRERROR_R */
212#ifdef HAS_TTYNAME_R
a02a5408 213 Newx(PL_reentrant_buffer->_ttyname_buffer, PL_reentrant_buffer->_ttyname_size, char);
10bc17b6
JH
214#endif /* HAS_TTYNAME_R */
215
216#endif /* USE_REENTRANT_API */
217}
218
219void
220Perl_reentrant_free(pTHX) {
23491f1d 221 PERL_UNUSED_CONTEXT;
10bc17b6
JH
222#ifdef USE_REENTRANT_API
223#ifdef HAS_ASCTIME_R
224 Safefree(PL_reentrant_buffer->_asctime_buffer);
225#endif /* HAS_ASCTIME_R */
226#ifdef HAS_CRYPT_R
05404ffe
JH
227#if CRYPT_R_PROTO != REENTRANT_PROTO_B_CCD
228 Safefree(PL_reentrant_buffer->_crypt_struct_buffer);
229#endif
10bc17b6
JH
230#endif /* HAS_CRYPT_R */
231#ifdef HAS_CTIME_R
232 Safefree(PL_reentrant_buffer->_ctime_buffer);
233#endif /* HAS_CTIME_R */
10bc17b6 234#ifdef HAS_GETGRNAM_R
f7937171 235 Safefree(PL_reentrant_buffer->_grent_buffer);
10bc17b6
JH
236#endif /* HAS_GETGRNAM_R */
237#ifdef HAS_GETHOSTBYNAME_R
238#if !(GETHOSTBYNAME_R_PROTO == REENTRANT_PROTO_I_CSD)
f7937171 239 Safefree(PL_reentrant_buffer->_hostent_buffer);
10bc17b6
JH
240#endif
241#endif /* HAS_GETHOSTBYNAME_R */
242#ifdef HAS_GETLOGIN_R
243 Safefree(PL_reentrant_buffer->_getlogin_buffer);
244#endif /* HAS_GETLOGIN_R */
245#ifdef HAS_GETNETBYNAME_R
246#if !(GETNETBYNAME_R_PROTO == REENTRANT_PROTO_I_CSD)
f7937171 247 Safefree(PL_reentrant_buffer->_netent_buffer);
10bc17b6
JH
248#endif
249#endif /* HAS_GETNETBYNAME_R */
250#ifdef HAS_GETPROTOBYNAME_R
251#if !(GETPROTOBYNAME_R_PROTO == REENTRANT_PROTO_I_CSD)
f7937171 252 Safefree(PL_reentrant_buffer->_protoent_buffer);
10bc17b6
JH
253#endif
254#endif /* HAS_GETPROTOBYNAME_R */
255#ifdef HAS_GETPWNAM_R
f7937171 256 Safefree(PL_reentrant_buffer->_pwent_buffer);
10bc17b6
JH
257#endif /* HAS_GETPWNAM_R */
258#ifdef HAS_GETSERVBYNAME_R
259#if !(GETSERVBYNAME_R_PROTO == REENTRANT_PROTO_I_CCSD)
f7937171 260 Safefree(PL_reentrant_buffer->_servent_buffer);
10bc17b6
JH
261#endif
262#endif /* HAS_GETSERVBYNAME_R */
263#ifdef HAS_GETSPNAM_R
f7937171 264 Safefree(PL_reentrant_buffer->_spent_buffer);
10bc17b6 265#endif /* HAS_GETSPNAM_R */
10bc17b6
JH
266#ifdef HAS_READDIR_R
267 Safefree(PL_reentrant_buffer->_readdir_struct);
268#endif /* HAS_READDIR_R */
269#ifdef HAS_READDIR64_R
270 Safefree(PL_reentrant_buffer->_readdir64_struct);
271#endif /* HAS_READDIR64_R */
272#ifdef HAS_SETLOCALE_R
273 Safefree(PL_reentrant_buffer->_setlocale_buffer);
274#endif /* HAS_SETLOCALE_R */
275#ifdef HAS_STRERROR_R
276 Safefree(PL_reentrant_buffer->_strerror_buffer);
277#endif /* HAS_STRERROR_R */
278#ifdef HAS_TTYNAME_R
279 Safefree(PL_reentrant_buffer->_ttyname_buffer);
280#endif /* HAS_TTYNAME_R */
281
282 Safefree(PL_reentrant_buffer);
283#endif /* USE_REENTRANT_API */
284}
285
edd309b7
JH
286void*
287Perl_reentrant_retry(const char *f, ...)
288{
edd309b7 289 void *retptr = NULL;
fe5bfecd 290 va_list ap;
7918f24d 291#ifdef USE_REENTRANT_API
dbf7dff6 292 dTHX;
7918f24d
NC
293 /* Easier to special case this here than in embed.pl. (Look at what it
294 generates for proto.h) */
295 PERL_ARGS_ASSERT_REENTRANT_RETRY;
296#endif
fe5bfecd 297 va_start(ap, f);
369ec4b2 298 {
edd309b7 299#ifdef USE_REENTRANT_API
0891a229 300# 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)
e3410746
SR
301 void *p0;
302# endif
f7937171 303# if defined(USE_SERVENT_BUFFER)
e3410746
SR
304 void *p1;
305# endif
f7937171 306# if defined(USE_HOSTENT_BUFFER)
edd309b7 307 size_t asize;
e3410746 308# endif
f7937171 309# if defined(USE_HOSTENT_BUFFER) || defined(USE_NETENT_BUFFER) || defined(USE_PROTOENT_BUFFER) || defined(USE_SERVENT_BUFFER)
edd309b7 310 int anint;
e3410746 311# endif
edd309b7 312
edd309b7 313 switch (PL_op->op_type) {
f7937171 314#ifdef USE_HOSTENT_BUFFER
edd309b7
JH
315 case OP_GHBYADDR:
316 case OP_GHBYNAME:
317 case OP_GHOSTENT:
318 {
af685957
JH
319#ifdef PERL_REENTRANT_MAXSIZE
320 if (PL_reentrant_buffer->_hostent_size <=
321 PERL_REENTRANT_MAXSIZE / 2)
322#endif
323 {
acfc2cc3
HS
324 RenewDouble(PL_reentrant_buffer->_hostent_buffer,
325 &PL_reentrant_buffer->_hostent_size, char);
edd309b7
JH
326 switch (PL_op->op_type) {
327 case OP_GHBYADDR:
328 p0 = va_arg(ap, void *);
329 asize = va_arg(ap, size_t);
330 anint = va_arg(ap, int);
331 retptr = gethostbyaddr(p0, asize, anint); break;
332 case OP_GHBYNAME:
333 p0 = va_arg(ap, void *);
f6f0b69b 334 retptr = gethostbyname((char *)p0); break;
edd309b7
JH
335 case OP_GHOSTENT:
336 retptr = gethostent(); break;
337 default:
0de8cad8 338 SETERRNO(ERANGE, LIB_INVARG);
edd309b7
JH
339 break;
340 }
341 }
342 }
343 break;
344#endif
f7937171 345#ifdef USE_GRENT_BUFFER
edd309b7
JH
346 case OP_GGRNAM:
347 case OP_GGRGID:
348 case OP_GGRENT:
349 {
af685957
JH
350#ifdef PERL_REENTRANT_MAXSIZE
351 if (PL_reentrant_buffer->_grent_size <=
352 PERL_REENTRANT_MAXSIZE / 2)
353#endif
354 {
edd309b7 355 Gid_t gid;
acfc2cc3
HS
356 RenewDouble(PL_reentrant_buffer->_grent_buffer,
357 &PL_reentrant_buffer->_grent_size, char);
edd309b7
JH
358 switch (PL_op->op_type) {
359 case OP_GGRNAM:
360 p0 = va_arg(ap, void *);
f6f0b69b 361 retptr = getgrnam((char *)p0); break;
edd309b7 362 case OP_GGRGID:
ab2b559b
JH
363#if Gid_t_size < INTSIZE
364 gid = (Gid_t)va_arg(ap, int);
365#else
edd309b7 366 gid = va_arg(ap, Gid_t);
ab2b559b 367#endif
edd309b7
JH
368 retptr = getgrgid(gid); break;
369 case OP_GGRENT:
370 retptr = getgrent(); break;
371 default:
0de8cad8 372 SETERRNO(ERANGE, LIB_INVARG);
edd309b7
JH
373 break;
374 }
375 }
376 }
377 break;
378#endif
f7937171 379#ifdef USE_NETENT_BUFFER
edd309b7
JH
380 case OP_GNBYADDR:
381 case OP_GNBYNAME:
382 case OP_GNETENT:
383 {
af685957
JH
384#ifdef PERL_REENTRANT_MAXSIZE
385 if (PL_reentrant_buffer->_netent_size <=
386 PERL_REENTRANT_MAXSIZE / 2)
387#endif
388 {
edd309b7 389 Netdb_net_t net;
acfc2cc3
HS
390 RenewDouble(PL_reentrant_buffer->_netent_buffer,
391 &PL_reentrant_buffer->_netent_size, char);
edd309b7
JH
392 switch (PL_op->op_type) {
393 case OP_GNBYADDR:
394 net = va_arg(ap, Netdb_net_t);
395 anint = va_arg(ap, int);
396 retptr = getnetbyaddr(net, anint); break;
397 case OP_GNBYNAME:
398 p0 = va_arg(ap, void *);
f6f0b69b 399 retptr = getnetbyname((char *)p0); break;
edd309b7
JH
400 case OP_GNETENT:
401 retptr = getnetent(); break;
402 default:
0de8cad8 403 SETERRNO(ERANGE, LIB_INVARG);
edd309b7
JH
404 break;
405 }
406 }
407 }
408 break;
409#endif
f7937171 410#ifdef USE_PWENT_BUFFER
edd309b7
JH
411 case OP_GPWNAM:
412 case OP_GPWUID:
413 case OP_GPWENT:
414 {
af685957
JH
415#ifdef PERL_REENTRANT_MAXSIZE
416 if (PL_reentrant_buffer->_pwent_size <=
417 PERL_REENTRANT_MAXSIZE / 2)
418#endif
419 {
edd309b7 420 Uid_t uid;
acfc2cc3
HS
421 RenewDouble(PL_reentrant_buffer->_pwent_buffer,
422 &PL_reentrant_buffer->_pwent_size, char);
edd309b7
JH
423 switch (PL_op->op_type) {
424 case OP_GPWNAM:
425 p0 = va_arg(ap, void *);
f6f0b69b 426 retptr = getpwnam((char *)p0); break;
edd309b7 427 case OP_GPWUID:
ab2b559b
JH
428#if Uid_t_size < INTSIZE
429 uid = (Uid_t)va_arg(ap, int);
430#else
edd309b7 431 uid = va_arg(ap, Uid_t);
ab2b559b 432#endif
edd309b7 433 retptr = getpwuid(uid); break;
123829cf 434#if defined(HAS_GETPWENT) || defined(HAS_GETPWENT_R)
edd309b7
JH
435 case OP_GPWENT:
436 retptr = getpwent(); break;
123829cf 437#endif
edd309b7 438 default:
0de8cad8 439 SETERRNO(ERANGE, LIB_INVARG);
edd309b7
JH
440 break;
441 }
442 }
443 }
444 break;
445#endif
f7937171 446#ifdef USE_PROTOENT_BUFFER
edd309b7
JH
447 case OP_GPBYNAME:
448 case OP_GPBYNUMBER:
449 case OP_GPROTOENT:
450 {
af685957
JH
451#ifdef PERL_REENTRANT_MAXSIZE
452 if (PL_reentrant_buffer->_protoent_size <=
453 PERL_REENTRANT_MAXSIZE / 2)
454#endif
455 {
acfc2cc3
HS
456 RenewDouble(PL_reentrant_buffer->_protoent_buffer,
457 &PL_reentrant_buffer->_protoent_size, char);
edd309b7
JH
458 switch (PL_op->op_type) {
459 case OP_GPBYNAME:
460 p0 = va_arg(ap, void *);
f6f0b69b 461 retptr = getprotobyname((char *)p0); break;
edd309b7
JH
462 case OP_GPBYNUMBER:
463 anint = va_arg(ap, int);
464 retptr = getprotobynumber(anint); break;
465 case OP_GPROTOENT:
466 retptr = getprotoent(); break;
467 default:
0de8cad8 468 SETERRNO(ERANGE, LIB_INVARG);
edd309b7
JH
469 break;
470 }
471 }
472 }
473 break;
474#endif
f7937171 475#ifdef USE_SERVENT_BUFFER
edd309b7
JH
476 case OP_GSBYNAME:
477 case OP_GSBYPORT:
478 case OP_GSERVENT:
479 {
af685957
JH
480#ifdef PERL_REENTRANT_MAXSIZE
481 if (PL_reentrant_buffer->_servent_size <=
482 PERL_REENTRANT_MAXSIZE / 2)
483#endif
484 {
acfc2cc3
HS
485 RenewDouble(PL_reentrant_buffer->_servent_buffer,
486 &PL_reentrant_buffer->_servent_size, char);
edd309b7
JH
487 switch (PL_op->op_type) {
488 case OP_GSBYNAME:
489 p0 = va_arg(ap, void *);
490 p1 = va_arg(ap, void *);
f6f0b69b 491 retptr = getservbyname((char *)p0, (char *)p1); break;
edd309b7
JH
492 case OP_GSBYPORT:
493 anint = va_arg(ap, int);
494 p0 = va_arg(ap, void *);
f6f0b69b 495 retptr = getservbyport(anint, (char *)p0); break;
edd309b7
JH
496 case OP_GSERVENT:
497 retptr = getservent(); break;
498 default:
0de8cad8 499 SETERRNO(ERANGE, LIB_INVARG);
edd309b7
JH
500 break;
501 }
502 }
503 }
504 break;
505#endif
506 default:
507 /* Not known how to retry, so just fail. */
508 break;
509 }
6148ee25
SP
510#else
511 PERL_UNUSED_ARG(f);
edd309b7 512#endif
369ec4b2 513 }
fe5bfecd 514 va_end(ap);
edd309b7
JH
515 return retptr;
516}
517
37442d52 518/* ex: set ro: */