svn commit: trunk/uClibc/libc/inet

vda at uclibc.org vda at uclibc.org
Fri Jun 6 00:25:14 PDT 2008


Author: vda
Date: 2008-06-06 00:25:12 -0700 (Fri, 06 Jun 2008)
New Revision: 22244

Log:
Use more natural way to return a value in __read_etc_hosts_r:

    text           data     bss     dec     hex filename
-    230              0       9     239      ef libc/inet/gethostent.o
+    224              0       9     233      e9 libc/inet/gethostent.o
-    782              0       0     782     30e libc/inet/read_etc_hosts_r.o
+    767              0       0     767     2ff libc/inet/read_etc_hosts_r.o

Run tested.



Modified:
   trunk/uClibc/libc/inet/resolv.c


Changeset:
Modified: trunk/uClibc/libc/inet/resolv.c
===================================================================
--- trunk/uClibc/libc/inet/resolv.c	2008-06-06 07:23:47 UTC (rev 22243)
+++ trunk/uClibc/libc/inet/resolv.c	2008-06-06 07:25:12 UTC (rev 22244)
@@ -307,7 +307,7 @@
 			      char * buf, size_t buflen,
 			      struct hostent ** result,
 			      int * h_errnop) attribute_hidden;
-extern void __open_etc_hosts(FILE **fp) attribute_hidden;
+extern FILE * __open_etc_hosts(void) attribute_hidden;
 extern int __read_etc_hosts_r(FILE *fp, const char * name, int type,
 			    enum etc_hosts_action action,
 			    struct hostent * result_buf,
@@ -1080,9 +1080,7 @@
 	if ((fp = fopen("/etc/resolv.conf", "r")) ||
 		(fp = fopen("/etc/config/resolv.conf", "r")))
 	{
-
 		while (fgets(szBuffer, sizeof(szBuffer), fp) != NULL) {
-
 			for (p = szBuffer; *p && isspace(*p); p++)
 				/* skip white space */;
 			if (*p == '\0' || *p == '\n' || *p == '#') /* skip comments etc */
@@ -1156,7 +1154,7 @@
 		struct hostent h;
 		char buf[sizeof(struct in_addr) +
 					sizeof(struct in_addr *)*2 +
-					sizeof(char *)*(ALIAS_DIM) + 384/*namebuffer*/ + 32/* margin */];
+					sizeof(char *)*ALIAS_DIM + 384/*namebuffer*/ + 32/* margin */];
 	} *sp;
 	struct hostent *hp;
 
@@ -1180,7 +1178,7 @@
 		struct hostent h;
 		char buf[sizeof(struct in6_addr) +
 					sizeof(struct in6_addr *)*2 +
-					sizeof(char *)*(ALIAS_DIM) + 384/*namebuffer*/ + 32/* margin */];
+					sizeof(char *)*ALIAS_DIM + 384/*namebuffer*/ + 32/* margin */];
 	} *sp;
 	struct hostent *hp;
 
@@ -1531,7 +1529,7 @@
 #else
 			sizeof(struct in6_addr) + sizeof(struct in6_addr *)*2 +
 #endif /* __UCLIBC_HAS_IPV6__ */
-			sizeof(char *)*(ALIAS_DIM) + 384 /*namebuffer*/ + 32 /* margin */];
+			sizeof(char *)*ALIAS_DIM + 384 /*namebuffer*/ + 32 /* margin */];
 	} *sp;
 	struct hostent *hp;
 
@@ -1547,12 +1545,13 @@
 
 #ifdef L_read_etc_hosts_r
 
