Make Win32 treat IO-Compress as an XS extension, as was done elsewhere by
[p5sagit/p5-mst-13.2.git] / reentr.c
CommitLineData
37442d52 1/* -*- buffer-read-only: t -*-
2 *
10bc17b6 3 * reentr.c
4 *
922adc66 5 * Copyright (C) 2002, 2003, 2005, 2006, 2007 by Larry Wall and others
10bc17b6 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 *
10 * !!!!!!! DO NOT EDIT THIS FILE !!!!!!!
61296642 11 * This file is built by reentr.pl from data in reentr.pl.
10bc17b6 12 *
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!"
15 *
61296642 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.
10bc17b6 22 */
23
24#include "EXTERN.h"
25#define PERL_IN_REENTR_C
26#include "perl.h"
27#include "reentr.h"
28
29void
30Perl_reentrant_size(pTHX) {
31#ifdef USE_REENTRANT_API
8695fa85 32#define REENTRANTSMALLSIZE 256 /* Make something up. */
33#define REENTRANTUSUALSIZE 4096 /* Make something up. */
10bc17b6 34#ifdef HAS_ASCTIME_R
8695fa85 35 PL_reentrant_buffer->_asctime_size = REENTRANTSMALLSIZE;
10bc17b6 36#endif /* HAS_ASCTIME_R */
37#ifdef HAS_CRYPT_R
38#endif /* HAS_CRYPT_R */
39#ifdef HAS_CTIME_R
8695fa85 40 PL_reentrant_buffer->_ctime_size = REENTRANTSMALLSIZE;
10bc17b6 41#endif /* HAS_CTIME_R */
42#ifdef HAS_DRAND48_R
43#endif /* HAS_DRAND48_R */
44#ifdef HAS_GETGRNAM_R
0de8cad8 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);
a3dd3f83 47 if (PL_reentrant_buffer->_grent_size == (size_t) -1)
0de8cad8 48 PL_reentrant_buffer->_grent_size = REENTRANTUSUALSIZE;
10bc17b6 49# else
50# if defined(__osf__) && defined(__alpha) && defined(SIABUFSIZ)
f7937171 51 PL_reentrant_buffer->_grent_size = SIABUFSIZ;
10bc17b6 52# else
53# ifdef __sgi
f7937171 54 PL_reentrant_buffer->_grent_size = BUFSIZ;
10bc17b6 55# else
f7937171 56 PL_reentrant_buffer->_grent_size = REENTRANTUSUALSIZE;
10bc17b6 57# endif
58# endif
59# endif
60#endif /* HAS_GETGRNAM_R */
61#ifdef HAS_GETHOSTBYNAME_R
62#if !(GETHOSTBYNAME_R_PROTO == REENTRANT_PROTO_I_CSD)
f7937171 63 PL_reentrant_buffer->_hostent_size = REENTRANTUSUALSIZE;
10bc17b6 64#endif
65#endif /* HAS_GETHOSTBYNAME_R */
66#ifdef HAS_GETLOGIN_R
8695fa85 67 PL_reentrant_buffer->_getlogin_size = REENTRANTSMALLSIZE;
10bc17b6 68#endif /* HAS_GETLOGIN_R */
69#ifdef HAS_GETNETBYNAME_R
70#if !(GETNETBYNAME_R_PROTO == REENTRANT_PROTO_I_CSD)
f7937171 71 PL_reentrant_buffer->_netent_size = REENTRANTUSUALSIZE;
10bc17b6 72#endif
73#endif /* HAS_GETNETBYNAME_R */
74#ifdef HAS_GETPROTOBYNAME_R
75#if !(GETPROTOBYNAME_R_PROTO == REENTRANT_PROTO_I_CSD)
f7937171 76 PL_reentrant_buffer->_protoent_size = REENTRANTUSUALSIZE;
10bc17b6 77#endif
78#endif /* HAS_GETPROTOBYNAME_R */
79#ifdef HAS_GETPWNAM_R
80# if defined(HAS_SYSCONF) && defined(_SC_GETPW_R_SIZE_MAX) && !defined(__GLIBC__)
f7937171 81 PL_reentrant_buffer->_pwent_size = sysconf(_SC_GETPW_R_SIZE_MAX);
a3dd3f83 82 if (PL_reentrant_buffer->_pwent_size == (size_t) -1)
f7937171 83 PL_reentrant_buffer->_pwent_size = REENTRANTUSUALSIZE;
10bc17b6 84# else
85# if defined(__osf__) && defined(__alpha) && defined(SIABUFSIZ)
f7937171 86 PL_reentrant_buffer->_pwent_size = SIABUFSIZ;
10bc17b6 87# else
88# ifdef __sgi
f7937171 89 PL_reentrant_buffer->_pwent_size = BUFSIZ;
10bc17b6 90# else
f7937171 91 PL_reentrant_buffer->_pwent_size = REENTRANTUSUALSIZE;
10bc17b6 92# endif
93# endif
94# endif
95#endif /* HAS_GETPWNAM_R */
96#ifdef HAS_GETSERVBYNAME_R
97#if !(GETSERVBYNAME_R_PROTO == REENTRANT_PROTO_I_CCSD)
f7937171 98 PL_reentrant_buffer->_servent_size = REENTRANTUSUALSIZE;
10bc17b6 99#endif
100#endif /* HAS_GETSERVBYNAME_R */
101#ifdef HAS_GETSPNAM_R
f7937171 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);
a3dd3f83 104 if (PL_reentrant_buffer->_spent_size == (size_t) -1)
0de8cad8 105 PL_reentrant_buffer->_spent_size = REENTRANTUSUALSIZE;
f7937171 106# else
107# if defined(__osf__) && defined(__alpha) && defined(SIABUFSIZ)
108 PL_reentrant_buffer->_spent_size = SIABUFSIZ;
109# else
110# ifdef __sgi
111 PL_reentrant_buffer->_spent_size = BUFSIZ;
112# else
113 PL_reentrant_buffer->_spent_size = REENTRANTUSUALSIZE;
114# endif
115# endif
116# endif
10bc17b6 117#endif /* HAS_GETSPNAM_R */
10bc17b6 118#ifdef HAS_RANDOM_R
119#endif /* HAS_RANDOM_R */
120#ifdef HAS_READDIR_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
8695fa85 131 PL_reentrant_buffer->_setlocale_size = REENTRANTSMALLSIZE;
10bc17b6 132#endif /* HAS_SETLOCALE_R */
5cb13b8d 133#ifdef HAS_SRANDOM_R
134#endif /* HAS_SRANDOM_R */
10bc17b6 135#ifdef HAS_STRERROR_R
8695fa85 136 PL_reentrant_buffer->_strerror_size = REENTRANTSMALLSIZE;
10bc17b6 137#endif /* HAS_STRERROR_R */
138#ifdef HAS_TTYNAME_R
8695fa85 139 PL_reentrant_buffer->_ttyname_size = REENTRANTSMALLSIZE;
10bc17b6 140#endif /* HAS_TTYNAME_R */
141
142#endif /* USE_REENTRANT_API */
143}
144
145void
146Perl_reentrant_init(pTHX) {
147#ifdef USE_REENTRANT_API
a02a5408 148 Newx(PL_reentrant_buffer, 1, REENTR);
10bc17b6 149 Perl_reentrant_size(aTHX);
150#ifdef HAS_ASCTIME_R
a02a5408 151 Newx(PL_reentrant_buffer->_asctime_buffer, PL_reentrant_buffer->_asctime_size, char);
10bc17b6 152#endif /* HAS_ASCTIME_R */
153#ifdef HAS_CRYPT_R
05404ffe 154#if CRYPT_R_PROTO != REENTRANT_PROTO_B_CCD
155 PL_reentrant_buffer->_crypt_struct_buffer = 0;
10bc17b6 156#endif
157#endif /* HAS_CRYPT_R */
158#ifdef HAS_CTIME_R
a02a5408 159 Newx(PL_reentrant_buffer->_ctime_buffer, PL_reentrant_buffer->_ctime_size, char);
10bc17b6 160#endif /* HAS_CTIME_R */
161#ifdef HAS_DRAND48_R
162#endif /* HAS_DRAND48_R */
163#ifdef HAS_GETGRNAM_R
f7937171 164# ifdef USE_GRENT_FPTR
165 PL_reentrant_buffer->_grent_fptr = NULL;
10bc17b6 166# endif
a02a5408 167 Newx(PL_reentrant_buffer->_grent_buffer, PL_reentrant_buffer->_grent_size, char);
10bc17b6 168#endif /* HAS_GETGRNAM_R */
169#ifdef HAS_GETHOSTBYNAME_R
170#if !(GETHOSTBYNAME_R_PROTO == REENTRANT_PROTO_I_CSD)
a02a5408 171 Newx(PL_reentrant_buffer->_hostent_buffer, PL_reentrant_buffer->_hostent_size, char);
10bc17b6 172#endif
173#endif /* HAS_GETHOSTBYNAME_R */
174#ifdef HAS_GETLOGIN_R
a02a5408 175 Newx(PL_reentrant_buffer->_getlogin_buffer, PL_reentrant_buffer->_getlogin_size, char);
10bc17b6 176#endif /* HAS_GETLOGIN_R */
177#ifdef HAS_GETNETBYNAME_R
178#if !(GETNETBYNAME_R_PROTO == REENTRANT_PROTO_I_CSD)
a02a5408 179 Newx(PL_reentrant_buffer->_netent_buffer, PL_reentrant_buffer->_netent_size, char);
10bc17b6 180#endif
181#endif /* HAS_GETNETBYNAME_R */
182#ifdef HAS_GETPROTOBYNAME_R
183#if !(GETPROTOBYNAME_R_PROTO == REENTRANT_PROTO_I_CSD)
a02a5408 184 Newx(PL_reentrant_buffer->_protoent_buffer, PL_reentrant_buffer->_protoent_size, char);
10bc17b6 185#endif
186#endif /* HAS_GETPROTOBYNAME_R */
187#ifdef HAS_GETPWNAM_R
f7937171 188# ifdef USE_PWENT_FPTR
189 PL_reentrant_buffer->_pwent_fptr = NULL;
10bc17b6 190# endif
a02a5408 191 Newx(PL_reentrant_buffer->_pwent_buffer, PL_reentrant_buffer->_pwent_size, char);
10bc17b6 192#endif /* HAS_GETPWNAM_R */
193#ifdef HAS_GETSERVBYNAME_R
194#if !(GETSERVBYNAME_R_PROTO == REENTRANT_PROTO_I_CCSD)
a02a5408 195 Newx(PL_reentrant_buffer->_servent_buffer, PL_reentrant_buffer->_servent_size, char);
10bc17b6 196#endif
197#endif /* HAS_GETSERVBYNAME_R */
198#ifdef HAS_GETSPNAM_R
f7937171 199# ifdef USE_SPENT_FPTR
200 PL_reentrant_buffer->_spent_fptr = NULL;
201# endif
a02a5408 202 Newx(PL_reentrant_buffer->_spent_buffer, PL_reentrant_buffer->_spent_size, char);
10bc17b6 203#endif /* HAS_GETSPNAM_R */
10bc17b6 204#ifdef HAS_RANDOM_R
205#endif /* HAS_RANDOM_R */
206#ifdef HAS_READDIR_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
a02a5408 213 Newx(PL_reentrant_buffer->_setlocale_buffer, PL_reentrant_buffer->_setlocale_size, char);
10bc17b6 214#endif /* HAS_SETLOCALE_R */
5cb13b8d 215#ifdef HAS_SRANDOM_R
216#endif /* HAS_SRANDOM_R */
10bc17b6 217#ifdef HAS_STRERROR_R
a02a5408 218 Newx(PL_reentrant_buffer->_strerror_buffer, PL_reentrant_buffer->_strerror_size, char);
10bc17b6 219#endif /* HAS_STRERROR_R */
220#ifdef HAS_TTYNAME_R
a02a5408 221 Newx(PL_reentrant_buffer->_ttyname_buffer, PL_reentrant_buffer->_ttyname_size, char);
10bc17b6 222#endif /* HAS_TTYNAME_R */
223
224#endif /* USE_REENTRANT_API */
225}
226
227void
228Perl_reentrant_free(pTHX) {
229#ifdef USE_REENTRANT_API
230#ifdef HAS_ASCTIME_R
231 Safefree(PL_reentrant_buffer->_asctime_buffer);
232#endif /* HAS_ASCTIME_R */
233#ifdef HAS_CRYPT_R
05404ffe 234#if CRYPT_R_PROTO != REENTRANT_PROTO_B_CCD
235 Safefree(PL_reentrant_buffer->_crypt_struct_buffer);
236#endif
10bc17b6 237#endif /* HAS_CRYPT_R */
238#ifdef HAS_CTIME_R
239 Safefree(PL_reentrant_buffer->_ctime_buffer);
240#endif /* HAS_CTIME_R */
241#ifdef HAS_DRAND48_R
242#endif /* HAS_DRAND48_R */
243#ifdef HAS_GETGRNAM_R
f7937171 244 Safefree(PL_reentrant_buffer->_grent_buffer);
10bc17b6 245#endif /* HAS_GETGRNAM_R */
246#ifdef HAS_GETHOSTBYNAME_R
247#if !(GETHOSTBYNAME_R_PROTO == REENTRANT_PROTO_I_CSD)
f7937171 248 Safefree(PL_reentrant_buffer->_hostent_buffer);
10bc17b6 249#endif
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)
f7937171 256 Safefree(PL_reentrant_buffer->_netent_buffer);
10bc17b6 257#endif
258#endif /* HAS_GETNETBYNAME_R */
259#ifdef HAS_GETPROTOBYNAME_R
260#if !(GETPROTOBYNAME_R_PROTO == REENTRANT_PROTO_I_CSD)
f7937171 261 Safefree(PL_reentrant_buffer->_protoent_buffer);
10bc17b6 262#endif
263#endif /* HAS_GETPROTOBYNAME_R */
264#ifdef HAS_GETPWNAM_R
f7937171 265 Safefree(PL_reentrant_buffer->_pwent_buffer);
10bc17b6 266#endif /* HAS_GETPWNAM_R */
267#ifdef HAS_GETSERVBYNAME_R
268#if !(GETSERVBYNAME_R_PROTO == REENTRANT_PROTO_I_CCSD)
f7937171 269 Safefree(PL_reentrant_buffer->_servent_buffer);
10bc17b6 270#endif
271#endif /* HAS_GETSERVBYNAME_R */
272#ifdef HAS_GETSPNAM_R
f7937171 273 Safefree(PL_reentrant_buffer->_spent_buffer);
10bc17b6 274#endif /* HAS_GETSPNAM_R */
10bc17b6 275#ifdef HAS_RANDOM_R
276#endif /* HAS_RANDOM_R */
277#ifdef HAS_READDIR_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 */
5cb13b8d 286#ifdef HAS_SRANDOM_R
287#endif /* HAS_SRANDOM_R */
10bc17b6 288#ifdef HAS_STRERROR_R
289 Safefree(PL_reentrant_buffer->_strerror_buffer);
290#endif /* HAS_STRERROR_R */
291#ifdef HAS_TTYNAME_R
292 Safefree(PL_reentrant_buffer->_ttyname_buffer);
293#endif /* HAS_TTYNAME_R */
294
295 Safefree(PL_reentrant_buffer);
296#endif /* USE_REENTRANT_API */
297}
298
edd309b7 299void*
300Perl_reentrant_retry(const char *f, ...)
301{
abb2c242 302 dTHX;
edd309b7 303 void *retptr = NULL;
fe5bfecd 304 va_list ap;
7918f24d 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;
309#endif
fe5bfecd 310 va_start(ap, f);
369ec4b2 311 {
edd309b7 312#ifdef USE_REENTRANT_API
0891a229 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)
e3410746 314 void *p0;
315# endif
f7937171 316# if defined(USE_SERVENT_BUFFER)
e3410746 317 void *p1;
318# endif
f7937171 319# if defined(USE_HOSTENT_BUFFER)
edd309b7 320 size_t asize;
e3410746 321# endif
f7937171 322# if defined(USE_HOSTENT_BUFFER) || defined(USE_NETENT_BUFFER) || defined(USE_PROTOENT_BUFFER) || defined(USE_SERVENT_BUFFER)
edd309b7 323 int anint;
e3410746 324# endif
edd309b7 325
edd309b7 326 switch (PL_op->op_type) {
f7937171 327#ifdef USE_HOSTENT_BUFFER
edd309b7 328 case OP_GHBYADDR:
329 case OP_GHBYNAME:
330 case OP_GHOSTENT:
331 {
af685957 332#ifdef PERL_REENTRANT_MAXSIZE
333 if (PL_reentrant_buffer->_hostent_size <=
334 PERL_REENTRANT_MAXSIZE / 2)
335#endif
336 {
f7937171 337 PL_reentrant_buffer->_hostent_size *= 2;
338 Renew(PL_reentrant_buffer->_hostent_buffer,
339 PL_reentrant_buffer->_hostent_size, char);
edd309b7 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 *);
f6f0b69b 348 retptr = gethostbyname((char *)p0); break;
edd309b7 349 case OP_GHOSTENT:
350 retptr = gethostent(); break;
351 default:
0de8cad8 352 SETERRNO(ERANGE, LIB_INVARG);
edd309b7 353 break;
354 }
355 }
356 }
357 break;
358#endif
f7937171 359#ifdef USE_GRENT_BUFFER
edd309b7 360 case OP_GGRNAM:
361 case OP_GGRGID:
362 case OP_GGRENT:
363 {
af685957 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 370 PL_reentrant_buffer->_grent_size *= 2;
371 Renew(PL_reentrant_buffer->_grent_buffer,
372 PL_reentrant_buffer->_grent_size, char);
edd309b7 373 switch (PL_op->op_type) {
374 case OP_GGRNAM:
375 p0 = va_arg(ap, void *);
f6f0b69b 376 retptr = getgrnam((char *)p0); break;
edd309b7 377 case OP_GGRGID:
ab2b559b 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 383 retptr = getgrgid(gid); break;
384 case OP_GGRENT:
385 retptr = getgrent(); break;
386 default:
0de8cad8 387 SETERRNO(ERANGE, LIB_INVARG);
edd309b7 388 break;
389 }
390 }
391 }
392 break;
393#endif
f7937171 394#ifdef USE_NETENT_BUFFER
edd309b7 395 case OP_GNBYADDR:
396 case OP_GNBYNAME:
397 case OP_GNETENT:
398 {
af685957 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 405 PL_reentrant_buffer->_netent_size *= 2;
406 Renew(PL_reentrant_buffer->_netent_buffer,
407 PL_reentrant_buffer->_netent_size, char);
edd309b7 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 *);
f6f0b69b 415 retptr = getnetbyname((char *)p0); break;
edd309b7 416 case OP_GNETENT:
417 retptr = getnetent(); break;
418 default:
0de8cad8 419 SETERRNO(ERANGE, LIB_INVARG);
edd309b7 420 break;
421 }
422 }
423 }
424 break;
425#endif
f7937171 426#ifdef USE_PWENT_BUFFER
edd309b7 427 case OP_GPWNAM:
428 case OP_GPWUID:
429 case OP_GPWENT:
430 {
af685957 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 437 PL_reentrant_buffer->_pwent_size *= 2;
438 Renew(PL_reentrant_buffer->_pwent_buffer,
439 PL_reentrant_buffer->_pwent_size, char);
edd309b7 440 switch (PL_op->op_type) {
441 case OP_GPWNAM:
442 p0 = va_arg(ap, void *);
f6f0b69b 443 retptr = getpwnam((char *)p0); break;
edd309b7 444 case OP_GPWUID:
ab2b559b 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 450 retptr = getpwuid(uid); break;
451 case OP_GPWENT:
452 retptr = getpwent(); break;
453 default:
0de8cad8 454 SETERRNO(ERANGE, LIB_INVARG);
edd309b7 455 break;
456 }
457 }
458 }
459 break;
460#endif
f7937171 461#ifdef USE_PROTOENT_BUFFER
edd309b7 462 case OP_GPBYNAME:
463 case OP_GPBYNUMBER:
464 case OP_GPROTOENT:
465 {
af685957 466#ifdef PERL_REENTRANT_MAXSIZE
467 if (PL_reentrant_buffer->_protoent_size <=
468 PERL_REENTRANT_MAXSIZE / 2)
469#endif
470 {
f7937171 471 PL_reentrant_buffer->_protoent_size *= 2;
472 Renew(PL_reentrant_buffer->_protoent_buffer,
473 PL_reentrant_buffer->_protoent_size, char);
edd309b7 474 switch (PL_op->op_type) {
475 case OP_GPBYNAME:
476 p0 = va_arg(ap, void *);
f6f0b69b 477 retptr = getprotobyname((char *)p0); break;
edd309b7 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 485 break;
486 }
487 }
488 }
489 break;
490#endif
f7937171 491#ifdef USE_SERVENT_BUFFER
edd309b7 492 case OP_GSBYNAME:
493 case OP_GSBYPORT:
494 case OP_GSERVENT:
495 {
af685957 496#ifdef PERL_REENTRANT_MAXSIZE
497 if (PL_reentrant_buffer->_servent_size <=
498 PERL_REENTRANT_MAXSIZE / 2)
499#endif
500 {
f7937171 501 PL_reentrant_buffer->_servent_size *= 2;
502 Renew(PL_reentrant_buffer->_servent_buffer,
503 PL_reentrant_buffer->_servent_size, char);
edd309b7 504 switch (PL_op->op_type) {
505 case OP_GSBYNAME:
506 p0 = va_arg(ap, void *);
507 p1 = va_arg(ap, void *);
f6f0b69b 508 retptr = getservbyname((char *)p0, (char *)p1); break;
edd309b7 509 case OP_GSBYPORT:
510 anint = va_arg(ap, int);
511 p0 = va_arg(ap, void *);
f6f0b69b 512 retptr = getservbyport(anint, (char *)p0); break;
edd309b7 513 case OP_GSERVENT:
514 retptr = getservent(); break;
515 default:
0de8cad8 516 SETERRNO(ERANGE, LIB_INVARG);
edd309b7 517 break;
518 }
519 }
520 }
521 break;
522#endif
523 default:
524 /* Not known how to retry, so just fail. */
525 break;
526 }
6148ee25 527#else
528 PERL_UNUSED_ARG(f);
edd309b7 529#endif
369ec4b2 530 }
fe5bfecd 531 va_end(ap);
edd309b7 532 return retptr;
533}
534
37442d52 535/* ex: set ro: */