Module Name: src
Committed By: christos
Date: Sun Aug 25 08:46:34 UTC 2013
Modified Files:
src/distrib/utils/libhack: gethost.c
Log Message:
provide the symbols sethostent.c in libc is missing.
To generate a diff of this commit:
cvs rdiff -u -r1.9 -r1.10 src/distrib/utils/libhack/gethost.c
Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.
Modified files:
Index: src/distrib/utils/libhack/gethost.c
diff -u src/distrib/utils/libhack/gethost.c:1.9 src/distrib/utils/libhack/gethost.c:1.10
--- src/distrib/utils/libhack/gethost.c:1.9 Tue Aug 20 11:44:17 2013
+++ src/distrib/utils/libhack/gethost.c Sun Aug 25 04:46:34 2013
@@ -1,4 +1,4 @@
-/* $NetBSD: gethost.c,v 1.9 2013/08/20 15:44:17 christos Exp $ */
+/* $NetBSD: gethost.c,v 1.10 2013/08/25 08:46:34 christos Exp $ */
/*-
* Copyright (c) 1985, 1988, 1993
@@ -87,11 +87,11 @@ static struct hostent host;
static char *host_aliases[MAXALIASES];
static char hostbuf[BUFSIZ+1];
static struct in_addr host_addr;
-static FILE *hostf = NULL;
-static int stayopen = 0;
-void _sethtent(int);
-void _endhtent(void);
+FILE *_h_file = NULL;
+void sethostent_r(FILE **);
+void endhostent_r(FILE **);
+
struct hostent *_gethtent(void);
struct hostent *_gethtbyname(const char *);
struct hostent *_gethtbyaddr(const void *, socklen_t, int);
@@ -166,21 +166,20 @@ gethostbyaddr(const void *addr, socklen_
}
void
-_sethtent(int f)
+sethostent_r(FILE **hf)
{
- if (hostf == NULL)
- hostf = fopen(_PATH_HOSTS, "r" );
+ if (*hf == NULL)
+ *hf = fopen(_PATH_HOSTS, "r");
else
- rewind(hostf);
- stayopen = f;
+ rewind(*hf);
}
void
-_endhtent(void)
+endhostent_r(FILE **hf)
{
- if (hostf && !stayopen) {
- (void) fclose(hostf);
- hostf = NULL;
+ if (*hf) {
+ (void)fclose(*hf);
+ *hf = NULL;
}
}
@@ -190,10 +189,10 @@ _gethtent(void)
char *p;
char *cp, **q;
- if (hostf == NULL && (hostf = fopen(_PATH_HOSTS, "r" )) == NULL)
+ if (_h_file == NULL && (_h_file = fopen(_PATH_HOSTS, "r" )) == NULL)
return NULL;
again:
- if ((p = fgets(hostbuf, BUFSIZ, hostf)) == NULL)
+ if ((p = fgets(hostbuf, BUFSIZ, _h_file)) == NULL)
return NULL;
if (*p == '#')
goto again;
@@ -239,8 +238,11 @@ _gethtbyname(const char *name)
{
struct hostent *p;
char **cp;
+ FILE *hf = NULL;
- _sethtent(0);
+ sethostent_r(&hf);
+ if (hf == NULL)
+ return NULL;
while ((p = _gethtent()) != NULL) {
if (strcasecmp(p->h_name, name) == 0)
break;
@@ -249,7 +251,7 @@ _gethtbyname(const char *name)
goto found;
}
found:
- _endhtent();
+ endhostent_r(&hf);
if (p == NULL)
h_errno = HOST_NOT_FOUND;
return p;
@@ -259,12 +261,15 @@ struct hostent *
_gethtbyaddr(const void *addr, socklen_t len, int type)
{
struct hostent *p;
-
- _sethtent(0);
+ FILE *hf = NULL;
+
+ sethostent_r(&hf);
+ if (hf == NULL)
+ return NULL;
while ((p = _gethtent()) != NULL)
if (p->h_addrtype == type && !memcmp(p->h_addr, addr, len))
break;
- _endhtent();
+ endhostent_r(&hf);
if (p == NULL)
h_errno = HOST_NOT_FOUND;
return p;