-void attribute_hidden __open_etc_hosts(FILE **fp)
+FILE * attribute_hidden __open_etc_hosts(void)
 {
-	if ((*fp = fopen("/etc/hosts", "r")) == NULL) {
-		*fp = fopen("/etc/config/hosts", "r");
+	FILE * fp;
+	if ((fp = fopen("/etc/hosts", "r")) == NULL) {
+		fp = fopen("/etc/config/hosts", "r");
 	}
-	return;
+	return fp;
 }
 
 int attribute_hidden __read_etc_hosts_r(FILE * fp, const char * name, int type,
@@ -1580,11 +1579,11 @@
 		buflen -= i;
 	}
 
-	if (buflen < sizeof(char *)*(ALIAS_DIM))
+	if (buflen < sizeof(char *)*ALIAS_DIM)
 		return ERANGE;
 	alias = (char **)buf;
-	buf += sizeof(char **)*(ALIAS_DIM);
-	buflen -= sizeof(char **)*(ALIAS_DIM);
+	buf += sizeof(char **)*ALIAS_DIM;
+	buflen -= sizeof(char **)*ALIAS_DIM;
 
 	if (action != GETHOSTENT) {
 #ifdef __UCLIBC_HAS_IPV6__
@@ -1626,7 +1625,7 @@
 		if (buflen < 80)
 			return ERANGE;
 
-		__open_etc_hosts(&fp);
+		fp = __open_etc_hosts();
 		if (fp == NULL) {
 			result = NULL;
 			return errno;
@@ -1749,7 +1748,7 @@
 
 	__UCLIBC_MUTEX_LOCK(mylock);
 	if (__gethostent_fp == NULL) {
-		__open_etc_hosts(&__gethostent_fp);
+		__gethostent_fp = __open_etc_hosts();
 		if (__gethostent_fp == NULL) {
 			*result = NULL;
 			ret = TRY_AGAIN;
@@ -1779,7 +1778,7 @@
 #else
 			sizeof(struct in6_addr) + sizeof(struct in6_addr *)*2 +
 #endif /* __UCLIBC_HAS_IPV6__ */
-			sizeof(char *)*(ALIAS_DIM) +
+			sizeof(char *)*ALIAS_DIM +
 			80 /*namebuffer*/ + 2 /* margin */];
 	} *sp;
 	struct hostent *host;
@@ -2117,11 +2116,11 @@
 	addr_list[0] = in;
 	addr_list[1] = 0;
 
-	if (buflen < sizeof(char *)*(ALIAS_DIM))
+	if (buflen < sizeof(char *)*ALIAS_DIM)
 		return ERANGE;
 	alias = (char **)buf;
-	buf += sizeof(char **)*(ALIAS_DIM);
-	buflen -= sizeof(char **)*(ALIAS_DIM);
+	buf += sizeof(char **)*ALIAS_DIM;
+	buflen -= sizeof(char **)*ALIAS_DIM;
 
 	if (buflen < 256)
 		return ERANGE;
@@ -2143,7 +2142,6 @@
 	}
 
 	for (;;) {
-
 		__UCLIBC_MUTEX_LOCK(__resolv_lock);
 		__nameserversXX = __nameservers;
 		__nameserverXX = __nameserver;
@@ -2426,11 +2424,11 @@
 	buf += sizeof(*addr_list)*2;
 	buflen -= sizeof(*addr_list)*2;
 
-	if (buflen < sizeof(char *)*(ALIAS_DIM))
+	if (buflen < sizeof(char *)*ALIAS_DIM)
 		return ERANGE;
 	alias = (char **)buf;
-	buf += sizeof(*alias)*(ALIAS_DIM);
-	buflen -= sizeof(*alias)*(ALIAS_DIM);
+	buf += sizeof(*alias)*ALIAS_DIM;
+	buflen -= sizeof(*alias)*ALIAS_DIM;
 
 #ifdef __UCLIBC_HAS_IPV6__
 	if (plen < sizeof(*in6))
@@ -2484,7 +2482,6 @@
 	alias[1] = 0;
 
 	for (;;) {
-
 		__UCLIBC_MUTEX_LOCK(__resolv_lock);
 		__nameserversXX = __nameservers;
 		__nameserverXX = __nameserver;



More information about the uClibc-cvs mailing list