This is the mail archive of the
libc-alpha@sourceware.org
mailing list for the glibc project.
[PATCH 1/4] getaddrinfo: Remove unnecessary variables and code
- From: Pavel Simerda <psimerda at redhat dot com>
- To: libc-alpha <libc-alpha at sourceware dot org>
- Cc: Siddhesh Poyarekar <siddhesh at redhat dot com>
- Date: Mon, 9 Dec 2013 08:37:18 -0500 (EST)
- Subject: [PATCH 1/4] getaddrinfo: Remove unnecessary variables and code
- Authentication-results: sourceware.org; auth=none
Variable 'end' in getaddrinfo() was only used to compute 'nresults'
which was already computed in gaih_inet() and stored in 'naddrs'.
Variable 'last_i' was used at the end of getaddrinfo() even though
it was always zero.
* sysdeps/posix/getaddrinfo.c (getaddrinfo): Remove unnecessary variables and code.
diff --git a/sysdeps/posix/getaddrinfo.c b/sysdeps/posix/getaddrinfo.c
index 8218237..023fc04 100644
--- a/sysdeps/posix/getaddrinfo.c
+++ b/sysdeps/posix/getaddrinfo.c
@@ -2310,7 +2310,7 @@ int
getaddrinfo (const char *name, const char *service,
const struct addrinfo *hints, struct addrinfo **pai)
{
- int i = 0, last_i = 0;
+ int i = 0;
int nresults = 0;
struct addrinfo *p = NULL;
struct gaih_service gaih_service, *pservice;
@@ -2397,24 +2397,15 @@ getaddrinfo (const char *name, const char *service,
else
pservice = NULL;
- struct addrinfo **end = &p;
-
- unsigned int naddrs = 0;
if (hints->ai_family == AF_UNSPEC || hints->ai_family == AF_INET
|| hints->ai_family == AF_INET6)
{
- last_i = gaih_inet (name, pservice, hints, end, &naddrs);
- if (last_i != 0)
+ int error;
+ if ((error = gaih_inet (name, pservice, hints, &p, &nresults)))
{
freeaddrinfo (p);
__free_in6ai (in6ai);
-
- return -last_i;
- }
- while (*end)
- {
- end = &((*end)->ai_next);
- ++nresults;
+ return -error;
}
}
else
@@ -2423,7 +2414,7 @@ getaddrinfo (const char *name, const char *service,
return EAI_FAMILY;
}
- if (naddrs > 1)
+ if (nresults > 1)
{
/* Read the config file. */
__libc_once_define (static, once);
@@ -2642,7 +2633,7 @@ getaddrinfo (const char *name, const char *service,
return 0;
}
- return last_i ? -last_i : EAI_NONAME;
+ return EAI_NONAME;
}
libc_hidden_def (getaddrinfo)