diff options
author | Denis Vlasenko <vda.linux@googlemail.com> | 2008-06-06 07:23:47 +0000 |
---|---|---|
committer | Denis Vlasenko <vda.linux@googlemail.com> | 2008-06-06 07:23:47 +0000 |
commit | c98a59e5a5900982d17f8e3709e940b8bf83bb4b (patch) | |
tree | 3baa5ee15474e95c5a0be7e2374bfd7882c9e9da | |
parent | 5680095d5dc3b040e4ad67da43e3ac7194682361 (diff) |
Fix failure in test/inet/gethost_r-align:
we were closing a FILE, but did not record that fact by setting
a variable to NULL, and then we used it for reading!
While at it, small reduction in bss.
Run tested.
text data bss dec hex filename
- 210 0 12 222 de libc/inet/gethostent.o
+ 230 0 9 239 ef libc/inet/gethostent.o
-rw-r--r-- | libc/inet/resolv.c | 12 |
1 files changed, 8 insertions, 4 deletions
diff --git a/libc/inet/resolv.c b/libc/inet/resolv.c index b799b0d81..4837bf9f7 100644 --- a/libc/inet/resolv.c +++ b/libc/inet/resolv.c @@ -1721,22 +1721,24 @@ int attribute_hidden __read_etc_hosts_r(FILE * fp, const char * name, int type, #ifdef L_gethostent __UCLIBC_MUTEX_STATIC(mylock, PTHREAD_MUTEX_INITIALIZER); -static int __stay_open; +static smallint __stay_open; static FILE * __gethostent_fp; void endhostent(void) { __UCLIBC_MUTEX_LOCK(mylock); __stay_open = 0; - if (__gethostent_fp) + if (__gethostent_fp) { fclose(__gethostent_fp); + __gethostent_fp = NULL; + } __UCLIBC_MUTEX_UNLOCK(mylock); } void sethostent(int stay_open) { __UCLIBC_MUTEX_LOCK(mylock); - __stay_open = stay_open; + __stay_open = (stay_open != 0); __UCLIBC_MUTEX_UNLOCK(mylock); } @@ -1757,8 +1759,10 @@ int gethostent_r(struct hostent *result_buf, char *buf, size_t buflen, ret = __read_etc_hosts_r(__gethostent_fp, NULL, AF_INET, GETHOSTENT, result_buf, buf, buflen, result, h_errnop); - if (__stay_open == 0) + if (__stay_open == 0) { fclose(__gethostent_fp); + __gethostent_fp = NULL; + } DONE: __UCLIBC_MUTEX_UNLOCK(mylock); return ret; |