diff options
author | Rich Felker <dalias@aerifal.cx> | 2012-07-22 18:49:49 -0400 |
---|---|---|
committer | Rich Felker <dalias@aerifal.cx> | 2012-07-22 18:49:49 -0400 |
commit | 75fff40b9b536e0e6847d17ecc076894ca7b7068 (patch) | |
tree | bd5d843b069cdbb703bc414ef3ab7767191d7ea6 /src/network/getservbyname_r.c | |
parent | 68c58223672465202958a5da16f19f64f32acf74 (diff) | |
download | musl-75fff40b9b536e0e6847d17ecc076894ca7b7068.tar.gz musl-75fff40b9b536e0e6847d17ecc076894ca7b7068.tar.bz2 musl-75fff40b9b536e0e6847d17ecc076894ca7b7068.tar.xz musl-75fff40b9b536e0e6847d17ecc076894ca7b7068.zip |
make getservby*_r return error code rather than -1 (and using errno)
untested but should be correct..
Diffstat (limited to 'src/network/getservbyname_r.c')
-rw-r--r-- | src/network/getservbyname_r.c | 26 |
1 files changed, 17 insertions, 9 deletions
diff --git a/src/network/getservbyname_r.c b/src/network/getservbyname_r.c index efa5d910..811c174c 100644 --- a/src/network/getservbyname_r.c +++ b/src/network/getservbyname_r.c @@ -12,25 +12,33 @@ int getservbyname_r(const char *name, const char *prots, struct addrinfo *ai, hint = { .ai_family = AF_INET }; int i; - if (!prots) return -( - getservbyname_r(name, "tcp", se, buf, buflen, res) - && getservbyname_r(name, "udp", se, buf, buflen, res) ); + if (!prots) { + int r = getservbyname_r(name, "tcp", se, buf, buflen, res); + if (r) r = getservbyname_r(name, "udp", se, buf, buflen, res); + return r; + } /* Align buffer */ i = (uintptr_t)buf & sizeof(char *)-1; if (!i) i = sizeof(char *); - if (buflen < 3*sizeof(char *)-i) { - errno = ERANGE; - return -1; - } + if (buflen < 3*sizeof(char *)-i) + return ERANGE; buf += sizeof(char *)-i; buflen -= sizeof(char *)-i; if (!strcmp(prots, "tcp")) hint.ai_protocol = IPPROTO_TCP; else if (!strcmp(prots, "udp")) hint.ai_protocol = IPPROTO_UDP; - else return -1; + else return EINVAL; - if (getaddrinfo(0, name, &hint, &ai) < 0) return -1; + switch (getaddrinfo(0, name, &hint, &ai)) { + case EAI_MEMORY: + case EAI_SYSTEM: + return ENOMEM; + default: + return ENOENT; + case 0: + break; + } se->s_name = (char *)name; se->s_aliases = (void *)buf; |