struct protoent * getprotobyname_r(const char *name, struct protoent *pr, struct protoent_data *pd) { struct protoent *p; char **cp; _DIAGASSERT(name != NULL); setprotoent_r(pd->stayopen, pd); while ((p = getprotoent_r(pr, pd)) != NULL) { if (strcmp(p->p_name, name) == 0) break; for (cp = p->p_aliases; *cp != NULL; cp++) if (strcmp(*cp, name) == 0) goto found; } found: if (!pd->stayopen) if (pd->fp != NULL) { (void)fclose(pd->fp); pd->fp = NULL; } return p; }
int getprotobynumber_r(int num, struct protoent *pe, struct protoent_data *pd) { int error; setprotoent_r(pd->stayopen, pd); while ((error = getprotoent_r(pe, pd)) == 0) if (pe->p_proto == num) break; if (!pd->stayopen && pd->fp != NULL) { (void)fclose(pd->fp); pd->fp = NULL; } return (error); }
void setprotoent(int f) { setprotoent_r(f, &_protoent_data); }