Get rid of C++-style comments (even inside "#if 0"/"#endif", the API
[obnox/wireshark/wip.git] / inet_ntop.c
index 19173877c920369a0c8e81f7af036aaf16615421..ab93d69096a1ba0e8e9ff6a0994b2cd297a7c79f 100644 (file)
@@ -1,4 +1,6 @@
 /*
+ * $Id$
+ *
  * Copyright (c) 1996-1999 by Internet Software Consortium.
  *
  * Permission to use, copy, modify, and distribute this software for any
  * SOFTWARE.
  */
 
+
 #ifdef HAVE_CONFIG_H
 #include "config.h"
 #endif
 
-#if defined(LIBC_SCCS) && !defined(lint)
-static char rcsid[] = "$Id$";
-#endif /* LIBC_SCCS and not lint */
-
 #ifdef HAVE_SYS_PARAM_H
 #include <sys/param.h>
 #endif
@@ -127,13 +126,12 @@ inet_ntop4(src, dst, size)
        int nprinted;
 
        nprinted = g_snprintf(tmp, sizeof(tmp), fmt, src[0], src[1], src[2], src[3]);
-       if (nprinted < 0)
-               return (NULL);  /* we assume "errno" was set by "g_snprintf()" */
-       if ((size_t)nprinted > size) {
+        /* Note: nprinted *excludes* the trailing '\0' character */
+       if ((size_t)nprinted >= size) {
                errno = ENOSPC;
                return (NULL);
        }
-       strcpy(dst, tmp);
+       g_strlcpy(dst, tmp, size);
        return (dst);
 }
 
@@ -215,7 +213,7 @@ inet_ntop6(src, dst, size)
                        tp += strlen(tp);
                        break;
                }
-               tp += g_snprintf(tp, sizeof tmp - (tp - tmp), "%x", words[i]);
+               tp += g_snprintf(tp, (gulong) (sizeof tmp - (tp - tmp)), "%x", words[i]);
        }
        /* Was it a trailing run of 0x00's? */
        if (best.base != -1 && (best.base + best.len) ==
@@ -230,6 +228,6 @@ inet_ntop6(src, dst, size)
                errno = ENOSPC;
                return (NULL);
        }
-       strcpy(dst, tmp);
+       g_strlcpy(dst, tmp, size);
        return (dst);
 }