fix error returns in gethostby*_r functions
authorRich Felker <dalias@aerifal.cx>
Sat, 2 Feb 2013 06:31:10 +0000 (01:31 -0500)
committerRich Felker <dalias@aerifal.cx>
Sat, 2 Feb 2013 06:31:10 +0000 (01:31 -0500)
they're supposed to return an error code rather than using errno.

src/network/gethostbyaddr_r.c
src/network/gethostbyname2_r.c

index cdb1d50348879772989a90043ee6fa052497af29..73e764474a58a2a13542935df98983c66840add0 100644 (file)
@@ -23,16 +23,13 @@ int gethostbyaddr_r(const void *a, socklen_t l, int af,
        else if (af==AF_INET && l==4) memcpy(&sa.sin.sin_addr, a, 4);
        else {
                *err = NO_RECOVERY;
-               return -1;
+               return EINVAL;
        }
 
        /* Align buffer and check for space for pointers and ip address */
        i = (uintptr_t)buf & sizeof(char *)-1;
        if (!i) i = sizeof(char *);
-       if (buflen <= 5*sizeof(char *)-i + l) {
-               errno = ERANGE;
-               return -1;
-       }
+       if (buflen <= 5*sizeof(char *)-i + l) return ERANGE;
        buf += sizeof(char *)-i;
        buflen -= 5*sizeof(char *)-i + l;
 
@@ -51,15 +48,15 @@ int gethostbyaddr_r(const void *a, socklen_t l, int af,
        switch (getnameinfo((void *)&sa, sl, buf, buflen, 0, 0, 0)) {
        case EAI_AGAIN:
                *err = TRY_AGAIN;
-               return -1;
+               return EAGAIN;
        case EAI_OVERFLOW:
-               errno = ERANGE;
+               return ERANGE;
        default:
        case EAI_MEMORY:
        case EAI_SYSTEM:
        case EAI_FAIL:
                *err = NO_RECOVERY;
-               return -1;
+               return errno;
        case 0:
                break;
        }
index c2ed75b4de77063da8cfa63b7b9b0a40b9eefbc5..49e4e53197d195d83a91ee4605c0cea7e5c8e9fa 100644 (file)
@@ -25,10 +25,7 @@ int gethostbyname2_r(const char *name, int af,
        /* Align buffer */
        i = (uintptr_t)buf & sizeof(char *)-1;
        if (i) {
-               if (buflen < sizeof(char *)-i) {
-                       errno = ERANGE;
-                       return -1;
-               }
+               if (buflen < sizeof(char *)-i) return ERANGE;
                buf += sizeof(char *)-i;
                buflen -= sizeof(char *)-i;
        }
@@ -37,16 +34,16 @@ int gethostbyname2_r(const char *name, int af,
        switch (getaddrinfo(name, 0, &hint, &ai)) {
        case EAI_NONAME:
                *err = HOST_NOT_FOUND;
-               return -1;
+               return errno;
        case EAI_AGAIN:
                *err = TRY_AGAIN;
-               return -1;
+               return errno;
        default:
        case EAI_MEMORY:
        case EAI_SYSTEM:
        case EAI_FAIL:
                *err = NO_RECOVERY;
-               return -1;
+               return errno;
        case 0:
                break;
        }
@@ -63,8 +60,7 @@ int gethostbyname2_r(const char *name, int af,
 
        if (need > buflen) {
                freeaddrinfo(ai);
-               errno = ERANGE;
-               return -1;
+               return ERANGE;
        }
 
        h->h_aliases = (void *)buf;