More unpack cleanups.
[p5sagit/p5-mst-13.2.git] / reentr.c
1 /*
2  *    reentr.c
3  *
4  *    Copyright (C) 2002, 2003, by Larry Wall and others
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
22 void
23 Perl_reentrant_size(pTHX) {
24 #ifdef USE_REENTRANT_API
25 #define REENTRANTSMALLSIZE       256    /* Make something up. */
26 #define REENTRANTUSUALSIZE      4096    /* Make something up. */
27 #ifdef HAS_ASCTIME_R
28         PL_reentrant_buffer->_asctime_size = REENTRANTSMALLSIZE;
29 #endif /* HAS_ASCTIME_R */
30 #ifdef HAS_CRYPT_R
31 #endif /* HAS_CRYPT_R */
32 #ifdef HAS_CTIME_R
33         PL_reentrant_buffer->_ctime_size = REENTRANTSMALLSIZE;
34 #endif /* HAS_CTIME_R */
35 #ifdef HAS_DRAND48_R
36 #endif /* HAS_DRAND48_R */
37 #ifdef HAS_GETGRNAM_R
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;
42 #   else
43 #       if defined(__osf__) && defined(__alpha) && defined(SIABUFSIZ)
44         PL_reentrant_buffer->_grent_size = SIABUFSIZ;
45 #       else
46 #           ifdef __sgi
47         PL_reentrant_buffer->_grent_size = BUFSIZ;
48 #           else
49         PL_reentrant_buffer->_grent_size = REENTRANTUSUALSIZE;
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)
56         PL_reentrant_buffer->_hostent_size = REENTRANTUSUALSIZE;
57 #endif
58 #endif /* HAS_GETHOSTBYNAME_R */
59 #ifdef HAS_GETLOGIN_R
60         PL_reentrant_buffer->_getlogin_size = REENTRANTSMALLSIZE;
61 #endif /* HAS_GETLOGIN_R */
62 #ifdef HAS_GETNETBYNAME_R
63 #if   !(GETNETBYNAME_R_PROTO == REENTRANT_PROTO_I_CSD)
64         PL_reentrant_buffer->_netent_size = REENTRANTUSUALSIZE;
65 #endif
66 #endif /* HAS_GETNETBYNAME_R */
67 #ifdef HAS_GETPROTOBYNAME_R
68 #if   !(GETPROTOBYNAME_R_PROTO == REENTRANT_PROTO_I_CSD)
69         PL_reentrant_buffer->_protoent_size = REENTRANTUSUALSIZE;
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__)
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;
77 #   else
78 #       if defined(__osf__) && defined(__alpha) && defined(SIABUFSIZ)
79         PL_reentrant_buffer->_pwent_size = SIABUFSIZ;
80 #       else
81 #           ifdef __sgi
82         PL_reentrant_buffer->_pwent_size = BUFSIZ;
83 #           else
84         PL_reentrant_buffer->_pwent_size = REENTRANTUSUALSIZE;
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)
91         PL_reentrant_buffer->_servent_size = REENTRANTUSUALSIZE;
92 #endif
93 #endif /* HAS_GETSERVBYNAME_R */
94 #ifdef HAS_GETSPNAM_R
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);
97         if (PL_reentrant_buffer->_spent_size == -1)
98                 PL_reentrant_buffer->_spent_size = REENTRANTUSUALSIZE;
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 
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
128         PL_reentrant_buffer->_setlocale_size = REENTRANTSMALLSIZE;
129 #endif /* HAS_SETLOCALE_R */
130 #ifdef HAS_SRANDOM_R
131 #endif /* HAS_SRANDOM_R */
132 #ifdef HAS_STRERROR_R
133         PL_reentrant_buffer->_strerror_size = REENTRANTSMALLSIZE;
134 #endif /* HAS_STRERROR_R */
135 #ifdef HAS_TTYNAME_R
136         PL_reentrant_buffer->_ttyname_size = REENTRANTSMALLSIZE;
137 #endif /* HAS_TTYNAME_R */
138
139 #endif /* USE_REENTRANT_API */
140 }
141
142 void
143 Perl_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
151 #if CRYPT_R_PROTO != REENTRANT_PROTO_B_CCD
152         PL_reentrant_buffer->_crypt_struct_buffer = 0;
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
161 #   ifdef USE_GRENT_FPTR
162         PL_reentrant_buffer->_grent_fptr = NULL;
163 #   endif
164         New(31338, PL_reentrant_buffer->_grent_buffer, PL_reentrant_buffer->_grent_size, char);
165 #endif /* HAS_GETGRNAM_R */
166 #ifdef HAS_GETHOSTBYNAME_R
167 #if   !(GETHOSTBYNAME_R_PROTO == REENTRANT_PROTO_I_CSD)
168         New(31338, PL_reentrant_buffer->_hostent_buffer, PL_reentrant_buffer->_hostent_size, char);
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)
176         New(31338, PL_reentrant_buffer->_netent_buffer, PL_reentrant_buffer->_netent_size, char);
177 #endif
178 #endif /* HAS_GETNETBYNAME_R */
179 #ifdef HAS_GETPROTOBYNAME_R
180 #if   !(GETPROTOBYNAME_R_PROTO == REENTRANT_PROTO_I_CSD)
181         New(31338, PL_reentrant_buffer->_protoent_buffer, PL_reentrant_buffer->_protoent_size, char);
182 #endif
183 #endif /* HAS_GETPROTOBYNAME_R */
184 #ifdef HAS_GETPWNAM_R
185 #   ifdef USE_PWENT_FPTR
186         PL_reentrant_buffer->_pwent_fptr = NULL;
187 #   endif
188         New(31338, PL_reentrant_buffer->_pwent_buffer, PL_reentrant_buffer->_pwent_size, char);
189 #endif /* HAS_GETPWNAM_R */
190 #ifdef HAS_GETSERVBYNAME_R
191 #if   !(GETSERVBYNAME_R_PROTO == REENTRANT_PROTO_I_CCSD)
192         New(31338, PL_reentrant_buffer->_servent_buffer, PL_reentrant_buffer->_servent_size, char);
193 #endif
194 #endif /* HAS_GETSERVBYNAME_R */
195 #ifdef HAS_GETSPNAM_R
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);
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 */
216 #ifdef HAS_SRANDOM_R
217 #endif /* HAS_SRANDOM_R */
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
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_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 */
291 #ifdef HAS_SRANDOM_R
292 #endif /* HAS_SRANDOM_R */
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
304 void*
305 Perl_reentrant_retry(const char *f, ...)
306 {
307     dTHX;
308     void *retptr = NULL;
309 #ifdef USE_REENTRANT_API
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)
311     void *p0;
312 #  endif
313 #  if defined(USE_SERVENT_BUFFER)
314     void *p1;
315 #  endif
316 #  if defined(USE_HOSTENT_BUFFER)
317     size_t asize;
318 #  endif
319 #  if defined(USE_HOSTENT_BUFFER) || defined(USE_NETENT_BUFFER) || defined(USE_PROTOENT_BUFFER) || defined(USE_SERVENT_BUFFER)
320     int anint;
321 #  endif
322     va_list ap;
323
324     va_start(ap, f);
325
326     switch (PL_op->op_type) {
327 #ifdef USE_HOSTENT_BUFFER
328     case OP_GHBYADDR:
329     case OP_GHBYNAME:
330     case OP_GHOSTENT:
331         {
332 #ifdef PERL_REENTRANT_MAXSIZE
333             if (PL_reentrant_buffer->_hostent_size <=
334                 PERL_REENTRANT_MAXSIZE / 2)
335 #endif
336             {
337                 PL_reentrant_buffer->_hostent_size *= 2;
338                 Renew(PL_reentrant_buffer->_hostent_buffer,
339                       PL_reentrant_buffer->_hostent_size, char);
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:
352                     SETERRNO(ERANGE, LIB_INVARG);
353                     break;
354                 }
355             }
356         }
357         break;
358 #endif
359 #ifdef USE_GRENT_BUFFER
360     case OP_GGRNAM:
361     case OP_GGRGID:
362     case OP_GGRENT:
363         {
364 #ifdef PERL_REENTRANT_MAXSIZE
365             if (PL_reentrant_buffer->_grent_size <=
366                 PERL_REENTRANT_MAXSIZE / 2)
367 #endif
368             {
369                 Gid_t gid;
370                 PL_reentrant_buffer->_grent_size *= 2;
371                 Renew(PL_reentrant_buffer->_grent_buffer,
372                       PL_reentrant_buffer->_grent_size, char);
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:
378 #if Gid_t_size < INTSIZE
379                     gid = (Gid_t)va_arg(ap, int);
380 #else
381                     gid = va_arg(ap, Gid_t);
382 #endif
383                     retptr = getgrgid(gid); break;
384                 case OP_GGRENT:
385                     retptr = getgrent(); break;
386                 default:
387                     SETERRNO(ERANGE, LIB_INVARG);
388                     break;
389                 }
390             }
391         }
392         break;
393 #endif
394 #ifdef USE_NETENT_BUFFER
395     case OP_GNBYADDR:
396     case OP_GNBYNAME:
397     case OP_GNETENT:
398         {
399 #ifdef PERL_REENTRANT_MAXSIZE
400             if (PL_reentrant_buffer->_netent_size <=
401                 PERL_REENTRANT_MAXSIZE / 2)
402 #endif
403             {
404                 Netdb_net_t net;
405                 PL_reentrant_buffer->_netent_size *= 2;
406                 Renew(PL_reentrant_buffer->_netent_buffer,
407                       PL_reentrant_buffer->_netent_size, char);
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:
419                     SETERRNO(ERANGE, LIB_INVARG);
420                     break;
421                 }
422             }
423         }
424         break;
425 #endif
426 #ifdef USE_PWENT_BUFFER
427     case OP_GPWNAM:
428     case OP_GPWUID:
429     case OP_GPWENT:
430         {
431 #ifdef PERL_REENTRANT_MAXSIZE
432             if (PL_reentrant_buffer->_pwent_size <=
433                 PERL_REENTRANT_MAXSIZE / 2)
434 #endif
435             {
436                 Uid_t uid;
437                 PL_reentrant_buffer->_pwent_size *= 2;
438                 Renew(PL_reentrant_buffer->_pwent_buffer,
439                       PL_reentrant_buffer->_pwent_size, char);
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:
445 #if Uid_t_size < INTSIZE
446                     uid = (Uid_t)va_arg(ap, int);
447 #else
448                     uid = va_arg(ap, Uid_t);
449 #endif
450                     retptr = getpwuid(uid); break;
451                 case OP_GPWENT:
452                     retptr = getpwent(); break;
453                 default:
454                     SETERRNO(ERANGE, LIB_INVARG);
455                     break;
456                 }
457             }
458         }
459         break;
460 #endif
461 #ifdef USE_PROTOENT_BUFFER
462     case OP_GPBYNAME:
463     case OP_GPBYNUMBER:
464     case OP_GPROTOENT:
465         {
466 #ifdef PERL_REENTRANT_MAXSIZE
467             if (PL_reentrant_buffer->_protoent_size <=
468                 PERL_REENTRANT_MAXSIZE / 2)
469 #endif
470             {
471                 PL_reentrant_buffer->_protoent_size *= 2;
472                 Renew(PL_reentrant_buffer->_protoent_buffer,
473                       PL_reentrant_buffer->_protoent_size, char);
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:
484                     SETERRNO(ERANGE, LIB_INVARG);
485                     break;
486                 }
487             }
488         }
489         break;
490 #endif
491 #ifdef USE_SERVENT_BUFFER
492     case OP_GSBYNAME:
493     case OP_GSBYPORT:
494     case OP_GSERVENT:
495         {
496 #ifdef PERL_REENTRANT_MAXSIZE
497             if (PL_reentrant_buffer->_servent_size <=
498                 PERL_REENTRANT_MAXSIZE / 2)
499 #endif
500             {
501                 PL_reentrant_buffer->_servent_size *= 2;
502                 Renew(PL_reentrant_buffer->_servent_buffer,
503                       PL_reentrant_buffer->_servent_size, char);
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:
516                     SETERRNO(ERANGE, LIB_INVARG);
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