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