summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorPaul Eggert <eggert@cs.ucla.edu>2006-07-04 05:39:07 +0000
committerPaul Eggert <eggert@cs.ucla.edu>2006-07-04 05:39:07 +0000
commit6a9740567292a983b05533901dc7a687ec2fb68c (patch)
tree942771c90c0eff8fc776a1b631e9032e60641ea7 /lib
parent8e19f6282b0621f63b47716bd2eadfb9d466c758 (diff)
downloadcoreutils-6a9740567292a983b05533901dc7a687ec2fb68c.tar.xz
Sync from gnulib.
Diffstat (limited to 'lib')
-rw-r--r--lib/ChangeLog102
-rw-r--r--lib/alloca_.h26
-rw-r--r--lib/base64.c163
-rw-r--r--lib/exclude.c36
-rw-r--r--lib/exclude.h5
-rw-r--r--lib/getaddrinfo.c175
-rw-r--r--lib/getaddrinfo.h43
-rw-r--r--lib/getpass.c8
-rw-r--r--lib/getugroups.c3
-rw-r--r--lib/mbchar.h4
-rw-r--r--lib/mbswidth.c27
-rw-r--r--lib/sha1.c10
-rw-r--r--lib/strtod.c5
-rw-r--r--lib/strtol.c5
-rw-r--r--lib/time_r.c8
-rw-r--r--lib/unicodeio.c6
16 files changed, 450 insertions, 176 deletions
diff --git a/lib/ChangeLog b/lib/ChangeLog
index 6256a606c..c7a74e269 100644
--- a/lib/ChangeLog
+++ b/lib/ChangeLog
@@ -1,5 +1,107 @@
2006-07-03 Paul Eggert <eggert@cs.ucla.edu>
+ * Makefile.am (libcoreutils_a_SOURCES): Add setenv.h, wcwidth.h,
+ to accommodate sync from gnulib.
+
+ Sync from gnulib.
+
+ 2006-06-30 Jim Hyslop <jhyslop@dreampossible.ca> (tiny change)
+
+ * getaddrinfo.c: fixed typo
+
+ 2006-06-28 Bruno Haible <bruno@clisp.org>
+
+ * getaddrinfo.h: Fix POSIX URL.
+ * getaddrinfo.c (WIN32_NATIVE): New macro. Use it instead of _WIN32.
+ (use_win32_p): Make static.
+ (getaddrinfo): Reject service name if it is empty or does not consist
+ solely of decimal digits, or if its value is > 65535.
+ (getnameinfo): Remove useless casts.
+
+ 2006-06-28 Eric Blake <ebb9@byu.net>
+
+ * mbchar.h (wcwidth): Include wcwidth.h.
+ * mbswidth.c (wcwidth): Move from here...
+ * wcwidth.h: ...to this new file.
+
+ 2006-06-28 Simon Josefsson <jas@extundo.com>
+
+ * getaddrinfo.c: Try to load ws2_32.dll on Windows, to find the
+ functions there. It will succeed on Windows XP, but on Windows
+ 2000 and (presumably) earlier, it will fail, and use the internal
+ re-implementation.
+ (use_win32_p): New function.
+ (getaddrinfo): Use strtoul on servname, to support numeric ports.
+ Support AI_NUMERICSERV to disable getservbyname.
+ (getnameinfo): New function, only supports
+ NI_NUMERICHOST|NI_NUMERICSERV for now.
+
+ * getaddrinfo.h: Test and check for AI_* flags separately, MinGW
+ only have some of them. Add AI_NUMERICSERV. Add prototype for
+ getnameinfo.
+
+ 2006-06-26 Paul Eggert <eggert@cs.ucla.edu>
+
+ * base64.c (B64): Use _ as the formal parameter, not x, to avoid
+ bug in IBM C V6 for AIX. Problem reported by Larry Jones in
+ <http://lists.gnu.org/archive/html/bug-gnulib/2006-06/msg00181.html>.
+
+ 2006-06-21 Simon Josefsson <jas@extundo.com>
+
+ * getaddrinfo.c (getaddrinfo): Set ai_family in the return
+ variable.
+
+ 2006-06-19 Paul Eggert <eggert@cs.ucla.edu>
+
+ * alloca_.h (alloca) [defined alloca]: Don't define or declare.
+
+ 2006-06-16 Eric Blake <ebb9@byu.net>
+
+ * unsetenv.c [!defined errno]: Assume errno.h declares errno.
+ * unicodeio.c [!defined errno]: Likewise.
+ * strtol.c [!defined errno]: Likewise.
+ * strtod.c [!defined errno]: Likewise.
+
+ 2006-05-26 Martin Lambers <marlam@marlam.de>
+
+ * getpass.c: Updates the test for the native W32 API, and adds
+ missing includes, thus fixing compilation warnings.
+
+ 2006-05-25 Sergey Poznyakoff <gray@gnu.org.ua>
+
+ * exclude.c (exclude_fnmatch): New function.
+ (excluded_file_name): Call exclude_fnmatch.
+ * exclude.h (excluded_file_name): New prototype
+
+ 2006-05-19 Jim Meyering <jim@meyering.net>
+
+ * getugroups.c: Correct an outdated comment. From Bruno Haible.
+
+ 2006-05-10 Paul Eggert <eggert@cs.ucla.edu>
+
+ * sha1.c (rol): Cast right-shift arg to uint32_t to prevent
+ unwanted sign propagation, e.g., on hosts with 64-bit int.
+ There still are some problems with reeelly weird theoretical hosts
+ (e.g., 33-bit int) but it's not worth worrying about now.
+ (K1, K2, K3, K4): Remove unnecessary L suffix.
+
+ 2006-03-24 Simon Josefsson <jas@extundo.com>
+
+ * base64.c: Fix problems reported by Eric Blake <ebb9@byu.net>,
+ including some doc fixes.
+ (base64_encode_alloc): Fix +1 bug on allocation failures.
+
+ 2006-03-24 Ralf Wildenhues <Ralf.Wildenhues@gmx.de>
+
+ * base64.c (base64_encode): Do not read past end of array with
+ unsanitized input on systems with CHAR_BIT > 8.
+
+ 2006-03-24 Eric Blake <ebb9@byu.net>
+
+ * time_r.c (copy_string_result): Remove, as it is no longer used.
+
+2006-07-03 Paul Eggert <eggert@cs.ucla.edu>
+
* stdint_.h: Include <sys/types.h> after @FULL_PATH_STDINT_H@, for
MacOS X 10.4.6. Don't mention <sys/int_types.h>. Problems
reported by Mark D. Baushke, one in
diff --git a/lib/alloca_.h b/lib/alloca_.h
index 3e3fdf43f..dd0b3e98f 100644
--- a/lib/alloca_.h
+++ b/lib/alloca_.h
@@ -1,6 +1,6 @@
/* Memory allocation on the stack.
- Copyright (C) 1995, 1999, 2001, 2002, 2003, 2004 Free Software
+ Copyright (C) 1995, 1999, 2001, 2002, 2003, 2004, 2006 Free Software
Foundation, Inc.
This program is free software; you can redistribute it and/or modify it
@@ -34,19 +34,21 @@
request, the program just crashes.
*/
-#ifdef __GNUC__
-# define alloca __builtin_alloca
-#elif defined _AIX
-# define alloca __alloca
-#elif defined _MSC_VER
-# include <malloc.h>
-# define alloca _alloca
-#else
-# include <stddef.h>
-# ifdef __cplusplus
+#ifndef alloca
+# ifdef __GNUC__
+# define alloca __builtin_alloca
+# elif defined _AIX
+# define alloca __alloca
+# elif defined _MSC_VER
+# include <malloc.h>
+# define alloca _alloca
+# else
+# include <stddef.h>
+# ifdef __cplusplus
extern "C"
-# endif
+# endif
void *alloca (size_t);
+# endif
#endif
#endif /* _GNULIB_ALLOCA_H */
diff --git a/lib/base64.c b/lib/base64.c
index 2a68952d7..3316d1c12 100644
--- a/lib/base64.c
+++ b/lib/base64.c
@@ -1,5 +1,6 @@
/* base64.c -- Encode binary data using printable characters.
- Copyright (C) 1999, 2000, 2001, 2004, 2005, 2006 Free Software Foundation, Inc.
+ Copyright (C) 1999, 2000, 2001, 2004, 2005, 2006 Free Software
+ Foundation, Inc.
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
@@ -73,7 +74,7 @@ base64_encode (const char *restrict in, size_t inlen,
while (inlen && outlen)
{
- *out++ = b64str[to_uchar (in[0]) >> 2];
+ *out++ = b64str[(to_uchar (in[0]) >> 2) & 0x3f];
if (!--outlen)
break;
*out++ = b64str[((to_uchar (in[0]) << 4)
@@ -108,8 +109,8 @@ base64_encode (const char *restrict in, size_t inlen,
return, the OUT variable will hold a pointer to newly allocated
memory that must be deallocated by the caller. If output string
length would overflow, 0 is returned and OUT is set to NULL. If
- memory allocation fail, OUT is set to NULL, and the return value
- indicate length of the requested memory block, i.e.,
+ memory allocation failed, OUT is set to NULL, and the return value
+ indicates length of the requested memory block, i.e.,
BASE64_LENGTH(inlen) + 1. */
size_t
base64_encode_alloc (const char *in, size_t inlen, char **out)
@@ -135,8 +136,10 @@ base64_encode_alloc (const char *in, size_t inlen, char **out)
}
*out = malloc (outlen);
- if (*out)
- base64_encode (in, inlen, *out, outlen);
+ if (!*out)
+ return outlen;
+
+ base64_encode (in, inlen, *out, outlen);
return outlen - 1;
}
@@ -146,72 +149,75 @@ base64_encode_alloc (const char *in, size_t inlen, char **out)
Base64 alphabet (A-Za-z0-9+/) are encoded in 0..255. POSIX
1003.1-2001 require that char and unsigned char are 8-bit
quantities, though, taking care of that problem. But this may be a
- potential problem on non-POSIX C99 platforms. */
-#define B64(x) \
- ((x) == 'A' ? 0 \
- : (x) == 'B' ? 1 \
- : (x) == 'C' ? 2 \
- : (x) == 'D' ? 3 \
- : (x) == 'E' ? 4 \
- : (x) == 'F' ? 5 \
- : (x) == 'G' ? 6 \
- : (x) == 'H' ? 7 \
- : (x) == 'I' ? 8 \
- : (x) == 'J' ? 9 \
- : (x) == 'K' ? 10 \
- : (x) == 'L' ? 11 \
- : (x) == 'M' ? 12 \
- : (x) == 'N' ? 13 \
- : (x) == 'O' ? 14 \
- : (x) == 'P' ? 15 \
- : (x) == 'Q' ? 16 \
- : (x) == 'R' ? 17 \
- : (x) == 'S' ? 18 \
- : (x) == 'T' ? 19 \
- : (x) == 'U' ? 20 \
- : (x) == 'V' ? 21 \
- : (x) == 'W' ? 22 \
- : (x) == 'X' ? 23 \
- : (x) == 'Y' ? 24 \
- : (x) == 'Z' ? 25 \
- : (x) == 'a' ? 26 \
- : (x) == 'b' ? 27 \
- : (x) == 'c' ? 28 \
- : (x) == 'd' ? 29 \
- : (x) == 'e' ? 30 \
- : (x) == 'f' ? 31 \
- : (x) == 'g' ? 32 \
- : (x) == 'h' ? 33 \
- : (x) == 'i' ? 34 \
- : (x) == 'j' ? 35 \
- : (x) == 'k' ? 36 \
- : (x) == 'l' ? 37 \
- : (x) == 'm' ? 38 \
- : (x) == 'n' ? 39 \
- : (x) == 'o' ? 40 \
- : (x) == 'p' ? 41 \
- : (x) == 'q' ? 42 \
- : (x) == 'r' ? 43 \
- : (x) == 's' ? 44 \
- : (x) == 't' ? 45 \
- : (x) == 'u' ? 46 \
- : (x) == 'v' ? 47 \
- : (x) == 'w' ? 48 \
- : (x) == 'x' ? 49 \
- : (x) == 'y' ? 50 \
- : (x) == 'z' ? 51 \
- : (x) == '0' ? 52 \
- : (x) == '1' ? 53 \
- : (x) == '2' ? 54 \
- : (x) == '3' ? 55 \
- : (x) == '4' ? 56 \
- : (x) == '5' ? 57 \
- : (x) == '6' ? 58 \
- : (x) == '7' ? 59 \
- : (x) == '8' ? 60 \
- : (x) == '9' ? 61 \
- : (x) == '+' ? 62 \
- : (x) == '/' ? 63 \
+ potential problem on non-POSIX C99 platforms.
+
+ IBM C V6 for AIX mishandles "#define B64(x) ...'x'...", so use "_"
+ as the formal parameter rather than "x". */
+#define B64(_) \
+ ((_) == 'A' ? 0 \
+ : (_) == 'B' ? 1 \
+ : (_) == 'C' ? 2 \
+ : (_) == 'D' ? 3 \
+ : (_) == 'E' ? 4 \
+ : (_) == 'F' ? 5 \
+ : (_) == 'G' ? 6 \
+ : (_) == 'H' ? 7 \
+ : (_) == 'I' ? 8 \
+ : (_) == 'J' ? 9 \
+ : (_) == 'K' ? 10 \
+ : (_) == 'L' ? 11 \
+ : (_) == 'M' ? 12 \
+ : (_) == 'N' ? 13 \
+ : (_) == 'O' ? 14 \
+ : (_) == 'P' ? 15 \
+ : (_) == 'Q' ? 16 \
+ : (_) == 'R' ? 17 \
+ : (_) == 'S' ? 18 \
+ : (_) == 'T' ? 19 \
+ : (_) == 'U' ? 20 \
+ : (_) == 'V' ? 21 \
+ : (_) == 'W' ? 22 \
+ : (_) == 'X' ? 23 \
+ : (_) == 'Y' ? 24 \
+ : (_) == 'Z' ? 25 \
+ : (_) == 'a' ? 26 \
+ : (_) == 'b' ? 27 \
+ : (_) == 'c' ? 28 \
+ : (_) == 'd' ? 29 \
+ : (_) == 'e' ? 30 \
+ : (_) == 'f' ? 31 \
+ : (_) == 'g' ? 32 \
+ : (_) == 'h' ? 33 \
+ : (_) == 'i' ? 34 \
+ : (_) == 'j' ? 35 \
+ : (_) == 'k' ? 36 \
+ : (_) == 'l' ? 37 \
+ : (_) == 'm' ? 38 \
+ : (_) == 'n' ? 39 \
+ : (_) == 'o' ? 40 \
+ : (_) == 'p' ? 41 \
+ : (_) == 'q' ? 42 \
+ : (_) == 'r' ? 43 \
+ : (_) == 's' ? 44 \
+ : (_) == 't' ? 45 \
+ : (_) == 'u' ? 46 \
+ : (_) == 'v' ? 47 \
+ : (_) == 'w' ? 48 \
+ : (_) == 'x' ? 49 \
+ : (_) == 'y' ? 50 \
+ : (_) == 'z' ? 51 \
+ : (_) == '0' ? 52 \
+ : (_) == '1' ? 53 \
+ : (_) == '2' ? 54 \
+ : (_) == '3' ? 55 \
+ : (_) == '4' ? 56 \
+ : (_) == '5' ? 57 \
+ : (_) == '6' ? 58 \
+ : (_) == '7' ? 59 \
+ : (_) == '8' ? 60 \
+ : (_) == '9' ? 61 \
+ : (_) == '+' ? 62 \
+ : (_) == '/' ? 63 \
: -1)
static const signed char b64[0x100] = {
@@ -287,6 +293,9 @@ static const signed char b64[0x100] = {
# define uchar_in_range(c) ((c) <= 255)
#endif
+/* Return true if CH is a character from the Base64 alphabet, and
+ false otherwise. Note that '=' is padding and not considered to be
+ part of the alphabet. */
bool
isbase64 (char ch)
{
@@ -299,7 +308,9 @@ isbase64 (char ch)
otherwise. If *OUTLEN is too small, as many bytes as possible will
be written to OUT. On return, *OUTLEN holds the length of decoded
bytes in OUT. Note that as soon as any non-alphabet characters are
- encountered, decoding is stopped and false is returned. */
+ encountered, decoding is stopped and false is returned. This means
+ that, when applicable, you must remove any line terminators that is
+ part of the data stream before calling this function. */
bool
base64_decode (const char *restrict in, size_t inlen,
char *restrict out, size_t *outlen)
@@ -381,11 +392,11 @@ base64_decode (const char *restrict in, size_t inlen,
size of the decoded data is stored in *OUTLEN. OUTLEN may be NULL,
if the caller is not interested in the decoded length. *OUT may be
NULL to indicate an out of memory error, in which case *OUTLEN
- contain the size of the memory block needed. The function return
+ contains the size of the memory block needed. The function returns
true on successful decoding and memory allocation errors. (Use the
*OUT and *OUTLEN parameters to differentiate between successful
- decoding and memory error.) The function return false if the input
- was invalid, in which case *OUT is NULL and *OUTLEN is
+ decoding and memory error.) The function returns false if the
+ input was invalid, in which case *OUT is NULL and *OUTLEN is
undefined. */
bool
base64_decode_alloc (const char *in, size_t inlen, char **out,
diff --git a/lib/exclude.c b/lib/exclude.c
index 6a0c14974..6bd7339f4 100644
--- a/lib/exclude.c
+++ b/lib/exclude.c
@@ -1,7 +1,7 @@
/* exclude.c -- exclude file names
Copyright (C) 1992, 1993, 1994, 1997, 1999, 2000, 2001, 2002, 2003,
- 2004, 2005 Free Software Foundation, Inc.
+ 2004, 2005, 2006 Free Software Foundation, Inc.
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
@@ -129,6 +129,24 @@ fnmatch_no_wildcards (char const *pattern, char const *f, int options)
}
}
+bool
+exclude_fnmatch (char const *pattern, char const *f, int options)
+{
+ int (*matcher) (char const *, char const *, int) =
+ (options & EXCLUDE_WILDCARDS
+ ? fnmatch
+ : fnmatch_no_wildcards);
+ bool matched = ((*matcher) (pattern, f, options) == 0);
+ char const *p;
+
+ if (! (options & EXCLUDE_ANCHORED))
+ for (p = f; *p && ! matched; p++)
+ if (*p == '/' && p[1] != '/')
+ matched = ((*matcher) (pattern, p + 1, options) == 0);
+
+ return matched;
+}
+
/* Return true if EX excludes F. */
bool
@@ -154,21 +172,7 @@ excluded_file_name (struct exclude const *ex, char const *f)
char const *pattern = exclude[i].pattern;
int options = exclude[i].options;
if (excluded == !! (options & EXCLUDE_INCLUDE))
- {
- int (*matcher) (char const *, char const *, int) =
- (options & EXCLUDE_WILDCARDS
- ? fnmatch
- : fnmatch_no_wildcards);
- bool matched = ((*matcher) (pattern, f, options) == 0);
- char const *p;
-
- if (! (options & EXCLUDE_ANCHORED))
- for (p = f; *p && ! matched; p++)
- if (*p == '/' && p[1] != '/')
- matched = ((*matcher) (pattern, p + 1, options) == 0);
-
- excluded ^= matched;
- }
+ excluded ^= exclude_fnmatch (pattern, f, options);
}
return excluded;
diff --git a/lib/exclude.h b/lib/exclude.h
index 6923efa5f..203e38485 100644
--- a/lib/exclude.h
+++ b/lib/exclude.h
@@ -1,7 +1,7 @@
/* exclude.h -- declarations for excluding file names
- Copyright (C) 1992, 1993, 1994, 1997, 1999, 2001, 2002, 2003, 2005
- Free Software Foundation, Inc.
+ Copyright (C) 1992, 1993, 1994, 1997, 1999, 2001, 2002, 2003, 2005,
+ 2006 Free Software Foundation, Inc.
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
@@ -41,3 +41,4 @@ void add_exclude (struct exclude *, char const *, int);
int add_exclude_file (void (*) (struct exclude *, char const *, int),
struct exclude *, char const *, int, char);
bool excluded_file_name (struct exclude const *, char const *);
+bool exclude_fnmatch (char const *pattern, char const *f, int options);
diff --git a/lib/getaddrinfo.c b/lib/getaddrinfo.c
index 7ea696778..2cba44387 100644
--- a/lib/getaddrinfo.c
+++ b/lib/getaddrinfo.c
@@ -1,5 +1,5 @@
/* Get address information (partial implementation).
- Copyright (C) 1997, 2001, 2002, 2004, 2005 Free Software Foundation, Inc.
+ Copyright (C) 1997, 2001, 2002, 2004, 2005, 2006 Free Software Foundation, Inc.
Contributed by Simon Josefsson <simon@josefsson.org>.
This program is free software; you can redistribute it and/or modify
@@ -40,6 +40,56 @@
#include "strdup.h"
+#if defined _WIN32 || defined __WIN32__
+# define WIN32_NATIVE
+#endif
+
+#ifdef WIN32_NATIVE
+typedef int WSAAPI (*getaddrinfo_func) (const char*, const char*,
+ const struct addrinfo*,
+ struct addrinfo**);
+typedef void WSAAPI (*freeaddrinfo_func) (struct addrinfo*);
+typedef int WSAAPI (*getnameinfo_func) (const struct sockaddr*,
+ socklen_t, char*, DWORD,
+ char*, DWORD, int);
+
+static getaddrinfo_func getaddrinfo_ptr = NULL;
+static freeaddrinfo_func freeaddrinfo_ptr = NULL;
+static getnameinfo_func getnameinfo_ptr = NULL;
+
+static int
+use_win32_p (void)
+{
+ static int done = 0;
+ HMODULE h;
+
+ if (done)
+ return getaddrinfo_ptr ? 1 : 0;
+
+ done = 1;
+
+ h = GetModuleHandle ("ws2_32.dll");
+
+ if (h)
+ {
+ getaddrinfo_ptr = GetProcAddress (h, "getaddrinfo");
+ freeaddrinfo_ptr = GetProcAddress (h, "freeaddrinfo");
+ getnameinfo_ptr = GetProcAddress (h, "getnameinfo");
+ }
+
+ /* If either is missing, something is odd. */
+ if (!getaddrinfo_ptr || !freeaddrinfo_ptr || !getnameinfo_ptr)
+ {
+ getaddrinfo_ptr = NULL;
+ freeaddrinfo_ptr = NULL;
+ getnameinfo_ptr = NULL;
+ return 0;
+ }
+
+ return 1;
+}
+#endif
+
static inline bool
validate_family (int family)
{
@@ -66,7 +116,7 @@ getaddrinfo (const char *restrict nodename,
struct addrinfo **restrict res)
{
struct addrinfo *tmp;
- struct servent *se = NULL;
+ int port = 0;
struct hostent *he;
void *storage;
size_t size;
@@ -83,6 +133,11 @@ getaddrinfo (const char *restrict nodename,
};
#endif
+#ifdef WIN32_NATIVE
+ if (use_win32_p ())
+ return getaddrinfo_ptr (nodename, servname, hints, res);
+#endif
+
if (hints && (hints->ai_flags & ~AI_CANONNAME))
/* FIXME: Support more flags. */
return EAI_BADFLAGS;
@@ -101,14 +156,26 @@ getaddrinfo (const char *restrict nodename,
if (servname)
{
+ struct servent *se = NULL;
const char *proto =
(hints && hints->ai_socktype == SOCK_DGRAM) ? "udp" : "tcp";
- /* FIXME: Use getservbyname_r if available. */
- se = getservbyname (servname, proto);
+ if (!(hints->ai_flags & AI_NUMERICSERV))
+ /* FIXME: Use getservbyname_r if available. */
+ se = getservbyname (servname, proto);
if (!se)
- return EAI_SERVICE;
+ {
+ char *c;
+ if (!(*servname >= '0' && *servname <= '9'))
+ return EAI_NONAME;
+ port = strtoul (servname, &c, 10);
+ if (*c || port > 0xffff)
+ return EAI_NONAME;
+ port = htons (port);
+ }
+ else
+ port = se->s_port;
}
/* FIXME: Use gethostbyname_r if available. */
@@ -147,8 +214,8 @@ getaddrinfo (const char *restrict nodename,
struct sockaddr_in6 *sinp = &p->sockaddr_in6;
tmp = &p->addrinfo;
- if (se)
- sinp->sin6_port = se->s_port;
+ if (port)
+ sinp->sin6_port = port;
if (he->h_length != sizeof (sinp->sin6_addr))
{
@@ -171,8 +238,8 @@ getaddrinfo (const char *restrict nodename,
struct sockaddr_in *sinp = &p->sockaddr_in;
tmp = &p->addrinfo;
- if (se)
- sinp->sin_port = se->s_port;
+ if (port)
+ sinp->sin_port = port;
if (he->h_length != sizeof (sinp->sin_addr))
{
@@ -212,6 +279,7 @@ getaddrinfo (const char *restrict nodename,
tmp->ai_protocol = (hints) ? hints->ai_protocol : 0;
tmp->ai_socktype = (hints) ? hints->ai_socktype : 0;
tmp->ai_addr->sa_family = he->h_addrtype;
+ tmp->ai_family = he->h_addrtype;
/* FIXME: If more than one address, create linked list of addrinfo's. */
@@ -224,6 +292,11 @@ getaddrinfo (const char *restrict nodename,
void
freeaddrinfo (struct addrinfo *ai)
{
+#ifdef WIN32_NATIVE
+ if (use_win32_p ())
+ return freeaddrinfo_ptr (ai);
+#endif
+
while (ai)
{
struct addrinfo *cur;
@@ -235,3 +308,87 @@ freeaddrinfo (struct addrinfo *ai)
free (cur);
}
}
+
+int getnameinfo(const struct sockaddr *restrict sa, socklen_t salen,
+ char *restrict node, socklen_t nodelen,
+ char *restrict service, socklen_t servicelen,
+ int flags)
+{
+#if WIN32_NATIVE
+ if (use_win32_p ())
+ return getnameinfo_ptr (sa, salen, node, nodelen,
+ service, servicelen, flags);
+#endif
+
+ /* FIXME: Support other flags. */
+ if ((node && nodelen > 0 && !(flags & NI_NUMERICHOST)) ||
+ (service && servicelen > 0 && !(flags & NI_NUMERICHOST)) ||
+ (flags & ~(NI_NUMERICHOST|NI_NUMERICSERV)))
+ return EAI_BADFLAGS;
+
+ if (sa == NULL || salen < sizeof (sa->sa_family))
+ return EAI_FAMILY;
+
+ switch (sa->sa_family)
+ {
+#if HAVE_IPV4
+ case AF_INET:
+ if (salen < sizeof (struct sockaddr_in))
+ return EAI_FAMILY;
+ break;
+#endif
+#if HAVE_IPV6
+ case AF_INET6:
+ if (salen < sizeof (struct sockaddr_in6))
+ return EAI_FAMILY;
+ break;
+#endif
+ default:
+ return EAI_FAMILY;
+ }
+
+ if (node && nodelen > 0 && flags & NI_NUMERICHOST)
+ {
+ switch (sa->sa_family)
+ {
+#if HAVE_IPV4
+ case AF_INET:
+ if (!inet_ntop (AF_INET,
+ &(((const struct sockaddr_in *) sa)->sin_addr),
+ node, nodelen))
+ return EAI_SYSTEM;
+ break;
+#endif
+
+#if HAVE_IPV6
+ case AF_INET6:
+ if (!inet_ntop (AF_INET6,
+ &(((const struct sockaddr_in6 *) sa)->sin6_addr),
+ node, nodelen))
+ return EAI_SYSTEM;
+ break;
+#endif
+
+ default:
+ return EAI_FAMILY;
+ }
+ }
+
+ if (service && servicelen > 0 && flags & NI_NUMERICSERV)
+ switch (sa->sa_family)
+ {
+#if HAVE_IPV4
+ case AF_INET:
+#endif
+#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;
+ break;
+ }
+
+ return 0;
+}
diff --git a/lib/getaddrinfo.h b/lib/getaddrinfo.h
index 7722c14ba..bbf71f22e 100644
--- a/lib/getaddrinfo.h
+++ b/lib/getaddrinfo.h
@@ -48,13 +48,26 @@ struct addrinfo
/* Possible values for `ai_flags' field in `addrinfo' structure. */
# ifndef AI_PASSIVE
-# define AI_PASSIVE 0x0001 /* Socket address is intended for `bind'. */
-# define AI_CANONNAME 0x0002 /* Request for canonical name. */
+# define AI_PASSIVE 0x0001 /* Socket address is intended for `bind'. */
+# endif
+# ifndef AI_CANONNAME
+# define AI_CANONNAME 0x0002 /* Request for canonical name. */
+# endif
+# ifndef AI_NUMERICHOST
# define AI_NUMERICHOST 0x0004 /* Don't use name resolution. */
-# define AI_V4MAPPED 0x0008 /* IPv4 mapped addresses are acceptable. */
-# define AI_ALL 0x0010 /* Return IPv4 mapped and IPv6 addresses. */
-# define AI_ADDRCONFIG 0x0020 /* Use configuration of this host to choose
+# endif
+# ifndef AI_V4MAPPED
+# define AI_V4MAPPED 0x0008 /* IPv4 mapped addresses are acceptable. */
+# endif
+# ifndef AI_ALL
+# define AI_ALL 0x0010 /* Return IPv4 mapped and IPv6 addresses. */
+# endif
+# ifndef AI_ADDRCONFIG
+# define AI_ADDRCONFIG 0x0020 /* Use configuration of this host to choose
returned address type.. */
+#endif
+#ifndef AI_NUMERICSERV
+# define AI_NUMERICSERV 0x0400 /* Don't use name resolution. */
# endif
/* Error values for `getaddrinfo' function. */
@@ -68,16 +81,17 @@ struct addrinfo
# define EAI_SOCKTYPE -7 /* `ai_socktype' not supported. */
# define EAI_SERVICE -8 /* SERVICE not supported for `ai_socktype'. */
# define EAI_MEMORY -10 /* Memory allocation failure. */
+#endif
+#ifndef EAI_OVERFLOW
+/* Not defined on mingw32. */
# define EAI_OVERFLOW -12 /* Argument buffer overflow. */
#endif
# ifndef EAI_ADDRFAMILY
-/* Not defined on mingw32. XXX May be incorrect? Perhaps it is never
- returned? */
+/* Not defined on mingw32. */
# define EAI_ADDRFAMILY -9 /* Address family for NAME not supported. */
# endif
# ifndef EAI_SYSTEM
-/* Not defined on mingw32. XXX May be incorrect? Perhaps it is never
- returned? */
+/* Not defined on mingw32. */
# define EAI_SYSTEM -11 /* System error returned in `errno'. */
# endif
@@ -117,4 +131,15 @@ extern void freeaddrinfo (struct addrinfo *ai);
extern const char *gai_strerror (int ecode);
# endif
+# if !HAVE_DECL_GETNAMEINFO
+/* Convert socket address to printable node and service names.
+ For more details, see the POSIX:2001 specification
+ <http://www.opengroup.org/susv3xsh/getnameinfo.html>. */
+extern int getnameinfo(const struct sockaddr *restrict sa, socklen_t salen,
+ char *restrict node, socklen_t nodelen,
+ char *restrict service, socklen_t servicelen,
+ int flags);
+
+# endif
+
#endif /* GETADDRINFO_H */
diff --git a/lib/getpass.c b/lib/getpass.c
index f0b3184ee..4e3339659 100644
--- a/lib/getpass.c
+++ b/lib/getpass.c
@@ -23,7 +23,7 @@
#include <stdio.h>
-#if !defined _WIN32
+#if !((defined _WIN32 || defined __WIN32__) && !defined __CYGWIN__)
#include <stdbool.h>
@@ -170,13 +170,17 @@ getpass (const char *prompt)
return buf;
}
-#else /* WIN32 */
+#else /* W32 native */
/* Windows implementation by Martin Lambers <marlam@marlam.de>,
improved by Simon Josefsson. */
/* For PASS_MAX. */
#include <limits.h>
+/* For _getch(). */
+#include <conio.h>
+/* For strdup(). */
+#include <string.h>
#ifndef PASS_MAX
# define PASS_MAX 512
diff --git a/lib/getugroups.c b/lib/getugroups.c
index 7aa540db7..dfcffd75f 100644
--- a/lib/getugroups.c
+++ b/lib/getugroups.c
@@ -34,8 +34,7 @@
# define EOVERFLOW EINVAL
#endif
-/* setgrent, getgrent, and endgrent are not specified by POSIX.1,
- so header files might not declare them.
+/* Some old header files might not declare setgrent, getgrent, and endgrent.
If you don't have them at all, we can't implement this function.
You lose! */
struct group *getgrent ();
diff --git a/lib/mbchar.h b/lib/mbchar.h
index 4472aa020..738efd948 100644
--- a/lib/mbchar.h
+++ b/lib/mbchar.h
@@ -1,5 +1,5 @@
/* Multibyte character data type.
- Copyright (C) 2001, 2005 Free Software Foundation, Inc.
+ Copyright (C) 2001, 2005-2006 Free Software Foundation, Inc.
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
@@ -158,6 +158,8 @@
#include <wctype.h>
+#include "wcwidth.h"
+
#define MBCHAR_BUF_SIZE 24
struct mbchar
diff --git a/lib/mbswidth.c b/lib/mbswidth.c
index c9e78d650..ef8398a78 100644
--- a/lib/mbswidth.c
+++ b/lib/mbswidth.c
@@ -1,5 +1,5 @@
/* Determine the number of screen columns needed for a string.
- Copyright (C) 2000-2005 Free Software Foundation, Inc.
+ Copyright (C) 2000-2006 Free Software Foundation, Inc.
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
@@ -32,7 +32,7 @@
/* Get isprint(). */
#include <ctype.h>
-/* Get mbstate_t, mbrtowc(), mbsinit(), wcwidth(). */
+/* Get mbstate_t, mbrtowc(), mbsinit(). */
#if HAVE_WCHAR_H
/* Tru64 with Desktop Toolkit C has a bug: <stdio.h> must be included before
<wchar.h>.
@@ -43,13 +43,13 @@
# include <wchar.h>
#endif
-/* Get iswprint(), iswcntrl(). */
+/* Get wcwidth(). */
+#include "wcwidth.h"
+
+/* Get iswcntrl(). */
#if HAVE_WCTYPE_H
# include <wctype.h>
#endif
-#if !defined iswprint && !HAVE_ISWPRINT
-# define iswprint(wc) 1
-#endif
#if !defined iswcntrl && !HAVE_ISWCNTRL
# define iswcntrl(wc) 0
#endif
@@ -60,21 +60,6 @@
# endif
#endif
-#ifndef HAVE_DECL_WCWIDTH
-"this configure-time declaration test was not run"
-#endif
-#if !HAVE_DECL_WCWIDTH
-int wcwidth ();
-#endif
-
-#ifndef wcwidth
-# if !HAVE_WCWIDTH
-/* wcwidth doesn't exist, so assume all printable characters have
- width 1. */
-# define wcwidth(wc) ((wc) == 0 ? 0 : iswprint (wc) ? 1 : -1)
-# endif
-#endif
-
/* Get ISPRINT. */
#if defined (STDC_HEADERS) || (!defined (isascii) && !defined (HAVE_ISASCII))
# define IN_CTYPE_DOMAIN(c) 1
diff --git a/lib/sha1.c b/lib/sha1.c
index 509911d87..dadf97361 100644
--- a/lib/sha1.c
+++ b/lib/sha1.c
@@ -270,10 +270,10 @@ sha1_process_bytes (const void *buffer, size_t len, struct sha1_ctx *ctx)
/* --- Code below is the primary difference between md5.c and sha1.c --- */
/* SHA1 round constants */
-#define K1 0x5a827999L
-#define K2 0x6ed9eba1L
-#define K3 0x8f1bbcdcL
-#define K4 0xca62c1d6L
+#define K1 0x5a827999
+#define K2 0x6ed9eba1
+#define K3 0x8f1bbcdc
+#define K4 0xca62c1d6
/* Round functions. Note that F2 is the same as F4. */
#define F1(B,C,D) ( D ^ ( B & ( C ^ D ) ) )
@@ -305,7 +305,7 @@ sha1_process_block (const void *buffer, size_t len, struct sha1_ctx *ctx)
if (ctx->total[0] < len)
++ctx->total[1];
-#define rol(x, n) (((x) << (n)) | ((x) >> (32 - (n))))
+#define rol(x, n) (((x) << (n)) | ((uint32_t) (x) >> (32 - (n))))
#define M(I) ( tm = x[I&0x0f] ^ x[(I-14)&0x0f] \
^ x[(I-8)&0x0f] ^ x[(I-3)&0x0f] \
diff --git a/lib/strtod.c b/lib/strtod.c
index 7b48754e4..b8aab679e 100644
--- a/lib/strtod.c
+++ b/lib/strtod.c
@@ -1,4 +1,4 @@
-/* Copyright (C) 1991, 1992, 1997, 1999, 2003 Free Software Foundation, Inc.
+/* Copyright (C) 1991, 1992, 1997, 1999, 2003, 2006 Free Software Foundation, Inc.
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
@@ -19,9 +19,6 @@
#endif
#include <errno.h>
-#ifndef errno
-extern int errno;
-#endif
#include <ctype.h>
diff --git a/lib/strtol.c b/lib/strtol.c
index 9bfbe3c1a..eda2d2699 100644
--- a/lib/strtol.c
+++ b/lib/strtol.c
@@ -1,6 +1,6 @@
/* Convert string representation of a number into an integer value.
- Copyright (C) 1991, 1992, 1994, 1995, 1996, 1997, 1998, 1999, 2003, 2005
+ Copyright (C) 1991, 1992, 1994, 1995, 1996, 1997, 1998, 1999, 2003, 2005, 2006
Free Software Foundation, Inc.
NOTE: The canonical source of this file is maintained with the GNU C
@@ -30,9 +30,6 @@
#include <ctype.h>
#include <errno.h>
-#ifndef errno
-extern int errno;
-#endif
#ifndef __set_errno
# define __set_errno(Val) errno = (Val)
#endif
diff --git a/lib/time_r.c b/lib/time_r.c
index af845b499..412006372 100644
--- a/lib/time_r.c
+++ b/lib/time_r.c
@@ -26,14 +26,6 @@
#include <string.h>
-static char *
-copy_string_result (char *dest, char const *src)
-{
- if (! src)
- return 0;
- return strcpy (dest, src);
-}
-
static struct tm *
copy_tm_result (struct tm *dest, struct tm const *src)
{
diff --git a/lib/unicodeio.c b/lib/unicodeio.c
index 83ed6d02f..f8fedb66c 100644
--- a/lib/unicodeio.c
+++ b/lib/unicodeio.c
@@ -1,6 +1,6 @@
/* Unicode character output to streams with locale dependent encoding.
- Copyright (C) 2000-2003, 2005 Free Software Foundation, Inc.
+ Copyright (C) 2000-2003, 2005, 2006 Free Software Foundation, Inc.
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
@@ -30,11 +30,7 @@
#include <stdio.h>
#include <string.h>
-
#include <errno.h>
-#ifndef errno
-extern int errno;
-#endif
#if HAVE_ICONV
# include <iconv.h>