From 47dfc702de46c6c96dc37c075f456c21d84e0546 Mon Sep 17 00:00:00 2001 From: Mark Andrews Date: Mon, 16 Jul 2001 14:43:40 +0000 Subject: [PATCH] glibc getserv*_r() --- lib/bind/configure.in | 18 +++++++++++------- lib/bind/include/netdb.h | 10 +++++++++- lib/bind/irs/getservent_r.c | 34 ++++++++++++++++++++++++++++++++-- lib/bind/port_before.h.in | 1 + 4 files changed, 53 insertions(+), 10 deletions(-) diff --git a/lib/bind/configure.in b/lib/bind/configure.in index e94a47668c..5f4244a2aa 100644 --- a/lib/bind/configure.in +++ b/lib/bind/configure.in @@ -18,7 +18,7 @@ AC_DIVERT_PUSH(AC_DIVERSION_NOTICE)dnl esyscmd([sed "s/^/# /" COPYRIGHT])dnl AC_DIVERT_POP()dnl -AC_REVISION($Revision: 1.72 $) +AC_REVISION($Revision: 1.73 $) AC_INIT(resolv/herror.c) AC_PREREQ(2.13) @@ -1950,21 +1950,23 @@ SERV_R_BAD="#define SERV_R_BAD NULL" SERV_R_COPY="#define SERV_R_COPY buf, buflen" SERV_R_COPY_ARGS="#define SERV_R_COPY_ARGS SERV_R_ARGS" SERV_R_OK="#define SERV_R_OK sptr" +SERV_R_SETANSWER="#undef SERV_R_SETANSWER" SERV_R_RETURN="#define SERV_R_RETURN struct servent *" ] , AC_TRY_COMPILE([ #include -struct servent * -getservent_r __P ((struct servent *, char *, size_t, struct servent **)); +int +getservent_r (struct servent *, char *, size_t, struct servent **); ],[return (0);], [ -SERV_R_ARGS="#define SERV_R_ARGS char *buf, int buflen, struct servent **answer" -SERV_R_BAD="#define SERV_R_BAD (-1)" +SERV_R_ARGS="#define SERV_R_ARGS char *buf, size_t buflen, struct servent **answerp" +SERV_R_BAD="#define SERV_R_BAD ERANGE" SERV_R_COPY="#define SERV_R_COPY buf, buflen" -SERV_R_COPY_ARGS="#define SERV_R_COPY_ARGS SERV_R_ARGS" +SERV_R_COPY_ARGS="#define SERV_R_COPY_ARGS char *buf, size_t buflen" SERV_R_OK="#define SERV_R_OK (0)" -SERV_R_RETURN="#define SERV_R_RETURN 1" +SERV_R_SETANSWER="#define SERV_R_SETANSWER 1" +SERV_R_RETURN="#define SERV_R_RETURN int" ] , ) @@ -1975,6 +1977,7 @@ SERV_R_BAD="#define SERV_R_BAD NULL" SERV_R_COPY="#define SERV_R_COPY buf, buflen" SERV_R_COPY_ARGS="#define SERV_R_COPY_ARGS SERV_R_ARGS" SERV_R_OK="#define SERV_R_OK sptr" +SERV_R_SETANSWER="#undef SERV_R_SETANSWER" SERV_R_RETURN="#define SERV_R_RETURN struct servent *" ) AC_SUBST(SERV_R_ARGS) @@ -1982,6 +1985,7 @@ AC_SUBST(SERV_R_BAD) AC_SUBST(SERV_R_COPY) AC_SUBST(SERV_R_COPY_ARGS) AC_SUBST(SERV_R_OK) +AC_SUBST(SERV_R_SETANSWER) AC_SUBST(SERV_R_RETURN) AC_CHECK_FUNC(endservent_r, diff --git a/lib/bind/include/netdb.h b/lib/bind/include/netdb.h index c8e5858edc..996873e007 100644 --- a/lib/bind/include/netdb.h +++ b/lib/bind/include/netdb.h @@ -86,7 +86,7 @@ /* * @(#)netdb.h 8.1 (Berkeley) 6/2/93 - * $Id: netdb.h,v 1.9 2001/07/16 08:37:44 marka Exp $ + * $Id: netdb.h,v 1.10 2001/07/16 14:43:39 marka Exp $ */ #ifndef _NETDB_H_ @@ -486,11 +486,19 @@ struct protoent *getprotoent_r __P((struct protoent *, char *, int)); void setprotoent_r __P((int)); void endprotoent_r __P((void)); +#ifdef __GLIBC__ +int getservbyname_r __P((const char *name, const char *, + struct servent *, char *, size_t, struct servent **)); +int getservbyport_r __P((int port, const char *, + struct servent *, char *, size_t, struct servent **)); +int getservent_r __P((struct servent *, char *, size_t, struct servent **)); +#else struct servent *getservbyname_r __P((const char *name, const char *, struct servent *, char *, int)); struct servent *getservbyport_r __P((int port, const char *, struct servent *, char *, int)); struct servent *getservent_r __P((struct servent *, char *, int)); +#endif void setservent_r __P((int)); void endservent_r __P((void)); diff --git a/lib/bind/irs/getservent_r.c b/lib/bind/irs/getservent_r.c index 89ac50593e..e9984ec35e 100644 --- a/lib/bind/irs/getservent_r.c +++ b/lib/bind/irs/getservent_r.c @@ -16,7 +16,7 @@ */ #if defined(LIBC_SCCS) && !defined(lint) -static const char rcsid[] = "$Id: getservent_r.c,v 1.2 2001/07/15 23:29:48 marka Exp $"; +static const char rcsid[] = "$Id: getservent_r.c,v 1.3 2001/07/16 14:43:40 marka Exp $"; #endif /* LIBC_SCCS and not lint */ #include @@ -41,22 +41,42 @@ SERV_R_RETURN getservbyname_r(const char *name, const char *proto, struct servent *sptr, SERV_R_ARGS) { struct servent *se = getservbyname(name, proto); +#ifdef SERV_R_SETANSWER + int n = 0; + + if (se == NULL || (n = copy_servent(se, sptr, SERV_R_COPY)) != 0) + *answerp = NULL; + else + *answerp = sptr; + return (n); +#else if (se == NULL) return (SERV_R_BAD); return (copy_servent(se, sptr, SERV_R_COPY)); +#endif } SERV_R_RETURN getservbyport_r(int port, const char *proto, struct servent *sptr, SERV_R_ARGS) { struct servent *se = getservbyport(port, proto); +#ifdef SERV_R_SETANSWER + int n = 0; + + if (se == NULL || (n = copy_servent(se, sptr, SERV_R_COPY)) != 0) + *answerp = NULL; + else + *answerp = sptr; + return (n); +#else if (se == NULL) return (SERV_R_BAD); return (copy_servent(se, sptr, SERV_R_COPY)); +#endif } /* @@ -68,11 +88,21 @@ getservbyport_r(int port, const char *proto, SERV_R_RETURN getservent_r(struct servent *sptr, SERV_R_ARGS) { struct servent *se = getservent(); +#ifdef SERV_R_SETANSWER + int n = 0; + + if (se == NULL || (n = copy_servent(se, sptr, SERV_R_COPY)) != 0) + *answerp = NULL; + else + *answerp = sptr; + return (n); +#else if (se == NULL) return (SERV_R_BAD); return (copy_servent(se, sptr, SERV_R_COPY)); +#endif } SERV_R_SET_RETURN @@ -120,7 +150,7 @@ copy_servent(struct servent *se, struct servent *sptr, SERV_R_COPY_ARGS) { len += strlen(se->s_proto) + 1; len += numptr * sizeof(char*); - if (len > buflen) { + if (len > (int)buflen) { errno = ERANGE; return (SERV_R_BAD); } diff --git a/lib/bind/port_before.h.in b/lib/bind/port_before.h.in index 538d5d52d8..db8810d64c 100644 --- a/lib/bind/port_before.h.in +++ b/lib/bind/port_before.h.in @@ -109,6 +109,7 @@ struct timezone; /* silence warning */ @SERV_R_END_RETURN@ @SERV_R_ENT_ARGS@ @SERV_R_OK@ +@SERV_R_SETANSWER@ @SERV_R_RETURN@ @SERV_R_SET_RESULT@ @SERV_R_SET_RETURN@