This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
reentr.[ch]: 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
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"
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;
0917d9b3
KW
46
47 /* Set the sizes of the reentrant buffers */
48
10bc17b6 49#ifdef USE_REENTRANT_API
7c1815b7
KW
50# define REENTRANTSMALLSIZE 256 /* Make something up. */
51# define REENTRANTUSUALSIZE 4096 /* Make something up. */
52
53# ifdef HAS_ASCTIME_R
8695fa85 54 PL_reentrant_buffer->_asctime_size = REENTRANTSMALLSIZE;
7c1815b7
KW
55# endif /* HAS_ASCTIME_R */
56
57# ifdef HAS_CRYPT_R
58# endif /* HAS_CRYPT_R */
59
60# ifdef HAS_CTIME_R
8695fa85 61 PL_reentrant_buffer->_ctime_size = REENTRANTSMALLSIZE;
7c1815b7
KW
62# endif /* HAS_CTIME_R */
63
64# ifdef HAS_GETGRNAM_R
65# if defined(HAS_SYSCONF) && defined(_SC_GETGR_R_SIZE_MAX) && !defined(__GLIBC__)
0de8cad8 66 PL_reentrant_buffer->_grent_size = sysconf(_SC_GETGR_R_SIZE_MAX);
a3dd3f83 67 if (PL_reentrant_buffer->_grent_size == (size_t) -1)
0de8cad8 68 PL_reentrant_buffer->_grent_size = REENTRANTUSUALSIZE;
7c1815b7 69# elif defined(__osf__) && defined(__alpha) && defined(SIABUFSIZ)
f7937171 70 PL_reentrant_buffer->_grent_size = SIABUFSIZ;
7c1815b7 71# elif defined(__sgi)
f7937171 72 PL_reentrant_buffer->_grent_size = BUFSIZ;
7c1815b7 73# else
f7937171 74 PL_reentrant_buffer->_grent_size = REENTRANTUSUALSIZE;
7c1815b7
KW
75# endif
76# endif /* HAS_GETGRNAM_R */
77
78# ifdef HAS_GETHOSTBYNAME_R
79# if !(GETHOSTBYNAME_R_PROTO == REENTRANT_PROTO_I_CSD)
f7937171 80 PL_reentrant_buffer->_hostent_size = REENTRANTUSUALSIZE;
7c1815b7
KW
81# endif
82# endif /* HAS_GETHOSTBYNAME_R */
83
84# ifdef HAS_GETLOGIN_R
8695fa85 85 PL_reentrant_buffer->_getlogin_size = REENTRANTSMALLSIZE;
7c1815b7
KW
86# endif /* HAS_GETLOGIN_R */
87
88# ifdef HAS_GETNETBYNAME_R
89# if !(GETNETBYNAME_R_PROTO == REENTRANT_PROTO_I_CSD)
f7937171 90 PL_reentrant_buffer->_netent_size = REENTRANTUSUALSIZE;
7c1815b7
KW
91# endif
92# endif /* HAS_GETNETBYNAME_R */
93
94# ifdef HAS_GETPROTOBYNAME_R
95# if !(GETPROTOBYNAME_R_PROTO == REENTRANT_PROTO_I_CSD)
f7937171 96 PL_reentrant_buffer->_protoent_size = REENTRANTUSUALSIZE;
7c1815b7
KW
97# endif
98# endif /* HAS_GETPROTOBYNAME_R */
99
100# ifdef HAS_GETPWNAM_R
101# if defined(HAS_SYSCONF) && defined(_SC_GETPW_R_SIZE_MAX) && !defined(__GLIBC__)
f7937171 102 PL_reentrant_buffer->_pwent_size = sysconf(_SC_GETPW_R_SIZE_MAX);
a3dd3f83 103 if (PL_reentrant_buffer->_pwent_size == (size_t) -1)
f7937171 104 PL_reentrant_buffer->_pwent_size = REENTRANTUSUALSIZE;
7c1815b7 105# elif defined(__osf__) && defined(__alpha) && defined(SIABUFSIZ)
f7937171 106 PL_reentrant_buffer->_pwent_size = SIABUFSIZ;
7c1815b7 107# elif defined(__sgi)
f7937171 108 PL_reentrant_buffer->_pwent_size = BUFSIZ;
7c1815b7 109# else
f7937171 110 PL_reentrant_buffer->_pwent_size = REENTRANTUSUALSIZE;
7c1815b7
KW
111# endif
112# endif /* HAS_GETPWNAM_R */
113
114# ifdef HAS_GETSERVBYNAME_R
115# if !(GETSERVBYNAME_R_PROTO == REENTRANT_PROTO_I_CCSD)
f7937171 116 PL_reentrant_buffer->_servent_size = REENTRANTUSUALSIZE;
7c1815b7
KW
117# endif
118# endif /* HAS_GETSERVBYNAME_R */
119
120# ifdef HAS_GETSPNAM_R
121# if defined(HAS_SYSCONF) && defined(_SC_GETPW_R_SIZE_MAX) && !defined(__GLIBC__)
f7937171 122 PL_reentrant_buffer->_spent_size = sysconf(_SC_GETPW_R_SIZE_MAX);
a3dd3f83 123 if (PL_reentrant_buffer->_spent_size == (size_t) -1)
0de8cad8 124 PL_reentrant_buffer->_spent_size = REENTRANTUSUALSIZE;
7c1815b7 125# elif defined(__osf__) && defined(__alpha) && defined(SIABUFSIZ)
f7937171 126 PL_reentrant_buffer->_spent_size = SIABUFSIZ;
7c1815b7 127# elif defined(__sgi)
f7937171 128 PL_reentrant_buffer->_spent_size = BUFSIZ;
7c1815b7 129# else
f7937171 130 PL_reentrant_buffer->_spent_size = REENTRANTUSUALSIZE;
7c1815b7
KW
131# endif
132# endif /* HAS_GETSPNAM_R */
133
134# ifdef HAS_READDIR_R
10bc17b6
JH
135 /* This is the size Solaris recommends.
136 * (though we go static, should use pathconf() instead) */
137 PL_reentrant_buffer->_readdir_size = sizeof(struct dirent) + MAXPATHLEN + 1;
7c1815b7
KW
138# endif /* HAS_READDIR_R */
139
140# ifdef HAS_READDIR64_R
10bc17b6
JH
141 /* This is the size Solaris recommends.
142 * (though we go static, should use pathconf() instead) */
143 PL_reentrant_buffer->_readdir64_size = sizeof(struct dirent64) + MAXPATHLEN + 1;
7c1815b7
KW
144# endif /* HAS_READDIR64_R */
145
146# ifdef HAS_SETLOCALE_R
8695fa85 147 PL_reentrant_buffer->_setlocale_size = REENTRANTSMALLSIZE;
7c1815b7
KW
148# endif /* HAS_SETLOCALE_R */
149
150# ifdef HAS_STRERROR_R
8695fa85 151 PL_reentrant_buffer->_strerror_size = REENTRANTSMALLSIZE;
7c1815b7
KW
152# endif /* HAS_STRERROR_R */
153
154# ifdef HAS_TTYNAME_R
8695fa85 155 PL_reentrant_buffer->_ttyname_size = REENTRANTSMALLSIZE;
7c1815b7
KW
156# endif /* HAS_TTYNAME_R */
157
10bc17b6
JH
158
159#endif /* USE_REENTRANT_API */
7c1815b7 160
10bc17b6
JH
161}
162
163void
164Perl_reentrant_init(pTHX) {
23491f1d 165 PERL_UNUSED_CONTEXT;
0917d9b3
KW
166
167 /* Initialize the whole thing */
168
10bc17b6 169#ifdef USE_REENTRANT_API
7c1815b7 170
a02a5408 171 Newx(PL_reentrant_buffer, 1, REENTR);
10bc17b6 172 Perl_reentrant_size(aTHX);
7c1815b7
KW
173
174# ifdef HAS_ASCTIME_R
a02a5408 175 Newx(PL_reentrant_buffer->_asctime_buffer, PL_reentrant_buffer->_asctime_size, char);
7c1815b7
KW
176# endif /* HAS_ASCTIME_R */
177
178# ifdef HAS_CRYPT_R
179# if CRYPT_R_PROTO != REENTRANT_PROTO_B_CCD
05404ffe 180 PL_reentrant_buffer->_crypt_struct_buffer = 0;
7c1815b7
KW
181# endif
182# endif /* HAS_CRYPT_R */
183
184# ifdef HAS_CTIME_R
a02a5408 185 Newx(PL_reentrant_buffer->_ctime_buffer, PL_reentrant_buffer->_ctime_size, char);
7c1815b7
KW
186# endif /* HAS_CTIME_R */
187
188# ifdef HAS_GETGRNAM_R
f7937171
JH
189# ifdef USE_GRENT_FPTR
190 PL_reentrant_buffer->_grent_fptr = NULL;
10bc17b6 191# endif
a02a5408 192 Newx(PL_reentrant_buffer->_grent_buffer, PL_reentrant_buffer->_grent_size, char);
7c1815b7
KW
193# endif /* HAS_GETGRNAM_R */
194
195# ifdef HAS_GETHOSTBYNAME_R
196# if !(GETHOSTBYNAME_R_PROTO == REENTRANT_PROTO_I_CSD)
a02a5408 197 Newx(PL_reentrant_buffer->_hostent_buffer, PL_reentrant_buffer->_hostent_size, char);
7c1815b7
KW
198# endif
199# endif /* HAS_GETHOSTBYNAME_R */
200
201# ifdef HAS_GETLOGIN_R
a02a5408 202 Newx(PL_reentrant_buffer->_getlogin_buffer, PL_reentrant_buffer->_getlogin_size, char);
7c1815b7
KW
203# endif /* HAS_GETLOGIN_R */
204
205# ifdef HAS_GETNETBYNAME_R
206# if !(GETNETBYNAME_R_PROTO == REENTRANT_PROTO_I_CSD)
a02a5408 207 Newx(PL_reentrant_buffer->_netent_buffer, PL_reentrant_buffer->_netent_size, char);
7c1815b7
KW
208# endif
209# endif /* HAS_GETNETBYNAME_R */
210
211# ifdef HAS_GETPROTOBYNAME_R
212# if !(GETPROTOBYNAME_R_PROTO == REENTRANT_PROTO_I_CSD)
a02a5408 213 Newx(PL_reentrant_buffer->_protoent_buffer, PL_reentrant_buffer->_protoent_size, char);
7c1815b7
KW
214# endif
215# endif /* HAS_GETPROTOBYNAME_R */
216
217# ifdef HAS_GETPWNAM_R
f7937171
JH
218# ifdef USE_PWENT_FPTR
219 PL_reentrant_buffer->_pwent_fptr = NULL;
10bc17b6 220# endif
a02a5408 221 Newx(PL_reentrant_buffer->_pwent_buffer, PL_reentrant_buffer->_pwent_size, char);
7c1815b7
KW
222# endif /* HAS_GETPWNAM_R */
223
224# ifdef HAS_GETSERVBYNAME_R
225# if !(GETSERVBYNAME_R_PROTO == REENTRANT_PROTO_I_CCSD)
a02a5408 226 Newx(PL_reentrant_buffer->_servent_buffer, PL_reentrant_buffer->_servent_size, char);
7c1815b7
KW
227# endif
228# endif /* HAS_GETSERVBYNAME_R */
229
230# ifdef HAS_GETSPNAM_R
f7937171
JH
231# ifdef USE_SPENT_FPTR
232 PL_reentrant_buffer->_spent_fptr = NULL;
233# endif
a02a5408 234 Newx(PL_reentrant_buffer->_spent_buffer, PL_reentrant_buffer->_spent_size, char);
7c1815b7
KW
235# endif /* HAS_GETSPNAM_R */
236
237# ifdef HAS_READDIR_R
10bc17b6 238 PL_reentrant_buffer->_readdir_struct = (struct dirent*)safemalloc(PL_reentrant_buffer->_readdir_size);
7c1815b7
KW
239# endif /* HAS_READDIR_R */
240
241# ifdef HAS_READDIR64_R
10bc17b6 242 PL_reentrant_buffer->_readdir64_struct = (struct dirent64*)safemalloc(PL_reentrant_buffer->_readdir64_size);
7c1815b7
KW
243# endif /* HAS_READDIR64_R */
244
245# ifdef HAS_SETLOCALE_R
a02a5408 246 Newx(PL_reentrant_buffer->_setlocale_buffer, PL_reentrant_buffer->_setlocale_size, char);
7c1815b7
KW
247# endif /* HAS_SETLOCALE_R */
248
249# ifdef HAS_STRERROR_R
a02a5408 250 Newx(PL_reentrant_buffer->_strerror_buffer, PL_reentrant_buffer->_strerror_size, char);
7c1815b7
KW
251# endif /* HAS_STRERROR_R */
252
253# ifdef HAS_TTYNAME_R
a02a5408 254 Newx(PL_reentrant_buffer->_ttyname_buffer, PL_reentrant_buffer->_ttyname_size, char);
7c1815b7
KW
255# endif /* HAS_TTYNAME_R */
256
10bc17b6
JH
257
258#endif /* USE_REENTRANT_API */
7c1815b7 259
10bc17b6
JH
260}
261
262void
263Perl_reentrant_free(pTHX) {
23491f1d 264 PERL_UNUSED_CONTEXT;
0917d9b3
KW
265
266 /* Tear down */
267
10bc17b6 268#ifdef USE_REENTRANT_API
7c1815b7
KW
269
270# ifdef HAS_ASCTIME_R
10bc17b6 271 Safefree(PL_reentrant_buffer->_asctime_buffer);
7c1815b7
KW
272# endif /* HAS_ASCTIME_R */
273
274# ifdef HAS_CRYPT_R
275# if CRYPT_R_PROTO != REENTRANT_PROTO_B_CCD
05404ffe 276 Safefree(PL_reentrant_buffer->_crypt_struct_buffer);
7c1815b7
KW
277# endif
278# endif /* HAS_CRYPT_R */
279
280# ifdef HAS_CTIME_R
10bc17b6 281 Safefree(PL_reentrant_buffer->_ctime_buffer);
7c1815b7
KW
282# endif /* HAS_CTIME_R */
283
284# ifdef HAS_GETGRNAM_R
f7937171 285 Safefree(PL_reentrant_buffer->_grent_buffer);
7c1815b7
KW
286# endif /* HAS_GETGRNAM_R */
287
288# ifdef HAS_GETHOSTBYNAME_R
289# if !(GETHOSTBYNAME_R_PROTO == REENTRANT_PROTO_I_CSD)
f7937171 290 Safefree(PL_reentrant_buffer->_hostent_buffer);
7c1815b7
KW
291# endif
292# endif /* HAS_GETHOSTBYNAME_R */
293
294# ifdef HAS_GETLOGIN_R
10bc17b6 295 Safefree(PL_reentrant_buffer->_getlogin_buffer);
7c1815b7
KW
296# endif /* HAS_GETLOGIN_R */
297
298# ifdef HAS_GETNETBYNAME_R
299# if !(GETNETBYNAME_R_PROTO == REENTRANT_PROTO_I_CSD)
f7937171 300 Safefree(PL_reentrant_buffer->_netent_buffer);
7c1815b7
KW
301# endif
302# endif /* HAS_GETNETBYNAME_R */
303
304# ifdef HAS_GETPROTOBYNAME_R
305# if !(GETPROTOBYNAME_R_PROTO == REENTRANT_PROTO_I_CSD)
f7937171 306 Safefree(PL_reentrant_buffer->_protoent_buffer);
7c1815b7
KW
307# endif
308# endif /* HAS_GETPROTOBYNAME_R */
309
310# ifdef HAS_GETPWNAM_R
f7937171 311 Safefree(PL_reentrant_buffer->_pwent_buffer);
7c1815b7
KW
312# endif /* HAS_GETPWNAM_R */
313
314# ifdef HAS_GETSERVBYNAME_R
315# if !(GETSERVBYNAME_R_PROTO == REENTRANT_PROTO_I_CCSD)
f7937171 316 Safefree(PL_reentrant_buffer->_servent_buffer);
7c1815b7
KW
317# endif
318# endif /* HAS_GETSERVBYNAME_R */
319
320# ifdef HAS_GETSPNAM_R
f7937171 321 Safefree(PL_reentrant_buffer->_spent_buffer);
7c1815b7
KW
322# endif /* HAS_GETSPNAM_R */
323
324# ifdef HAS_READDIR_R
10bc17b6 325 Safefree(PL_reentrant_buffer->_readdir_struct);
7c1815b7
KW
326# endif /* HAS_READDIR_R */
327
328# ifdef HAS_READDIR64_R
10bc17b6 329 Safefree(PL_reentrant_buffer->_readdir64_struct);
7c1815b7
KW
330# endif /* HAS_READDIR64_R */
331
332# ifdef HAS_SETLOCALE_R
10bc17b6 333 Safefree(PL_reentrant_buffer->_setlocale_buffer);
7c1815b7
KW
334# endif /* HAS_SETLOCALE_R */
335
336# ifdef HAS_STRERROR_R
10bc17b6 337 Safefree(PL_reentrant_buffer->_strerror_buffer);
7c1815b7
KW
338# endif /* HAS_STRERROR_R */
339
340# ifdef HAS_TTYNAME_R
10bc17b6 341 Safefree(PL_reentrant_buffer->_ttyname_buffer);
7c1815b7
KW
342# endif /* HAS_TTYNAME_R */
343
10bc17b6
JH
344
345 Safefree(PL_reentrant_buffer);
7c1815b7 346
10bc17b6
JH
347#endif /* USE_REENTRANT_API */
348}
349
edd309b7
JH
350void*
351Perl_reentrant_retry(const char *f, ...)
352{
0917d9b3
KW
353 /* This function is set up to be called if the normal function returns
354 * failure with errno ERANGE, which indicates the buffer is too small.
355 * This function calls the failing one again with a larger buffer.
356 *
357 * What has happened is that, due to the magic of C preprocessor macro
358 * expansion, when the original code called function 'foo(args)', it was
359 * instead compiled into something like a call of 'foo_r(args, buffer)'
360 * Below we retry with 'foo', but the preprocessor has changed that into
361 * 'foo_r', so this function will end up calling itself recursively, each
362 * time with a larger buffer. If PERL_REENTRANT_MAXSIZE is defined, it
363 * won't increase beyond that, instead failing. */
364
edd309b7 365 void *retptr = NULL;
fe5bfecd 366 va_list ap;
7c1815b7 367
7918f24d 368#ifdef USE_REENTRANT_API
7c1815b7 369
dbf7dff6 370 dTHX;
7c1815b7 371
7918f24d
NC
372 /* Easier to special case this here than in embed.pl. (Look at what it
373 generates for proto.h) */
374 PERL_ARGS_ASSERT_REENTRANT_RETRY;
7c1815b7 375
7918f24d 376#endif
7c1815b7 377
fe5bfecd 378 va_start(ap, f);
369ec4b2 379 {
7c1815b7 380
edd309b7 381#ifdef USE_REENTRANT_API
0891a229 382# 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
383 void *p0;
384# endif
f7937171 385# if defined(USE_SERVENT_BUFFER)
e3410746
SR
386 void *p1;
387# endif
f7937171 388# if defined(USE_HOSTENT_BUFFER)
edd309b7 389 size_t asize;
e3410746 390# endif
f7937171 391# if defined(USE_HOSTENT_BUFFER) || defined(USE_NETENT_BUFFER) || defined(USE_PROTOENT_BUFFER) || defined(USE_SERVENT_BUFFER)
edd309b7 392 int anint;
e3410746 393# endif
edd309b7 394
edd309b7 395 switch (PL_op->op_type) {
7c1815b7
KW
396
397# ifdef USE_HOSTENT_BUFFER
398
edd309b7
JH
399 case OP_GHBYADDR:
400 case OP_GHBYNAME:
401 case OP_GHOSTENT:
402 {
7c1815b7
KW
403
404# ifdef PERL_REENTRANT_MAXSIZE
af685957
JH
405 if (PL_reentrant_buffer->_hostent_size <=
406 PERL_REENTRANT_MAXSIZE / 2)
7c1815b7 407# endif
af685957 408 {
7c1815b7
KW
409 RenewDouble(PL_reentrant_buffer->_hostent_buffer,
410 &PL_reentrant_buffer->_hostent_size, char);
411 switch (PL_op->op_type) {
edd309b7
JH
412 case OP_GHBYADDR:
413 p0 = va_arg(ap, void *);
414 asize = va_arg(ap, size_t);
415 anint = va_arg(ap, int);
2b1f0c39 416 retptr = gethostbyaddr((Netdb_host_t) p0, (Netdb_hlen_t) asize, anint); break;
edd309b7
JH
417 case OP_GHBYNAME:
418 p0 = va_arg(ap, void *);
2b1f0c39 419 retptr = gethostbyname((Netdb_name_t) p0); break;
edd309b7
JH
420 case OP_GHOSTENT:
421 retptr = gethostent(); break;
422 default:
0de8cad8 423 SETERRNO(ERANGE, LIB_INVARG);
edd309b7 424 break;
7c1815b7 425 }
edd309b7
JH
426 }
427 }
428 break;
7c1815b7
KW
429
430# endif
431# ifdef USE_GRENT_BUFFER
432
edd309b7
JH
433 case OP_GGRNAM:
434 case OP_GGRGID:
435 case OP_GGRENT:
436 {
7c1815b7
KW
437
438# ifdef PERL_REENTRANT_MAXSIZE
af685957
JH
439 if (PL_reentrant_buffer->_grent_size <=
440 PERL_REENTRANT_MAXSIZE / 2)
7c1815b7 441# endif
af685957 442 {
edd309b7 443 Gid_t gid;
7c1815b7
KW
444 RenewDouble(PL_reentrant_buffer->_grent_buffer,
445 &PL_reentrant_buffer->_grent_size, char);
446 switch (PL_op->op_type) {
edd309b7
JH
447 case OP_GGRNAM:
448 p0 = va_arg(ap, void *);
f6f0b69b 449 retptr = getgrnam((char *)p0); break;
7c1815b7
KW
450 case OP_GGRGID:
451
452# if Gid_t_size < INTSIZE
453 gid = (Gid_t)va_arg(ap, int);
454# else
edd309b7 455 gid = va_arg(ap, Gid_t);
7c1815b7 456# endif
edd309b7
JH
457 retptr = getgrgid(gid); break;
458 case OP_GGRENT:
459 retptr = getgrent(); break;
460 default:
0de8cad8 461 SETERRNO(ERANGE, LIB_INVARG);
edd309b7 462 break;
7c1815b7 463 }
edd309b7
JH
464 }
465 }
466 break;
7c1815b7
KW
467
468# endif
469# ifdef USE_NETENT_BUFFER
470
edd309b7
JH
471 case OP_GNBYADDR:
472 case OP_GNBYNAME:
473 case OP_GNETENT:
474 {
7c1815b7
KW
475
476# ifdef PERL_REENTRANT_MAXSIZE
af685957
JH
477 if (PL_reentrant_buffer->_netent_size <=
478 PERL_REENTRANT_MAXSIZE / 2)
7c1815b7 479# endif
af685957 480 {
edd309b7 481 Netdb_net_t net;
7c1815b7
KW
482 RenewDouble(PL_reentrant_buffer->_netent_buffer,
483 &PL_reentrant_buffer->_netent_size, char);
484 switch (PL_op->op_type) {
edd309b7
JH
485 case OP_GNBYADDR:
486 net = va_arg(ap, Netdb_net_t);
487 anint = va_arg(ap, int);
488 retptr = getnetbyaddr(net, anint); break;
489 case OP_GNBYNAME:
490 p0 = va_arg(ap, void *);
f6f0b69b 491 retptr = getnetbyname((char *)p0); break;
edd309b7
JH
492 case OP_GNETENT:
493 retptr = getnetent(); break;
494 default:
0de8cad8 495 SETERRNO(ERANGE, LIB_INVARG);
edd309b7 496 break;
7c1815b7
KW
497 }
498 }
edd309b7
JH
499 }
500 break;
7c1815b7
KW
501
502# endif
503# ifdef USE_PWENT_BUFFER
504
edd309b7
JH
505 case OP_GPWNAM:
506 case OP_GPWUID:
507 case OP_GPWENT:
508 {
7c1815b7
KW
509
510# ifdef PERL_REENTRANT_MAXSIZE
af685957
JH
511 if (PL_reentrant_buffer->_pwent_size <=
512 PERL_REENTRANT_MAXSIZE / 2)
7c1815b7
KW
513
514# endif
af685957 515 {
edd309b7 516 Uid_t uid;
7c1815b7
KW
517 RenewDouble(PL_reentrant_buffer->_pwent_buffer,
518 &PL_reentrant_buffer->_pwent_size, char);
519 switch (PL_op->op_type) {
edd309b7
JH
520 case OP_GPWNAM:
521 p0 = va_arg(ap, void *);
f6f0b69b 522 retptr = getpwnam((char *)p0); break;
edd309b7 523 case OP_GPWUID:
7c1815b7
KW
524
525# if Uid_t_size < INTSIZE
ab2b559b 526 uid = (Uid_t)va_arg(ap, int);
7c1815b7 527# else
edd309b7 528 uid = va_arg(ap, Uid_t);
7c1815b7 529# endif
edd309b7 530 retptr = getpwuid(uid); break;
7c1815b7
KW
531
532# if defined(HAS_GETPWENT) || defined(HAS_GETPWENT_R)
edd309b7
JH
533 case OP_GPWENT:
534 retptr = getpwent(); break;
7c1815b7 535# endif
edd309b7 536 default:
0de8cad8 537 SETERRNO(ERANGE, LIB_INVARG);
edd309b7 538 break;
7c1815b7 539 }
edd309b7
JH
540 }
541 }
542 break;
7c1815b7
KW
543
544# endif
545# ifdef USE_PROTOENT_BUFFER
546
edd309b7
JH
547 case OP_GPBYNAME:
548 case OP_GPBYNUMBER:
549 case OP_GPROTOENT:
550 {
7c1815b7
KW
551
552# ifdef PERL_REENTRANT_MAXSIZE
af685957
JH
553 if (PL_reentrant_buffer->_protoent_size <=
554 PERL_REENTRANT_MAXSIZE / 2)
7c1815b7 555# endif
af685957 556 {
7c1815b7
KW
557 RenewDouble(PL_reentrant_buffer->_protoent_buffer,
558 &PL_reentrant_buffer->_protoent_size, char);
559 switch (PL_op->op_type) {
edd309b7
JH
560 case OP_GPBYNAME:
561 p0 = va_arg(ap, void *);
f6f0b69b 562 retptr = getprotobyname((char *)p0); break;
edd309b7
JH
563 case OP_GPBYNUMBER:
564 anint = va_arg(ap, int);
565 retptr = getprotobynumber(anint); break;
566 case OP_GPROTOENT:
567 retptr = getprotoent(); break;
568 default:
0de8cad8 569 SETERRNO(ERANGE, LIB_INVARG);
edd309b7 570 break;
7c1815b7 571 }
edd309b7
JH
572 }
573 }
574 break;
7c1815b7
KW
575
576# endif
577# ifdef USE_SERVENT_BUFFER
578
edd309b7
JH
579 case OP_GSBYNAME:
580 case OP_GSBYPORT:
581 case OP_GSERVENT:
582 {
7c1815b7
KW
583
584# ifdef PERL_REENTRANT_MAXSIZE
af685957
JH
585 if (PL_reentrant_buffer->_servent_size <=
586 PERL_REENTRANT_MAXSIZE / 2)
7c1815b7 587# endif
af685957 588 {
7c1815b7
KW
589 RenewDouble(PL_reentrant_buffer->_servent_buffer,
590 &PL_reentrant_buffer->_servent_size, char);
591 switch (PL_op->op_type) {
edd309b7
JH
592 case OP_GSBYNAME:
593 p0 = va_arg(ap, void *);
594 p1 = va_arg(ap, void *);
f6f0b69b 595 retptr = getservbyname((char *)p0, (char *)p1); break;
edd309b7
JH
596 case OP_GSBYPORT:
597 anint = va_arg(ap, int);
598 p0 = va_arg(ap, void *);
f6f0b69b 599 retptr = getservbyport(anint, (char *)p0); break;
edd309b7
JH
600 case OP_GSERVENT:
601 retptr = getservent(); break;
602 default:
0de8cad8 603 SETERRNO(ERANGE, LIB_INVARG);
edd309b7 604 break;
7c1815b7 605 }
edd309b7
JH
606 }
607 }
608 break;
7c1815b7
KW
609
610# endif
611
edd309b7
JH
612 default:
613 /* Not known how to retry, so just fail. */
614 break;
615 }
7c1815b7 616
6148ee25 617#else
7c1815b7 618
6148ee25 619 PERL_UNUSED_ARG(f);
7c1815b7 620
edd309b7 621#endif
7c1815b7 622
369ec4b2 623 }
fe5bfecd 624 va_end(ap);
edd309b7
JH
625 return retptr;
626}
627
37442d52 628/* ex: set ro: */