From c98a59e5a5900982d17f8e3709e940b8bf83bb4b Mon Sep 17 00:00:00 2001 From: Denis Vlasenko Date: Fri, 6 Jun 2008 07:23:47 +0000 Subject: 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 --- libc/inet/resolv.c | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) (limited to 'libc/inet') 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; -- cgit v1.2.3