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 void setservent(int f) { struct servdata *sd = 0; #ifndef __SYMBIAN32__ if ((sd = __servdata_init()) == NULL) return; #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; num_line=0; #endif//__SYMBIAN32__ setservent_r(f, &sd->data); #ifdef __SYMBIAN32__ if(sd->data.fp) { fclose(sd->data.fp); } #endif//__SYMBIAN32__ }
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; }
struct servent * getservbyport_r(int port, const char *proto, struct servent *sp, struct servent_data *sd) { setservent_r(sd->flags & _SV_STAYOPEN, sd); sp = _servent_getbyport(sd, sp, port, proto); if (!(sd->flags & _SV_STAYOPEN)) _servent_close(sd); return sp; }
struct servent * getservbyname_r(const char *name, const char *proto, struct servent *sp, struct servent_data *sd) { assert(name != NULL); /* proto may be NULL */ setservent_r(sd->flags & _SV_STAYOPEN, sd); sp = _servent_getbyname(sd, sp, name, proto); if (!(sd->flags & _SV_STAYOPEN)) _servent_close(sd); return sp; }
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; }
void setservent(int f) { setservent_r(f, &_servent_data); }