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