From 101e6adfe041b661e04444e3cb08654f0dfec310 Mon Sep 17 00:00:00 2001 From: Mark Andrews Date: Mon, 16 Jul 2001 08:37:45 +0000 Subject: [PATCH] glibc getproto*_r() --- lib/bind/configure.in | 25 ++++++++++++++++++++++++- lib/bind/include/netdb.h | 10 +++++++++- lib/bind/irs/getprotoent_r.c | 34 ++++++++++++++++++++++++++++++++-- lib/bind/port_before.h.in | 1 + 4 files changed, 66 insertions(+), 4 deletions(-) diff --git a/lib/bind/configure.in b/lib/bind/configure.in index 8607cb9c93..e94a47668c 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.71 $) +AC_REVISION($Revision: 1.72 $) AC_INIT(resolv/herror.c) AC_PREREQ(2.13) @@ -1792,9 +1792,30 @@ PROTO_R_BAD="#define PROTO_R_BAD NULL" PROTO_R_COPY="#define PROTO_R_COPY buf, buflen" PROTO_R_COPY_ARGS="#define PROTO_R_COPY_ARGS PROTO_R_ARGS" PROTO_R_OK="#define PROTO_R_OK pptr" +PROTO_R_SETANSWER="#undef PROTO_R_SETANSWER" PROTO_R_RETURN="#define PROTO_R_RETURN struct protoent *" ] , +AC_TRY_COMPILE( +[ +#include +int getprotoent_r (struct protoent *, char *, size_t, struct protoent **); + +] +, +[return (0);] +, +[ +PROTO_R_ARGS="#define PROTO_R_ARGS char *buf, size_t buflen, struct protoent **answerp" +PROTO_R_BAD="#define PROTO_R_BAD ERANGE" +PROTO_R_COPY="#define PROTO_R_COPY buf, buflen" +PROTO_R_COPY_ARGS="#define PROTO_R_COPY_ARGS char *buf, size_t buflen" +PROTO_R_OK="#define PROTO_R_OK 0" +PROTO_R_SETANSWER="#define PROTO_R_SETANSWER 1" +PROTO_R_RETURN="#define PROTO_R_RETURN int" +] +, +) ) , PROTO_R_ARGS="#define PROTO_R_ARGS char *buf, int buflen" @@ -1802,6 +1823,7 @@ PROTO_R_BAD="#define PROTO_R_BAD NULL" PROTO_R_COPY="#define PROTO_R_COPY buf, buflen" PROTO_R_COPY_ARGS="#define PROTO_R_COPY_ARGS PROTO_R_ARGS" PROTO_R_OK="#define PROTO_R_OK pptr" +PROTO_R_SETANSWER="#undef PROTO_R_SETANSWER" PROTO_R_RETURN="#define PROTO_R_RETURN struct protoent *" ) AC_SUBST(PROTO_R_ARGS) @@ -1809,6 +1831,7 @@ AC_SUBST(PROTO_R_BAD) AC_SUBST(PROTO_R_COPY) AC_SUBST(PROTO_R_COPY_ARGS) AC_SUBST(PROTO_R_OK) +AC_SUBST(PROTO_R_SETANSWER) AC_SUBST(PROTO_R_RETURN) AC_CHECK_FUNC(endprotoent_r, diff --git a/lib/bind/include/netdb.h b/lib/bind/include/netdb.h index fafd2b640d..c8e5858edc 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.8 2001/07/16 08:05:19 marka Exp $ + * $Id: netdb.h,v 1.9 2001/07/16 08:37:44 marka Exp $ */ #ifndef _NETDB_H_ @@ -470,11 +470,19 @@ struct netent *getnetent_r __P((struct netent *, char *, int)); void setnetent_r __P((int)); void endnetent_r __P((void)); +#ifdef __GLIBC__ +int getprotobyname_r __P((const char *, struct protoent *, char *, + size_t, struct protoent **)); +int getprotobynumber_r __P((int, struct protoent *, char *, size_t, + struct protoent **)); +int getprotoent_r __P((struct protoent *, char *, size_t, struct protoent **)); +#else struct protoent *getprotobyname_r __P((const char *, struct protoent *, char *, int)); struct protoent *getprotobynumber_r __P((int, struct protoent *, char *, int)); struct protoent *getprotoent_r __P((struct protoent *, char *, int)); +#endif void setprotoent_r __P((int)); void endprotoent_r __P((void)); diff --git a/lib/bind/irs/getprotoent_r.c b/lib/bind/irs/getprotoent_r.c index b6d80eb2d1..78b93f8007 100644 --- a/lib/bind/irs/getprotoent_r.c +++ b/lib/bind/irs/getprotoent_r.c @@ -16,7 +16,7 @@ */ #if defined(LIBC_SCCS) && !defined(lint) -static const char rcsid[] = "$Id: getprotoent_r.c,v 1.2 2001/07/15 23:29:46 marka Exp $"; +static const char rcsid[] = "$Id: getprotoent_r.c,v 1.3 2001/07/16 08:37:45 marka Exp $"; #endif /* LIBC_SCCS and not lint */ #include @@ -39,21 +39,41 @@ copy_protoent(struct protoent *, struct protoent *, PROTO_R_COPY_ARGS); PROTO_R_RETURN getprotobyname_r(const char *name, struct protoent *pptr, PROTO_R_ARGS) { struct protoent *pe = getprotobyname(name); +#ifdef PROTO_R_SETANSWER + int n = 0; + if (pe == NULL || (n = copy_protoent(pe, pptr, PROTO_R_COPY)) != 0) + *answerp = NULL; + else + *answerp = pptr; + + return (n); +#else if (pe == NULL) return (PROTO_R_BAD); return (copy_protoent(pe, pptr, PROTO_R_COPY)); +#endif } PROTO_R_RETURN getprotobynumber_r(int proto, struct protoent *pptr, PROTO_R_ARGS) { struct protoent *pe = getprotobynumber(proto); +#ifdef PROTO_R_SETANSWER + int n = 0; + if (pe == NULL || (n = copy_protoent(pe, pptr, PROTO_R_COPY)) != 0) + *answerp = NULL; + else + *answerp = pptr; + + return (n); +#else if (pe == NULL) return (PROTO_R_BAD); return (copy_protoent(pe, pptr, PROTO_R_COPY)); +#endif } /* @@ -65,11 +85,21 @@ getprotobynumber_r(int proto, struct protoent *pptr, PROTO_R_ARGS) { PROTO_R_RETURN getprotoent_r(struct protoent *pptr, PROTO_R_ARGS) { struct protoent *pe = getprotoent(); +#ifdef PROTO_R_SETANSWER + int n = 0; + if (pe == NULL || (n = copy_protoent(pe, pptr, PROTO_R_COPY)) != 0) + *answerp = NULL; + else + *answerp = pptr; + + return (n); +#else if (pe == NULL) return (PROTO_R_BAD); return (copy_protoent(pe, pptr, PROTO_R_COPY)); +#endif } PROTO_R_SET_RETURN @@ -114,7 +144,7 @@ copy_protoent(struct protoent *pe, struct protoent *pptr, PROTO_R_COPY_ARGS) { len += strlen(pe->p_name) + 1; len += numptr * sizeof(char*); - if (len > buflen) { + if (len > (int)buflen) { errno = ERANGE; return (PROTO_R_BAD); } diff --git a/lib/bind/port_before.h.in b/lib/bind/port_before.h.in index 7d89ceb0e4..538d5d52d8 100644 --- a/lib/bind/port_before.h.in +++ b/lib/bind/port_before.h.in @@ -84,6 +84,7 @@ struct timezone; /* silence warning */ @PROTO_R_END_RETURN@ @PROTO_R_ENT_ARGS@ @PROTO_R_OK@ +@PROTO_R_SETANSWER@ @PROTO_R_RETURN@ @PROTO_R_SET_RESULT@ @PROTO_R_SET_RETURN@