Improve glibc compatibility of gethostby*_r functions.
And add more tests.
Bug: N/A (but I'm here because a recent test broke existing tests)
Test: ran tests
Change-Id: Ib78430f179b43484a49bb50ff447ea6870c1ee3a
diff --git a/libc/dns/net/sethostent.c b/libc/dns/net/sethostent.c
index 66c305f..a743a54 100644
--- a/libc/dns/net/sethostent.c
+++ b/libc/dns/net/sethostent.c
@@ -129,6 +129,9 @@
hp = _hf_gethtbyname2(name, af, info);
#endif
if (hp == NULL) {
+ if (*info->he == NETDB_INTERNAL && errno == ENOSPC) {
+ return NS_UNAVAIL; // glibc compatibility.
+ }
*info->he = HOST_NOT_FOUND;
return NS_NOTFOUND;
}
@@ -171,8 +174,12 @@
hp = netbsd_gethostent_r(hf, info->hp, info->buf, info->buflen,
info->he);
- if (hp == NULL)
+ if (hp == NULL) {
+ if (*info->he == NETDB_INTERNAL && errno == ENOSPC) {
+ goto nospc; // glibc compatibility.
+ }
break;
+ }
if (strcasecmp(hp->h_name, name) != 0) {
char **cp;
@@ -270,6 +277,7 @@
endhostent_r(&hf);
if (hp == NULL) {
+ if (errno == ENOSPC) return NS_UNAVAIL; // glibc compatibility.
*info->he = HOST_NOT_FOUND;
return NS_NOTFOUND;
}