struct servent * getservbyname_r(const char *name, const char *proto, struct servent *sp, struct servent_data *sd) { struct servent *s; char **cp; assert(name != NULL); /* proto may be NULL */ setservent_r(sd->stayopen, sd); while ((s = getservent_r(sp, sd)) != NULL) { if (strcmp(name, s->s_name) == 0) goto gotname; for (cp = s->s_aliases; *cp; cp++) if (strcmp(name, *cp) == 0) goto gotname; continue; gotname: if (proto == NULL || strcmp(s->s_proto, proto) == 0) break; } if (!sd->stayopen) if (sd->fp != NULL) { (void)fclose(sd->fp); sd->fp = NULL; } return s; }
/* libc_hidden_proto(getservbyname_r) */ int getservbyname_r(const char *name, const char *proto, struct servent * result_buf, char * buf, size_t buflen, struct servent ** result) { register char **cp; int ret; __UCLIBC_MUTEX_LOCK(mylock); setservent(serv_stayopen); while (!(ret=getservent_r(result_buf, buf, buflen, result))) { if (strcmp(name, result_buf->s_name) == 0) goto gotname; for (cp = result_buf->s_aliases; *cp; cp++) if (strcmp(name, *cp) == 0) goto gotname; continue; gotname: if (proto == 0 || strcmp(result_buf->s_proto, proto) == 0) break; } if (!serv_stayopen) endservent(); __UCLIBC_MUTEX_UNLOCK(mylock); return *result?0:ret; }
int getservbyname_r(const char *name, const char *proto, struct servent *se, struct servent_data *sd) { char **cp; int error; setservent_r(sd->stayopen, sd); while ((error = getservent_r(se, sd)) == 0) { if (strcmp(name, se->s_name) == 0) goto gotname; for (cp = se->s_aliases; *cp; cp++) if (strcmp(name, *cp) == 0) goto gotname; continue; gotname: if (proto == 0 || strcmp(se->s_proto, proto) == 0) break; } if (!sd->stayopen && sd->fp != NULL) { fclose(sd->fp); sd->fp = NULL; } return (error); }
EXPORT_C struct servent * getservent(void) { struct servdata *sd; #ifndef __SYMBIAN32__ if ((sd = __servdata_init()) == NULL) return (NULL); #else sd= reentfunction(_REENT); sd->serv.s_name=0; sd->serv.s_port=0; sd->serv.s_proto=0; sd->serv.s_aliases=0; sd->data.fp=0; #endif /*__SYMBIAN32__*/ if (getservent_r(&sd->serv, &sd->data) != 0) #ifdef __SYMBIAN32__ { num_line=0; #endif return (NULL); #ifdef __SYMBIAN32__ } num_line++; if(sd->data.fp) fclose(sd->data.fp); #endif//__SYMBIAN32__ return (&sd->serv); }
struct servent * getservent(void) { struct servent *result; __initbuf(); getservent_r(&serv, servbuf, SBUFSIZE, &result); return result; }
struct servent *getservent(void) { struct servent *result; __initbuf(); getservent_r(&serve, servbuf, servbuf_sz, &result); return result; }
struct servent * getservent(void) { static struct servent serv; if (getservent_r(&serv, &_servent_data) != 0) return (NULL); return (&serv); }
struct servent * getservent(void) { res_static rs = __res_get_static(); if (rs == NULL) return NULL; return getservent_r(rs); }
struct servent* getservbyname(const char* name, const char* proto) { res_static rs = __res_get_static(); rs->servent_ptr = NULL; struct servent* s; while ((s = getservent_r(rs)) != NULL) { if (strcmp(s->s_name, name) == 0 && (proto == NULL || strcmp(s->s_proto, proto) == 0)) { return s; } } return NULL; }
int main (void) { struct servent service; struct servent * retour; char buffer [256]; setservent(0); while(getservent_r(& service, buffer, 256, & retour) == 0) fprintf(stdout, "%s ", service.s_name); endservent(); fprintf(stdout, "\n"); return EXIT_SUCCESS; }
/* libc_hidden_proto(getservbyport_r) */ int getservbyport_r(int port, const char *proto, struct servent * result_buf, char * buf, size_t buflen, struct servent ** result) { int ret; __UCLIBC_MUTEX_LOCK(mylock); setservent(serv_stayopen); while (!(ret=getservent_r(result_buf, buf, buflen, result))) { if (result_buf->s_port != port) continue; if (proto == 0 || strcmp(result_buf->s_proto, proto) == 0) break; } if (!serv_stayopen) endservent(); __UCLIBC_MUTEX_UNLOCK(mylock); return *result?0:ret; }
int getservbyport_r(int port, const char *proto, struct servent *se, struct servent_data *sd) { int error; setservent_r(sd->stayopen, sd); while ((error = getservent_r(se, sd)) == 0) { if (se->s_port != port) continue; if (proto == 0 || strcmp(se->s_proto, proto) == 0) break; } if (!sd->stayopen && sd->fp != NULL) { fclose(sd->fp); sd->fp = NULL; } return (error); }
struct servent * getservbyport_r(int port, const char *proto, struct servent *sp, struct servent_data *sd) { struct servent *s; setservent_r(sd->stayopen, sd); while ((s = getservent_r(sp, sd)) != NULL) { if (s->s_port != port) continue; if (proto == NULL || strcmp(s->s_proto, proto) == 0) break; } if (!sd->stayopen) if (sd->fp != NULL) { (void)fclose(sd->fp); sd->fp = NULL; } return s; }
struct servent * getservbyport(int port, const char *proto) { res_static rs = __res_get_static(); struct servent* s; if (rs == NULL || proto == NULL) { errno = EINVAL; return NULL; } rs->servent_ptr = NULL; while (1) { struct servent* s = getservent_r(rs); if (s == NULL) break; if ( s->s_port == port && !strcmp( s->s_proto, proto ) ) return s; } return NULL; }