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