Include <signal.h> in sysdeps/nptl/allocrtsig.c
[platform/upstream/glibc.git] / resolv / inet_net_pton.c
index bf6fe02..14916f8 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 1996 by Internet Software Consortium.
+ * Copyright (c) 1996,1999 by Internet Software Consortium.
  *
  * Permission to use, copy, modify, and distribute this software for any
  * purpose with or without fee is hereby granted, provided that the above
@@ -16,7 +16,7 @@
  */
 
 #if defined(LIBC_SCCS) && !defined(lint)
-static const char rcsid[] = "$Id$";
+static const char rcsid[] = "$BINDId: inet_net_pton.c,v 1.11 1999/01/08 19:23:44 vixie Exp $";
 #endif
 
 #include <sys/types.h>
@@ -37,8 +37,8 @@ static const char rcsid[] = "$Id$";
 # define SPRINTF(x) ((size_t)sprintf x)
 #endif
 
-static int     inet_net_pton_ipv4 __P((const char *src, u_char *dst,
-                                       size_t size));
+static int     inet_net_pton_ipv4 (const char *src, u_char *dst,
+                                   size_t size) __THROW;
 
 /*
  * static int
@@ -81,7 +81,7 @@ inet_net_pton(af, src, dst, size)
  *     not an IPv4 network specification.
  * note:
  *     network byte order assumed.  this means 192.5.5.240/28 has
- *     0x11110000 in its fourth octet.
+ *     0b11110000 in its fourth octet.
  * author:
  *     Paul Vixie (ISC), June 1996
  */
@@ -91,9 +91,7 @@ inet_net_pton_ipv4(src, dst, size)
        u_char *dst;
        size_t size;
 {
-       static const char
-               xdigits[] = "0123456789abcdef",
-               digits[] = "0123456789";
+       static const char xdigits[] = "0123456789abcdef";
        int n, ch, tmp, dirty, bits;
        const u_char *odst = dst;
 
@@ -103,37 +101,42 @@ inet_net_pton_ipv4(src, dst, size)
                /* Hexadecimal: Eat nybble string. */
                if (size <= 0)
                        goto emsgsize;
-               *dst = 0, dirty = 0;
+               dirty = 0;
+               tmp = 0;        /* To calm down gcc.  */
                src++;  /* skip x or X. */
-               while ((ch = *src++) != '\0' &&
-                      isascii(ch) && isxdigit(ch)) {
-                       if (isupper(ch))
-                               ch = tolower(ch);
-                       n = strchr(xdigits, ch) - xdigits;
+               while (isxdigit((ch = *src++))) {
+                       ch = _tolower(ch);
+                       n = (const char *) __rawmemchr(xdigits, ch) - xdigits;
                        assert(n >= 0 && n <= 15);
-                       *dst |= n;
-                       if (!dirty++)
-                               *dst <<= 4;
-                       else if (size-- > 0)
-                               *++dst = 0, dirty = 0;
+                       if (dirty == 0)
+                               tmp = n;
                        else
+                               tmp = (tmp << 4) | n;
+                       if (++dirty == 2) {
+                               if (size-- <= 0)
+                                       goto emsgsize;
+                               *dst++ = (u_char) tmp;
+                               dirty = 0;
+                       }
+               }
+               if (dirty) {  /* Odd trailing nybble? */
+                       if (size-- <= 0)
                                goto emsgsize;
+                       *dst++ = (u_char) (tmp << 4);
                }
-               if (dirty)
-                       size--;
        } else if (isascii(ch) && isdigit(ch)) {
                /* Decimal: eat dotted digit string. */
                for (;;) {
                        tmp = 0;
                        do {
-                               n = strchr(digits, ch) - digits;
+                               n = ((const char *) __rawmemchr(xdigits, ch)
+                                    - xdigits);
                                assert(n >= 0 && n <= 9);
                                tmp *= 10;
                                tmp += n;
                                if (tmp > 255)
                                        goto enoent;
-                       } while ((ch = *src++) != '\0' &&
-                                isascii(ch) && isdigit(ch));
+                       } while (isascii((ch = *src++)) && isdigit(ch));
                        if (size-- <= 0)
                                goto emsgsize;
                        *dst++ = (u_char) tmp;
@@ -154,12 +157,11 @@ inet_net_pton_ipv4(src, dst, size)
                ch = *src++;    /* Skip over the /. */
                bits = 0;
                do {
-                       n = strchr(digits, ch) - digits;
+                       n = (const char *) __rawmemchr(xdigits, ch) - xdigits;
                        assert(n >= 0 && n <= 9);
                        bits *= 10;
                        bits += n;
-               } while ((ch = *src++) != '\0' &&
-                        isascii(ch) && isdigit(ch));
+               } while (isascii((ch = *src++)) && isdigit(ch));
                if (ch != '\0')
                        goto enoent;
                if (bits > 32)