From df36afa2e69d1d32dc69a41c07abca593a33ef5f Mon Sep 17 00:00:00 2001 From: Jim Meyering Date: Mon, 23 Oct 2006 06:03:01 +0000 Subject: [PATCH] * lib/getaddrinfo.c (getnameinfo): Use new lightweight uinttostr, in place of snprintf. * modules/inttostr (Files): Add lib/uinttostr.c. * lib/uinttostr.c (inttostr): New file/function. * lib/inttostr.h (uinttostr): Declare. * m4/inttostr.m4: Add AC_LIBOBJ([uinttostr]). * MODULES.html.sh (Numeric conversion functions ): Add uinttostr. * modules/getaddrinfo (Depends-on): Remove snprintf. Add inttostr. --- ChangeLog | 13 +++++++++++++ MODULES.html.sh | 1 + lib/getaddrinfo.c | 15 ++++++++++----- lib/inttostr.h | 1 + lib/uinttostr.c | 3 +++ m4/inttostr.m4 | 7 ++++++- modules/getaddrinfo | 4 ++-- modules/inttostr | 1 + 8 files changed, 37 insertions(+), 8 deletions(-) create mode 100644 lib/uinttostr.c diff --git a/ChangeLog b/ChangeLog index a97d6e67dd..190b68a3c4 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,16 @@ +2006-10-23 Jim Meyering + + * lib/getaddrinfo.c (getnameinfo): Use new lightweight uinttostr, + in place of snprintf. + + * modules/inttostr (Files): Add lib/uinttostr.c. + * lib/uinttostr.c (inttostr): New file/function. + * lib/inttostr.h (uinttostr): Declare. + * m4/inttostr.m4: Add AC_LIBOBJ([uinttostr]). + * MODULES.html.sh (Numeric conversion functions ): + Add uinttostr. + * modules/getaddrinfo (Depends-on): Remove snprintf. Add inttostr. + 2006-10-21 Paul Eggert * lib/canonicalize.c (ELOOP): Define if not already defined. diff --git a/MODULES.html.sh b/MODULES.html.sh index 1196121e03..81f1b786a9 100755 --- a/MODULES.html.sh +++ b/MODULES.html.sh @@ -1802,6 +1802,7 @@ func_all_modules () func_begin_table func_module intprops func_module inttostr + func_module uinttostr func_module xstrtoimax func_module xstrtoumax func_end_table diff --git a/lib/getaddrinfo.c b/lib/getaddrinfo.c index ef6fbbc1aa..51cc0335a2 100644 --- a/lib/getaddrinfo.c +++ b/lib/getaddrinfo.c @@ -39,7 +39,7 @@ #define N_(String) String #include "inet_ntop.h" -#include "snprintf.h" +#include "intprops.h" #include "strdup.h" /* BeOS has AF_INET, but not PF_INET. */ @@ -405,10 +405,15 @@ int getnameinfo(const struct sockaddr *restrict sa, socklen_t salen, #if HAVE_IPV6 case AF_INET6: #endif - if (snprintf (service, servicelen, "%d", - ntohs (((const struct sockaddr_in *) sa)->sin_port)) - + 1 > servicelen) - return EAI_OVERFLOW; + { + unsigned short int port + = ntohs (((const struct sockaddr_in *) sa)->sin_port); + char buf[INT_BUFSIZE_BOUND (port)]; + char const *s = uinttostr (port, buf); + if (strlen (s) + 1 > servicelen) + return EAI_OVERFLOW; + memcpy (service, s, strlen (s) + 1); + } break; } diff --git a/lib/inttostr.h b/lib/inttostr.h index 3988a6d337..31258cad35 100644 --- a/lib/inttostr.h +++ b/lib/inttostr.h @@ -27,3 +27,4 @@ char *offtostr (off_t, char *); char *imaxtostr (intmax_t, char *); char *umaxtostr (uintmax_t, char *); +char *uinttostr (unsigned int, char *); diff --git a/lib/uinttostr.c b/lib/uinttostr.c new file mode 100644 index 0000000000..52d288e44e --- /dev/null +++ b/lib/uinttostr.c @@ -0,0 +1,3 @@ +#define inttostr uinttostr +#define inttype unsigned int +#include "inttostr.c" diff --git a/m4/inttostr.m4 b/m4/inttostr.m4 index 4de28f1297..0a41fad731 100644 --- a/m4/inttostr.m4 +++ b/m4/inttostr.m4 @@ -1,4 +1,4 @@ -#serial 6 +#serial 7 dnl Copyright (C) 2004, 2005, 2006 Free Software Foundation, Inc. dnl This file is free software; the Free Software Foundation dnl gives unlimited permission to copy and/or distribute it, @@ -9,11 +9,13 @@ AC_DEFUN([gl_INTTOSTR], AC_LIBOBJ([imaxtostr]) AC_LIBOBJ([offtostr]) AC_LIBOBJ([umaxtostr]) + AC_LIBOBJ([uinttostr]) gl_PREREQ_INTTOSTR gl_PREREQ_IMAXTOSTR gl_PREREQ_OFFTOSTR gl_PREREQ_UMAXTOSTR + gl_PREREQ_UINTTOSTR ]) # Prerequisites of lib/inttostr.h. @@ -30,3 +32,6 @@ AC_DEFUN([gl_PREREQ_OFFTOSTR], [:]) # Prerequisites of lib/umaxtostr.c. AC_DEFUN([gl_PREREQ_UMAXTOSTR], [:]) + +# Prerequisites of lib/uinttostr.c. +AC_DEFUN([gl_PREREQ_UINTTOSTR], [:]) diff --git a/modules/getaddrinfo b/modules/getaddrinfo index ff0d16e898..8f5979db38 100644 --- a/modules/getaddrinfo +++ b/modules/getaddrinfo @@ -9,12 +9,12 @@ m4/getaddrinfo.m4 Depends-on: gettext-h -snprintf +inet_ntop +inttostr socklen stdbool strdup sys_socket -inet_ntop configure.ac: gl_GETADDRINFO diff --git a/modules/inttostr b/modules/inttostr index 658afb0e19..1f031abf8e 100644 --- a/modules/inttostr +++ b/modules/inttostr @@ -7,6 +7,7 @@ lib/inttostr.c lib/inttostr.h lib/offtostr.c lib/umaxtostr.c +lib/uinttostr.c m4/inttostr.m4 Depends-on: -- 2.30.2