Commit 47dfc702 authored by Mark Andrews's avatar Mark Andrews

glibc getserv*_r()

parent cabaeca9
......@@ -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 <netdb.h>
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,
......
......@@ -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));
......
......@@ -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 <port_before.h>
......@@ -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);
}
......
......@@ -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@
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment