[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Bug-gnulib] gnulib imports from coreutils for canon-host, human, xgetcw
From: |
Paul Eggert |
Subject: |
[Bug-gnulib] gnulib imports from coreutils for canon-host, human, xgetcwd |
Date: |
Tue, 16 Nov 2004 23:19:46 -0800 |
I imported the following changes from coreutils into gnulib for the
canon-host, human, and xgetcwd modules. These changes should be
noncontroversial. canon-host is perhaps the closest to the edge,
since it uses getaddrinfo without the getaddrinfo module.
2004-11-16 Paul Eggert <address@hidden>
* lib/canon-host.c: Include "strdup.h".
(canon_host): Use getaddrinfo if available, so that IPv6 works.
Use strdup instead of malloc/strcpy to duplicate strings.
* lib/human.h (LONGEST_HUMAN_READABLE): Add 1 for space before unit.
(human_space_before_unit): New constant.
* human.c (human_readable): Support it.
* lib/xgetcwd.c: Include <limits.h>, for PATH_MAX.
(xgetcwd): Set errno correctly when failing.
Work around Solaris 9 bug: getcwd sets errno==ERANGE even though
the failure is actually due to a PATH_MAX problem.
* m4/canon-host.m4 (gl_CANON_HOST): Check for getaddrinfo.
* modules/canon-host (Depends-on): Add strdup.
2004-11-13 Jim Meyering <address@hidden>
* jm-macros.m4: Do require gl_FUNC_FPENDING.
Index: lib/canon-host.c
===================================================================
RCS file: /cvsroot/gnulib/gnulib/lib/canon-host.c,v
retrieving revision 1.15
diff -p -u -r1.15 canon-host.c
--- lib/canon-host.c 8 Sep 2003 23:18:35 -0000 1.15
+++ lib/canon-host.c 17 Nov 2004 07:13:54 -0000
@@ -1,6 +1,7 @@
/* Host name canonicalization
- Copyright (C) 1995, 1999, 2000, 2002, 2003 Free Software Foundation, Inc.
+ Copyright (C) 1995, 1999, 2000, 2002, 2003, 2004 Free Software
+ Foundation, Inc.
Written by Miles Bader <address@hidden>
@@ -42,55 +43,73 @@
# include <arpa/inet.h>
#endif
+#include "strdup.h"
+
/* Returns the canonical hostname associated with HOST (allocated in a static
- buffer), or 0 if it can't be determined. */
+ buffer), or NULL if it can't be determined. */
char *
-canon_host (const char *host)
+canon_host (char const *host)
{
-#ifdef HAVE_GETHOSTBYNAME
- struct hostent *he = gethostbyname (host);
+ char *h_addr_copy = NULL;
- if (he)
- {
+#if HAVE_GETADDRINFO
+ {
+ struct addrinfo hint = { 0 };
+ struct addrinfo *res = NULL;
+ hint.ai_flags = AI_CANONNAME;
+ if (getaddrinfo (host, NULL, &hint, &res) == 0)
+ {
+ h_addr_copy = strdup (res->ai_canonname);
+ freeaddrinfo (res);
+ }
+ }
+#elif HAVE_GETHOSTBYNAME
+ {
+ struct hostent *he = gethostbyname (host);
+
+ if (he)
+ {
# ifdef HAVE_GETHOSTBYADDR
- char *addr = 0;
+ char *addr = NULL;
- /* Try and get an ascii version of the numeric host address. */
- switch (he->h_addrtype)
- {
+ /* Try and get an ascii version of the numeric host address. */
+ switch (he->h_addrtype)
+ {
# ifdef HAVE_INET_NTOA
- case AF_INET:
- addr = inet_ntoa (*(struct in_addr *) he->h_addr);
- break;
+ case AF_INET:
+ addr = inet_ntoa (*(struct in_addr *) he->h_addr);
+ break;
# endif /* HAVE_INET_NTOA */
- }
+ }
- if (addr && strcmp (he->h_name, addr) == 0)
- {
- /* gethostbyname has returned a string representation of the IP
- address, for example, "127.0.0.1". So now, look up the host
- name via the address. Although it may seem reasonable to look
- up the host name via the address, we must not pass `he->h_addr'
- directly to gethostbyaddr because on some systems he->h_addr
- is located in a static library buffer that is reused in the
- gethostbyaddr call. Make a copy and use that instead. */
- char *h_addr_copy = (char *) malloc (he->h_length);
- if (h_addr_copy == NULL)
- he = NULL;
- else
- {
- memcpy (h_addr_copy, he->h_addr, he->h_length);
- he = gethostbyaddr (h_addr_copy, he->h_length, he->h_addrtype);
- free (h_addr_copy);
- }
- }
+ if (addr && strcmp (he->h_name, addr) == 0)
+ {
+ /* gethostbyname has returned a string representation of the IP
+ address, for example, "127.0.0.1". So now, look up the host
+ name via the address. Although it may seem reasonable to look
+ up the host name via the address, we must not pass `he->h_addr'
+ directly to gethostbyaddr because on some systems he->h_addr
+ is located in a static library buffer that is reused in the
+ gethostbyaddr call. Make a copy and use that instead. */
+ h_addr_copy = (char *) malloc (he->h_length);
+ if (h_addr_copy == NULL)
+ he = NULL;
+ else
+ {
+ memcpy (h_addr_copy, he->h_addr, he->h_length);
+ he = gethostbyaddr (h_addr_copy, he->h_length, he->h_addrtype);
+ free (h_addr_copy);
+ }
+ }
# endif /* HAVE_GETHOSTBYADDR */
- if (he)
- return (char *) (he->h_name);
- }
+ if (he)
+ h_addr_copy = strdup (he->h_name);
+ }
+ }
#endif /* HAVE_GETHOSTBYNAME */
- return 0;
+
+ return h_addr_copy;
}
#ifdef TEST_CANON_HOST
Index: lib/human.c
===================================================================
RCS file: /cvsroot/gnulib/gnulib/lib/human.c,v
retrieving revision 1.25
diff -p -u -r1.25 human.c
--- lib/human.c 7 Aug 2004 00:09:39 -0000 1.25
+++ lib/human.c 17 Nov 2004 07:13:54 -0000
@@ -158,6 +158,9 @@ group_number (char *number, size_t numbe
so on. Numbers smaller than the power aren't modified.
human_autoscale is normally used together with human_SI.
+ If (OPTS & human_space_before_unit), use a space to separate the
+ number from any suffix that is appended as described below.
+
If (OPTS & human_SI), append an SI prefix indicating which power is
being used. If in addition (OPTS & human_B), append "B" (if base
1000) or "iB" (if base 1024) to the SI prefix. When ((OPTS &
@@ -384,6 +387,9 @@ human_readable (uintmax_t n, char *buf,
break;
}
+ if ((exponent | (opts & human_B)) && (opts & human_space_before_unit))
+ *psuffix++ = ' ';
+
if (exponent)
*psuffix++ = (! (opts & human_base_1024) && exponent == 1
? 'k'
Index: lib/human.h
===================================================================
RCS file: /cvsroot/gnulib/gnulib/lib/human.h,v
retrieving revision 1.9
diff -p -u -r1.9 human.h
--- lib/human.h 7 Aug 2004 00:09:39 -0000 1.9
+++ lib/human.h 17 Nov 2004 07:13:54 -0000
@@ -42,10 +42,11 @@
302 / 1000 is ceil (log10 (2.0)). Add 1 for integer division truncation.
Also, the output can have a thousands separator between every digit,
so multiply by MB_LEN_MAX + 1 and then subtract MB_LEN_MAX.
+ Append 1 for a space before the suffix.
Finally, append 3, the maximum length of a suffix. */
# define LONGEST_HUMAN_READABLE \
((2 * sizeof (uintmax_t) * CHAR_BIT * 302 / 1000 + 1) * (MB_LEN_MAX + 1) \
- - MB_LEN_MAX + 3)
+ - MB_LEN_MAX + 1 + 3)
/* Options for human_readable. */
enum
@@ -74,11 +75,14 @@ enum
/* Prefer base 1024 to base 1000. */
human_base_1024 = 32,
+ /* Prepend " " before unit symbol. */
+ human_space_before_unit = 64,
+
/* Append SI prefix, e.g. "k" or "M". */
- human_SI = 64,
+ human_SI = 128,
/* Append "B" (if base 1000) or "iB" (if base 1024) to SI prefix. */
- human_B = 128
+ human_B = 256
};
char *human_readable (uintmax_t, char *, int, uintmax_t, uintmax_t);
Index: lib/xgetcwd.c
===================================================================
RCS file: /cvsroot/gnulib/gnulib/lib/xgetcwd.c,v
retrieving revision 1.16
diff -p -u -r1.16 xgetcwd.c
--- lib/xgetcwd.c 6 Aug 2004 04:55:51 -0000 1.16
+++ lib/xgetcwd.c 17 Nov 2004 07:13:54 -0000
@@ -23,6 +23,7 @@
# include <config.h>
#endif
+#include <limits.h>
#include <stdio.h>
#include <errno.h>
#include <sys/types.h>
@@ -60,6 +61,8 @@ xgetcwd (void)
return cwd;
#else
+ int saved_errno;
+
/* The initial buffer size for the working directory. A power of 2
detects arithmetic overflow earlier, but is not required. */
# ifndef INITIAL_BUFFER_SIZE
@@ -72,16 +75,29 @@ xgetcwd (void)
{
char *buf = xmalloc (buf_size);
char *cwd = getcwd (buf, buf_size);
- int saved_errno;
if (cwd)
return cwd;
saved_errno = errno;
free (buf);
if (saved_errno != ERANGE)
- return NULL;
+ break;
+
+#ifdef PATH_MAX
+ if (PATH_MAX / 2 < buf_size)
+ {
+ if (PATH_MAX <= buf_size)
+ break;
+ buf_size = PATH_MAX;
+ continue;
+ }
+#endif
+
buf_size *= 2;
if (buf_size == 0)
xalloc_die ();
}
+
+ errno = saved_errno;
+ return NULL;
#endif
}
Index: m4/canon-host.m4
===================================================================
RCS file: /cvsroot/gnulib/gnulib/m4/canon-host.m4,v
retrieving revision 1.4
diff -p -u -r1.4 canon-host.m4
--- m4/canon-host.m4 8 Sep 2003 23:18:35 -0000 1.4
+++ m4/canon-host.m4 17 Nov 2004 07:13:54 -0000
@@ -1,5 +1,5 @@
-# canon-host.m4 serial 3
-dnl Copyright (C) 2002, 2003 Free Software Foundation, Inc.
+# canon-host.m4 serial 4
+dnl Copyright (C) 2002, 2003, 2004 Free Software Foundation, Inc.
dnl This file is free software, distributed under the terms of the GNU
dnl General Public License. As a special exception to the GNU General
dnl Public License, this file may be distributed as part of a program
@@ -18,5 +18,5 @@ AC_DEFUN([gl_CANON_HOST],
AC_SEARCH_LIBS(gethostbyname, [inet nsl])
dnl These come from -lnsl on Solaris 2.5.1.
- AC_CHECK_FUNCS(gethostbyname gethostbyaddr inet_ntoa)
+ AC_CHECK_FUNCS(getaddrinfo gethostbyname gethostbyaddr inet_ntoa)
])
Index: m4/jm-macros.m4
===================================================================
RCS file: /cvsroot/gnulib/gnulib/m4/jm-macros.m4,v
retrieving revision 1.153
diff -p -u -r1.153 jm-macros.m4
--- m4/jm-macros.m4 11 Nov 2004 04:58:52 -0000 1.153
+++ m4/jm-macros.m4 17 Nov 2004 07:13:54 -0000
@@ -1,4 +1,4 @@
-#serial 77 -*- autoconf -*-
+#serial 78 -*- autoconf -*-
dnl Misc type-related macros for coreutils.
@@ -59,6 +59,7 @@ AC_DEFUN([gl_MACROS],
AC_REQUIRE([gl_FUNC_GROUP_MEMBER])
AC_REQUIRE([gl_AFS])
AC_REQUIRE([gl_AC_FUNC_LINK_FOLLOWS_SYMLINK])
+ AC_REQUIRE([gl_FUNC_FPENDING])
# This is for od and stat, and any other program that
# uses the PRI.MAX macros from inttypes.h.
Index: modules/canon-host
===================================================================
RCS file: /cvsroot/gnulib/gnulib/modules/canon-host,v
retrieving revision 1.4
diff -p -u -r1.4 canon-host
--- modules/canon-host 22 Sep 2004 15:11:04 -0000 1.4
+++ modules/canon-host 17 Nov 2004 07:13:54 -0000
@@ -7,6 +7,7 @@ lib/canon-host.c
m4/canon-host.m4
Depends-on:
+strdup
configure.ac:
gl_CANON_HOST
@@ -21,4 +22,3 @@ GPL
Maintainer:
Jim Meyering
-
- [Bug-gnulib] gnulib imports from coreutils for canon-host, human, xgetcwd,
Paul Eggert <=
- Re: [Bug-gnulib] gnulib imports from coreutils for canon-host, human, xgetcwd, Bruno Haible, 2004/11/18
- Re: [Bug-gnulib] gnulib imports from coreutils for canon-host, human, xgetcwd, Paul Eggert, 2004/11/18
- Re: [Bug-gnulib] gnulib imports from coreutils for canon-host, human, xgetcwd, Bruno Haible, 2004/11/18
- Re: [Bug-gnulib] gnulib imports from coreutils for canon-host, human, xgetcwd, Jim Meyering, 2004/11/18
- Re: [Bug-gnulib] gnulib imports from coreutils for canon-host, human, xgetcwd, Paul Eggert, 2004/11/19
- Re: [Bug-gnulib] gnulib imports from coreutils for canon-host, human, xgetcwd, Jim Meyering, 2004/11/19
- Re: [Bug-gnulib] gnulib imports from coreutils for canon-host, human, xgetcwd, Paul Eggert, 2004/11/19