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