]> granicus.if.org Git - postgresql/blobdiff - src/backend/utils/adt/inet_net_ntop.c
Move some system includes into c.h, and remove duplicates.
[postgresql] / src / backend / utils / adt / inet_net_ntop.c
index d8cd2ff44975c571cb324e2c6be7b251464a405a..c38ecc5a6f2150181052657bc7ad965ce2f3a4e7 100644 (file)
@@ -16,7 +16,7 @@
  */
 
 #if defined(LIBC_SCCS) && !defined(lint)
-static const char rcsid[] = "$Id: inet_net_ntop.c,v 1.4 1999/01/01 04:17:13 momjian Exp $";
+static const char rcsid[] = "$Id: inet_net_ntop.c,v 1.8 1999/07/17 20:17:56 momjian Exp $";
 
 #endif
 
@@ -26,12 +26,9 @@ static const char rcsid[] = "$Id: inet_net_ntop.c,v 1.4 1999/01/01 04:17:13 momj
 #include <arpa/inet.h>
 
 #include <errno.h>
-#include <stdio.h>
-#include <string.h>
-#include <stdlib.h>
 
-#include <postgres.h>
-#include <utils/builtins.h>
+#include "postgres.h"
+#include "utils/builtins.h"
 
 #ifdef SPRINTF_CHAR
 #define SPRINTF(x) strlen(sprintf/**/x)
@@ -40,9 +37,9 @@ static const char rcsid[] = "$Id: inet_net_ntop.c,v 1.4 1999/01/01 04:17:13 momj
 #endif
 
 static char *inet_net_ntop_ipv4(const u_char *src, int bits,
-                                                               char *dst, size_t size);
+                                  char *dst, size_t size);
 static char *inet_cidr_ntop_ipv4(const u_char *src, int bits,
-                                                               char *dst, size_t size);
+                                       char *dst, size_t size);
 
 /*
  * char *
@@ -59,7 +56,7 @@ inet_cidr_ntop(int af, const void *src, int bits, char *dst, size_t size)
 {
        switch (af)
        {
-               case AF_INET:
+                       case AF_INET:
                        return (inet_cidr_ntop_ipv4(src, bits, dst, size));
                default:
                        errno = EAFNOSUPPORT;
@@ -162,7 +159,7 @@ inet_net_ntop(int af, const void *src, int bits, char *dst, size_t size)
 {
        switch (af)
        {
-               case AF_INET:
+                       case AF_INET:
                        return (inet_net_ntop_ipv4(src, bits, dst, size));
                default:
                        errno = EAFNOSUPPORT;
@@ -186,10 +183,11 @@ inet_net_ntop(int af, const void *src, int bits, char *dst, size_t size)
 static char *
 inet_net_ntop_ipv4(const u_char *src, int bits, char *dst, size_t size)
 {
-       char *odst = dst;
-       char *t;
-       size_t len = 4;
-       int b, tb;
+       char       *odst = dst;
+       char       *t;
+       size_t          len = 4;
+       int                     b,
+                               tb;
 
        if (bits < 0 || bits > 32)
        {
@@ -207,7 +205,7 @@ inet_net_ntop_ipv4(const u_char *src, int bits, char *dst, size_t size)
 
        /* Format whole octets plus nonzero trailing octets. */
        tb = (bits == 32) ? 31 : bits;
-       for (b = 0; b <= (tb / 8) || (b < len && *src != 0); b++)
+       for (b = 0; bits != 0 && (b <= (tb / 8) || (b < len && *src != 0)); b++)
        {
                if (size < sizeof "255.")
                        goto emsgsize;
@@ -218,7 +216,7 @@ inet_net_ntop_ipv4(const u_char *src, int bits, char *dst, size_t size)
                        *dst++ = '.';
                        *dst = '\0';
                }
-               size -= (size_t)(dst - t);
+               size -= (size_t) (dst - t);
        }
 
        /* don't print masklen if 32 bits */
@@ -232,7 +230,7 @@ inet_net_ntop_ipv4(const u_char *src, int bits, char *dst, size_t size)
 
        return (odst);
 
- emsgsize:
+emsgsize:
        errno = EMSGSIZE;
        return (NULL);
 }