about summary refs log tree commit diff
path: root/src
diff options
context:
space:
mode:
authorRich Felker <dalias@aerifal.cx>2012-07-22 18:49:49 -0400
committerRich Felker <dalias@aerifal.cx>2012-07-22 18:49:49 -0400
commit75fff40b9b536e0e6847d17ecc076894ca7b7068 (patch)
treebd5d843b069cdbb703bc414ef3ab7767191d7ea6 /src
parent68c58223672465202958a5da16f19f64f32acf74 (diff)
downloadmusl-75fff40b9b536e0e6847d17ecc076894ca7b7068.tar.gz
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')
-rw-r--r--src/network/getservbyname_r.c26
-rw-r--r--src/network/getservbyport_r.c28
2 files changed, 35 insertions, 19 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;
diff --git a/src/network/getservbyport_r.c b/src/network/getservbyport_r.c
index 821afae9..a0a7caec 100644
--- a/src/network/getservbyport_r.c
+++ b/src/network/getservbyport_r.c
@@ -15,21 +15,21 @@ int getservbyport_r(int port, const char *prots,
 		.sin_port = port,
 	};
 
-	if (!prots) return -(
-		getservbyport_r(port, "tcp", se, buf, buflen, res)
-		&& getservbyport_r(port, "udp", se, buf, buflen, res) );
+	if (!prots) {
+		int r = getservbyport_r(port, "tcp", se, buf, buflen, res);
+		if (r) r = getservbyport_r(port, "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") && strcmp(prots, "udp")) return -1;
+	if (strcmp(prots, "tcp") && strcmp(prots, "udp")) return EINVAL;
 
 	se->s_port = port;
 	se->s_proto = (char *)prots;
@@ -39,8 +39,16 @@ int getservbyport_r(int port, const char *prots,
 	se->s_aliases[1] = 0;
 	se->s_aliases[0] = se->s_name = buf;
 
-	if (getnameinfo((void *)&sin, sizeof sin, 0, 0, buf, buflen,
-		strcmp(prots, "udp") ? 0 : NI_DGRAM) < 0) return -1;
+	switch (getnameinfo((void *)&sin, sizeof sin, 0, 0, buf, buflen,
+		strcmp(prots, "udp") ? 0 : NI_DGRAM)) {
+	case EAI_MEMORY:
+	case EAI_SYSTEM:
+		return ENOMEM;
+	default:
+		return ENOENT;
+	case 0:
+		break;
+	}
 
 	*res = se;
 	return 0;