diff options
-rw-r--r-- | gl/alloca_.h | 26 | ||||
-rw-r--r-- | gl/getaddrinfo.c | 1 | ||||
-rw-r--r-- | gl/inet_ntop.c | 2 | ||||
-rw-r--r-- | gl/m4/getaddrinfo.m4 | 19 | ||||
-rw-r--r-- | gl/m4/sockpfaf.m4 | 24 | ||||
-rw-r--r-- | gl/m4/stdint.m4 | 8 | ||||
-rw-r--r-- | gl/read-file.c | 44 | ||||
-rw-r--r-- | gl/socket_.h | 36 | ||||
-rw-r--r-- | gl/stdint_.h | 5 |
9 files changed, 96 insertions, 69 deletions
diff --git a/gl/alloca_.h b/gl/alloca_.h index 65a40ffea6..e712211311 100644 --- a/gl/alloca_.h +++ b/gl/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/gl/getaddrinfo.c b/gl/getaddrinfo.c index add1446006..9ebca0c0e0 100644 --- a/gl/getaddrinfo.c +++ b/gl/getaddrinfo.c @@ -212,6 +212,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. */ diff --git a/gl/inet_ntop.c b/gl/inet_ntop.c index d2d99e1c84..50810acfe1 100644 --- a/gl/inet_ntop.c +++ b/gl/inet_ntop.c @@ -76,8 +76,10 @@ inet_ntop (int af, const void *restrict src, { switch (af) { +#if HAVE_IPV4 case AF_INET: return (inet_ntop4 (src, dst, cnt)); +#endif #if HAVE_IPV6 case AF_INET6: diff --git a/gl/m4/getaddrinfo.m4 b/gl/m4/getaddrinfo.m4 index c367190784..fef311ff18 100644 --- a/gl/m4/getaddrinfo.m4 +++ b/gl/m4/getaddrinfo.m4 @@ -17,7 +17,6 @@ AC_DEFUN([gl_GETADDRINFO], LIBS="$LIBS -lws2_32" AC_TRY_LINK([ #ifdef HAVE_WS2TCPIP_H -#define WINVER 0x0501 #include <ws2tcpip.h> #endif ], [getaddrinfo(0, 0, 0, 0);], gl_cv_w32_getaddrinfo=yes) @@ -37,6 +36,22 @@ AC_DEFUN([gl_GETADDRINFO], AC_DEFUN([gl_PREREQ_GETADDRINFO], [ AC_SEARCH_LIBS(gethostbyname, [inet nsl]) AC_SEARCH_LIBS(getservbyname, [inet nsl socket xnet]) + AC_CHECK_FUNCS(gethostbyname,, [ + AC_CACHE_CHECK(for gethostbyname in winsock2.h and -lws2_32, + gl_cv_w32_gethostbyname, [ + gl_cv_w32_gethostbyname=no + am_save_LIBS="$LIBS" + LIBS="$LIBS -lws2_32" + AC_TRY_LINK([ +#ifdef HAVE_WINSOCK2_H +#include <winsock2.h> +#endif +], [gethostbyname(0);], gl_cv_w32_gethostbyname=yes) + LIBS="$am_save_LIBS"]) + if test "$gl_cv_w32_gethostbyname" = "yes"; then + LIBS="$LIBS -lws2_32" + fi + ]) AC_REQUIRE([gl_C_RESTRICT]) AC_REQUIRE([gl_SOCKET_FAMILIES]) AC_REQUIRE([gl_HEADER_SYS_SOCKET]) @@ -55,7 +70,6 @@ AC_DEFUN([gl_PREREQ_GETADDRINFO], [ #include <netdb.h> #endif #ifdef HAVE_WS2TCPIP_H -#define WINVER 0x0501 #include <ws2tcpip.h> #endif ]) @@ -68,7 +82,6 @@ AC_DEFUN([gl_PREREQ_GETADDRINFO], [ #include <netdb.h> #endif #ifdef HAVE_WS2TCPIP_H -#define WINVER 0x0501 #include <ws2tcpip.h> #endif ]) diff --git a/gl/m4/sockpfaf.m4 b/gl/m4/sockpfaf.m4 index b224faec5e..9e396ebaf9 100644 --- a/gl/m4/sockpfaf.m4 +++ b/gl/m4/sockpfaf.m4 @@ -1,5 +1,5 @@ -# sockpfaf.m4 serial 2 -dnl Copyright (C) 2004 Free Software Foundation, Inc. +# sockpfaf.m4 serial 3 +dnl Copyright (C) 2004, 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, dnl with or without modifications, as long as this notice is preserved. @@ -13,11 +13,20 @@ dnl From Bruno Haible. AC_DEFUN([gl_SOCKET_FAMILIES], [ + AC_CHECK_HEADERS_ONCE(sys/socket.h netinet/in.h winsock2.h) + AC_MSG_CHECKING(for IPv4 sockets) AC_CACHE_VAL(gl_cv_socket_ipv4, [AC_TRY_COMPILE([#include <sys/types.h> +#ifdef HAVE_SYS_SOCKET_H #include <sys/socket.h> -#include <netinet/in.h>], +#endif +#ifdef HAVE_NETINET_IN_H +#include <netinet/in.h> +#endif +#ifdef HAVE_WINSOCK2_H +#include <winsock2.h> +#endif], [int x = AF_INET; struct in_addr y; struct sockaddr_in z;], gl_cv_socket_ipv4=yes, gl_cv_socket_ipv4=no)]) AC_MSG_RESULT($gl_cv_socket_ipv4) @@ -28,8 +37,15 @@ AC_DEFUN([gl_SOCKET_FAMILIES], AC_MSG_CHECKING(for IPv6 sockets) AC_CACHE_VAL(gl_cv_socket_ipv6, [AC_TRY_COMPILE([#include <sys/types.h> +#ifdef HAVE_SYS_SOCKET_H #include <sys/socket.h> -#include <netinet/in.h>], +#endif +#ifdef HAVE_NETINET_IN_H +#include <netinet/in.h> +#endif +#ifdef HAVE_WINSOCK2_H +#include <winsock2.h> +#endif], [int x = AF_INET6; struct in6_addr y; struct sockaddr_in6 z;], gl_cv_socket_ipv6=yes, gl_cv_socket_ipv6=no)]) AC_MSG_RESULT($gl_cv_socket_ipv6) diff --git a/gl/m4/stdint.m4 b/gl/m4/stdint.m4 index 33a443cf84..55388fae95 100644 --- a/gl/m4/stdint.m4 +++ b/gl/m4/stdint.m4 @@ -1,4 +1,4 @@ -# stdint.m4 serial 6 +# stdint.m4 serial 7 dnl Copyright (C) 2001-2002, 2004-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, @@ -14,7 +14,7 @@ AC_DEFUN([gl_STDINT_H], if test $gl_cv_header_stdint_h = yes; then ac_cv_header_stdint_h=yes; dnl Hack for gl_FULL_HEADER_PATH. gl_FULL_HEADER_PATH([stdint.h]) - FULL_PATH_STDINT_H=$gl_cv_full_path_stdint_h + FULL_PATH_STDINT_H='<'$gl_cv_full_path_stdint_h'>' AC_SUBST([FULL_PATH_STDINT_H]) HAVE_STDINT_H=1 else @@ -27,7 +27,7 @@ AC_DEFUN([gl_STDINT_H], if test $gl_cv_header_inttypes_h = yes; then ac_cv_header_inttypes_h=yes; dnl Hack for gl_FULL_HEADER_PATH. gl_FULL_HEADER_PATH([inttypes.h]) - FULL_PATH_INTTYPES_H=$gl_cv_full_path_inttypes_h + FULL_PATH_INTTYPES_H='<'$gl_cv_full_path_inttypes_h'>' AC_SUBST([FULL_PATH_INTTYPES_H]) HAVE_INTTYPES_H=1 else @@ -87,7 +87,7 @@ typedef int array [2 * (POW63 != 0 && POW64 == 0) - 1]; dnl created in the build directory. other_includes=' /* Get those types that are already defined in other system include files. */ -#if defined(__FreeBSD__) +#if defined(__FreeBSD__) && (__FreeBSD__ >= 3) && (__FreeBSD__ <= 4) # include <sys/inttypes.h> #endif #if defined(__OpenBSD__) diff --git a/gl/read-file.c b/gl/read-file.c index f73a498f08..e915b10920 100644 --- a/gl/read-file.c +++ b/gl/read-file.c @@ -36,19 +36,15 @@ char * fread_file (FILE * stream, size_t * length) { - char *buf = malloc (1); - size_t alloc = 1; + char *buf = NULL; + size_t alloc = 0; size_t size = 0; + int save_errno; - if (!buf) - return NULL; - - if (ferror (stream)) - return NULL; - - while (!feof (stream)) + for (;;) { size_t count; + size_t requested; if (size + BUFSIZ + 1 > alloc) { @@ -61,32 +57,31 @@ fread_file (FILE * stream, size_t * length) new_buf = realloc (buf, alloc); if (!new_buf) { - int save_errno = errno; - free (buf); - errno = save_errno; - return NULL; + save_errno = errno; + break; } buf = new_buf; } - count = fread (buf + size, 1, alloc - size - 1, stream); + requested = alloc - size - 1; + count = fread (buf + size, 1, requested, stream); size += count; - if (ferror (stream)) + if (count != requested) { - int save_errno = errno; - free (buf); - errno = save_errno; - return NULL; + save_errno = errno; + if (ferror (stream)) + break; + buf[size] = '\0'; + *length = size; + return buf; } } - buf[size] = '\0'; - - *length = size; - - return buf; + free (buf); + errno = save_errno; + return NULL; } static char * @@ -95,7 +90,6 @@ internal_read_file (const char *filename, size_t * length, const char *mode) FILE *stream = fopen (filename, mode); char *out; int save_errno; - int rc; if (!stream) return NULL; diff --git a/gl/socket_.h b/gl/socket_.h index ce1edbb417..715d0ad0b8 100644 --- a/gl/socket_.h +++ b/gl/socket_.h @@ -1,4 +1,4 @@ -/* Provide a sys/socket header file for systems lacking it (read: mingw32). +/* Provide a sys/socket header file for systems lacking it (read: MinGW). Copyright (C) 2005, 2006 Free Software Foundation, Inc. Written by Simon Josefsson. @@ -23,27 +23,23 @@ sys/socket.h. It is intended to provide definitions and prototypes needed by an application. - Currently only mingw32 is supported, which has the header files - winsock2.h and ws2tcpip.h that declare the sys/socket.h definitions - we need. */ + Currently only MinGW is supported. See the gnulib manual regarding + Windows sockets. MinGW have the header files winsock2.h and + ws2tcpip.h that declare the sys/socket.h definitions we need. Note + that you can influence which definitions you get by setting the + WINVER symbol before including these two files. For example, + getaddrinfo is only available if _WIN32_WINNT >= 0x0501 (that + symbol is set indiriectly through WINVER). You can set this by + adding AC_DEFIN(WINVER, 0x0501) to configure.ac. Note that your + code may not run on older Windows releases then. My Windows 2000 + box was not able to run the code, for example. The situation is + slightly confusing because: + http://msdn.microsoft.com/library/default.asp?url=/library/en-us/winsock/winsock/getaddrinfo_2.asp + suggests that getaddrinfo should be available on all Windows + releases. */ -#if HAVE_WINSOCK2_H -/* The following define makes sure we get all the prototypes from the - header files. getaddrinfo is only available if _WIN32_WINNT >= - 0x0501 (that symbol is set indiriectly through WINVER). This has - the following two (potential) problems: - - 1) winsock2.h must not have been included before this symbol - is set (I think). - 2) There may be some _reason_ for all prototypes not being - available with the default settings. Such as if some APIs are - not available on older Windows hosts. However, getaddrinfo - (which need >= 0x0501) should be available on Windows 95 and - later, according to: - http://msdn.microsoft.com/library/default.asp?url=/library/en-us/winsock/winsock/getaddrinfo_2.asp -*/ -#define WINVER 0x0501 +#if HAVE_WINSOCK2_H # include <winsock2.h> #endif #if HAVE_WS2TCPIP_H diff --git a/gl/stdint_.h b/gl/stdint_.h index dfa9d48c5f..8fc8cebf52 100644 --- a/gl/stdint_.h +++ b/gl/stdint_.h @@ -30,7 +30,7 @@ #include <limits.h> /* Get those types that are already defined in other system include files. */ -#if defined(__FreeBSD__) +#if defined(__FreeBSD__) && (__FreeBSD__ >= 3) && (__FreeBSD__ <= 4) # include <sys/inttypes.h> #endif #if defined(__OpenBSD__) @@ -77,6 +77,7 @@ typedef signed char int8_t; #endif #if !@HAVE_UINT8_T@ typedef unsigned char uint8_t; +# define _UINT8_T /* avoid collision with Solaris 2.5.1 <pthread.h> */ #endif #if !@HAVE_INT16_T@ @@ -91,6 +92,7 @@ typedef int int32_t; #endif #if !@HAVE_UINT32_T@ typedef unsigned int uint32_t; +# define _UINT32_T /* avoid collision with Solaris 2.5.1 <pthread.h> */ #endif #if @HAVE_INT64_T@ @@ -115,6 +117,7 @@ typedef unsigned long uint64_t; # define _STDINT_H_HAVE_UINT64 1 # elif @HAVE_LONG_LONG_64BIT@ typedef unsigned long long uint64_t; +# define _UINT64_T /* avoid collision with Solaris 2.5.1 <pthread.h> */ # define _STDINT_H_HAVE_UINT64 1 # elif defined _MSC_VER typedef unsigned __int64 uint64_t; |