diff options
author | Simon Josefsson <simon@josefsson.org> | 2009-03-30 12:08:38 +0200 |
---|---|---|
committer | Simon Josefsson <simon@josefsson.org> | 2009-03-30 12:08:38 +0200 |
commit | 96b8ed443933193a0d18ca21f5fd65028f948077 (patch) | |
tree | cb1e5b247f4170da6426627d8ae1fc6bb25f8f68 /gl | |
parent | fe5597bd4c51cfce5328b0a869a35dd5cda64a6b (diff) | |
download | gnutls-96b8ed443933193a0d18ca21f5fd65028f948077.tar.gz |
Update gnulib files.
Diffstat (limited to 'gl')
-rw-r--r-- | gl/Makefile.am | 16 | ||||
-rw-r--r-- | gl/close-hook.c | 91 | ||||
-rw-r--r-- | gl/close-hook.h | 72 | ||||
-rw-r--r-- | gl/close.c | 48 | ||||
-rw-r--r-- | gl/fseeko.c | 8 | ||||
-rw-r--r-- | gl/gai_strerror.c | 4 | ||||
-rw-r--r-- | gl/m4/close.m4 | 6 | ||||
-rw-r--r-- | gl/m4/gnulib-common.m4 | 15 | ||||
-rw-r--r-- | gl/m4/gnulib-comp.m4 | 11 | ||||
-rw-r--r-- | gl/m4/printf.m4 | 24 | ||||
-rw-r--r-- | gl/m4/select.m4 | 52 | ||||
-rw-r--r-- | gl/m4/stdarg.m4 | 6 | ||||
-rw-r--r-- | gl/m4/sys_select_h.m4 | 6 | ||||
-rw-r--r-- | gl/readline.c | 7 | ||||
-rw-r--r-- | gl/select.c (renamed from gl/winsock-select.c) | 27 | ||||
-rw-r--r-- | gl/setsockopt.c | 21 | ||||
-rw-r--r-- | gl/stdint.in.h | 4 | ||||
-rw-r--r-- | gl/sys_select.in.h | 4 | ||||
-rw-r--r-- | gl/sys_socket.in.h | 6 | ||||
-rw-r--r-- | gl/tests/Makefile.am | 2 | ||||
-rw-r--r-- | gl/tests/sockets.c | 55 | ||||
-rw-r--r-- | gl/tests/sockets.h | 10 | ||||
-rw-r--r-- | gl/tests/test-getaddrinfo.c | 9 | ||||
-rw-r--r-- | gl/tests/test-sockets.c | 2 | ||||
-rw-r--r-- | gl/unistd.in.h | 4 | ||||
-rw-r--r-- | gl/vasnprintf.c | 2 |
26 files changed, 416 insertions, 96 deletions
diff --git a/gl/Makefile.am b/gl/Makefile.am index c26daca396..fdb8ee54e3 100644 --- a/gl/Makefile.am +++ b/gl/Makefile.am @@ -29,6 +29,7 @@ SUBDIRS += tests EXTRA_DIST += m4/gnulib-cache.m4 AM_CPPFLAGS = +AM_CFLAGS = noinst_LTLIBRARIES += libgnu.la @@ -122,12 +123,20 @@ libgnu_la_SOURCES += c-ctype.h c-ctype.c ## begin gnulib module close -EXTRA_DIST += close.c w32sock.h +EXTRA_DIST += close.c EXTRA_libgnu_la_SOURCES += close.c ## end gnulib module close +## begin gnulib module close-hook + +libgnu_la_SOURCES += close-hook.c + +EXTRA_DIST += close-hook.h + +## end gnulib module close-hook + ## begin gnulib module connect @@ -461,9 +470,9 @@ EXTRA_libgnu_la_SOURCES += recv.c ## begin gnulib module select -EXTRA_DIST += winsock-select.c +EXTRA_DIST += select.c -EXTRA_libgnu_la_SOURCES += winsock-select.c +EXTRA_libgnu_la_SOURCES += select.c ## end gnulib module select @@ -851,6 +860,7 @@ sys/select.h: sys_select.in.h -e 's|@''HAVE_SYS_SELECT_H''@|$(HAVE_SYS_SELECT_H)|g' \ -e 's|@''GNULIB_SELECT''@|$(GNULIB_SELECT)|g' \ -e 's|@''HAVE_WINSOCK2_H''@|$(HAVE_WINSOCK2_H)|g' \ + -e 's|@''REPLACE_SELECT''@|$(REPLACE_SELECT)|g' \ -e '/definition of GL_LINK_WARNING/r $(LINK_WARNING_H)' \ < $(srcdir)/sys_select.in.h; \ } > $@-t diff --git a/gl/close-hook.c b/gl/close-hook.c new file mode 100644 index 0000000000..fe1f22c780 --- /dev/null +++ b/gl/close-hook.c @@ -0,0 +1,91 @@ +/* Hook for making the close() function extensible. + Copyright (C) 2009 Free Software Foundation, Inc. + Written by Bruno Haible <bruno@clisp.org>, 2009. + + 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 the Free Software Foundation; either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see <http://www.gnu.org/licenses/>. */ + +#include <config.h> + +/* Specification. */ +#include "close-hook.h" + +#include <stdlib.h> +#include <unistd.h> + +#undef close + + +/* Currently, this entire code is only needed for the handling of sockets + on native Windows platforms. */ +#if WINDOWS_SOCKETS + +/* The first and last link in the doubly linked list. + Initially the list is empty. */ +static struct close_hook anchor = { &anchor, &anchor, NULL }; + +int +execute_close_hooks (int fd, const struct close_hook *remaining_list) +{ + if (remaining_list == &anchor) + /* End of list reached. */ + return close (fd); + else + return remaining_list->private_fn (fd, remaining_list->private_next); +} + +int +execute_all_close_hooks (int fd) +{ + return execute_close_hooks (fd, anchor.private_next); +} + +void +register_close_hook (close_hook_fn hook, struct close_hook *link) +{ + if (link->private_next == NULL && link->private_prev == NULL) + { + /* Add the link to the doubly linked list. */ + link->private_next = anchor.private_next; + link->private_prev = &anchor; + link->private_fn = hook; + anchor.private_next->private_prev = link; + anchor.private_next = link; + } + else + { + /* The link is already in use. */ + if (link->private_fn != hook) + abort (); + } +} + +void +unregister_close_hook (struct close_hook *link) +{ + struct close_hook *next = link->private_next; + struct close_hook *prev = link->private_prev; + + if (next != NULL && prev != NULL) + { + /* The link is in use. Remove it from the doubly linked list. */ + prev->private_next = next; + next->private_prev = prev; + /* Clear the link, to mark it unused. */ + link->private_next = NULL; + link->private_prev = NULL; + link->private_fn = NULL; + } +} + +#endif diff --git a/gl/close-hook.h b/gl/close-hook.h new file mode 100644 index 0000000000..460603abac --- /dev/null +++ b/gl/close-hook.h @@ -0,0 +1,72 @@ +/* Hook for making the close() function extensible. + Copyright (C) 2009 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 the Free Software Foundation; either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see <http://www.gnu.org/licenses/>. */ + + +#ifndef CLOSE_HOOK_H +#define CLOSE_HOOK_H + +#ifdef __cplusplus +extern "C" { +#endif + + +/* Currently, this entire code is only needed for the handling of sockets + on native Windows platforms. */ +#if WINDOWS_SOCKETS + + +/* An element of the list of close hooks. + The fields of this structure are considered private. */ +struct close_hook +{ + /* Doubly linked list. */ + struct close_hook *private_next; + struct close_hook *private_prev; + /* Function that treats the types of FD that it knows about and calls + execute_close_hooks (FD, REMAINING_LIST) as a fallback. */ + int (*private_fn) (int fd, const struct close_hook *remaining_list); +}; + +/* This type of function closes FD, applying special knowledge for the FD + types it knows about, and calls execute_close_hooks (FD, REMAINING_LIST) + for the other FD types. */ +typedef int (*close_hook_fn) (int fd, const struct close_hook *remaining_list); + +/* Execute the close hooks in REMAINING_LIST. + Return 0 or -1, like close() would do. */ +extern int execute_close_hooks (int fd, const struct close_hook *remaining_list); + +/* Execute all close hooks. + Return 0 or -1, like close() would do. */ +extern int execute_all_close_hooks (int fd); + +/* Add a function to the list of close hooks. + The LINK variable points to a piece of memory which is guaranteed to be + accessible until the corresponding call to unregister_close_hook. */ +extern void register_close_hook (close_hook_fn hook, struct close_hook *link); + +/* Removes a function from the list of close hooks. */ +extern void unregister_close_hook (struct close_hook *link); + + +#endif + + +#ifdef __cplusplus +} +#endif + +#endif /* CLOSE_HOOK_H */ diff --git a/gl/close.c b/gl/close.c index 74a7adfbbc..0e56dcb27f 100644 --- a/gl/close.c +++ b/gl/close.c @@ -1,5 +1,5 @@ /* close replacement. - Copyright (C) 2008 Free Software Foundation, Inc. + Copyright (C) 2008-2009 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,47 +19,7 @@ /* Specification. */ #include <unistd.h> -#if GNULIB_SYS_SOCKET -# define WIN32_LEAN_AND_MEAN -# include <sys/socket.h> -#endif - -#if HAVE__GL_CLOSE_FD_MAYBE_SOCKET - -/* Get set_winsock_errno, FD_TO_SOCKET etc. */ -#include "w32sock.h" - -static int -_gl_close_fd_maybe_socket (int fd) -{ - SOCKET sock = FD_TO_SOCKET (fd); - WSANETWORKEVENTS ev; - - ev.lNetworkEvents = 0xDEADBEEF; - WSAEnumNetworkEvents (sock, NULL, &ev); - if (ev.lNetworkEvents != 0xDEADBEEF) - { - /* FIXME: other applications, like squid, use an undocumented - _free_osfhnd free function. But this is not enough: The 'osfile' - flags for fd also needs to be cleared, but it is hard to access it. - Instead, here we just close twice the file descriptor. */ - if (closesocket (sock)) - { - set_winsock_errno (); - return -1; - } - else - { - /* This call frees the file descriptor and does a - CloseHandle ((HANDLE) _get_osfhandle (fd)), which fails. */ - _close (fd); - return 0; - } - } - else - return _close (fd); -} -#endif +#include "close-hook.h" /* Override close() to call into other gnulib modules. */ @@ -67,8 +27,8 @@ int rpl_close (int fd) #undef close { -#if HAVE__GL_CLOSE_FD_MAYBE_SOCKET - int retval = _gl_close_fd_maybe_socket (fd); +#if WINDOWS_SOCKETS + int retval = execute_all_close_hooks (fd); #else int retval = close (fd); #endif diff --git a/gl/fseeko.c b/gl/fseeko.c index e057508d49..cf7c42fbfd 100644 --- a/gl/fseeko.c +++ b/gl/fseeko.c @@ -82,6 +82,11 @@ rpl_fseeko (FILE *fp, off_t offset, int whence) if ((fp->_Mode & _MWRITE ? fp->_Next == fp->_Buf : fp->_Next == fp->_Rend) && fp->_Rback == fp->_Back + sizeof (fp->_Back) && fp->_Rsave == NULL) +#elif defined __MINT__ /* Atari FreeMiNT */ + if (fp->__bufp == fp->__buffer + && fp->__get_limit == fp->__bufp + && fp->__put_limit == fp->__bufp + && !fp->__pushed_back) #else #error "Please port gnulib fseeko.c to your platform! Look at the code in fpurge.c, then report this to bug-gnulib." #endif @@ -112,6 +117,9 @@ rpl_fseeko (FILE *fp, off_t offset, int whence) fp->_flags &= ~_IOEOF; #elif defined _IOERR /* AIX, HP-UX, IRIX, OSF/1, Solaris, OpenServer, mingw */ fp->_flag &= ~_IOEOF; +#elif defined __MINT__ /* Atari FreeMiNT */ + fp->__offset = pos; + fp->__eof = 0; #endif /* If we were not requested to position beyond end of file, we're done. */ diff --git a/gl/gai_strerror.c b/gl/gai_strerror.c index 78a8edfed0..afbcdbb4f7 100644 --- a/gl/gai_strerror.c +++ b/gl/gai_strerror.c @@ -1,4 +1,4 @@ -/* Copyright (C) 1997, 2001, 2002, 2004, 2005, 2006, 2008 Free Software Foundation, Inc. +/* Copyright (C) 1997, 2001, 2002, 2004, 2005, 2006, 2008, 2009 Free Software Foundation, Inc. This file is part of the GNU C Library. Contributed by Philip Blundell <pjb27@cam.ac.uk>, 1997. @@ -50,7 +50,7 @@ values[] = { EAI_SOCKTYPE, N_("ai_socktype not supported") }, { EAI_SYSTEM, N_("System error") }, { EAI_OVERFLOW, N_("Argument buffer too small") }, -#ifdef __USE_GNU +#ifdef EAI_INPROGRESS { EAI_INPROGRESS, N_("Processing request in progress") }, { EAI_CANCELED, N_("Request canceled") }, { EAI_NOTCANCELED, N_("Request not canceled") }, diff --git a/gl/m4/close.m4 b/gl/m4/close.m4 index 29d3abdd13..b1189f5f50 100644 --- a/gl/m4/close.m4 +++ b/gl/m4/close.m4 @@ -1,5 +1,5 @@ -# close.m4 serial 2 -dnl Copyright (C) 2008 Free Software Foundation, Inc. +# close.m4 serial 3 +dnl Copyright (C) 2008-2009 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. @@ -22,6 +22,4 @@ AC_DEFUN([gl_REPLACE_CLOSE], fi REPLACE_CLOSE=1 gl_REPLACE_FCLOSE - LIB_CLOSE="-lws2_32" - AC_SUBST([LIB_CLOSE]) ]) diff --git a/gl/m4/gnulib-common.m4 b/gl/m4/gnulib-common.m4 index 50e399aa1c..c8fda20330 100644 --- a/gl/m4/gnulib-common.m4 +++ b/gl/m4/gnulib-common.m4 @@ -1,4 +1,4 @@ -# gnulib-common.m4 serial 10 +# gnulib-common.m4 serial 11 dnl Copyright (C) 2007-2009 Free Software Foundation, Inc. dnl This file is free software; the Free Software Foundation dnl gives unlimited permission to copy and/or distribute it, @@ -109,3 +109,16 @@ AC_DEFUN([gl_BIGENDIAN], [ AC_C_BIGENDIAN ]) + +# gl_CACHE_VAL_SILENT(cache-id, command-to-set-it) +# is like AC_CACHE_VAL(cache-id, command-to-set-it), except that it does not +# output a spurious "(cached)" mark in the midst of other configure output. +# This macro should be used instead of AC_CACHE_VAL when it is not surrounded +# by an AC_MSG_CHECKING/AC_MSG_RESULT pair. +AC_DEFUN([gl_CACHE_VAL_SILENT], +[ + saved_as_echo_n="$as_echo_n" + as_echo_n=':' + AC_CACHE_VAL([$1], [$2]) + as_echo_n="$saved_as_echo_n" +]) diff --git a/gl/m4/gnulib-comp.m4 b/gl/m4/gnulib-comp.m4 index f2cc584c8a..5106e8a8e8 100644 --- a/gl/m4/gnulib-comp.m4 +++ b/gl/m4/gnulib-comp.m4 @@ -130,10 +130,7 @@ AC_SUBST([LTALLOCA]) AC_LIBOBJ([recv]) fi gl_SYS_SOCKET_MODULE_INDICATOR([recv]) - AC_REQUIRE([gl_HEADER_SYS_SELECT]) - if test "$ac_cv_header_winsock2_h" = yes; then - AC_LIBOBJ([winsock-select]) - fi + gl_FUNC_SELECT gl_SYS_SELECT_MODULE_INDICATOR([select]) AC_REQUIRE([gl_HEADER_SYS_SOCKET]) if test "$ac_cv_header_winsock2_h" = yes; then @@ -171,7 +168,6 @@ AC_SUBST([LTALLOCA]) gl_HEADER_SYS_SELECT AC_PROG_MKDIR_P gl_HEADER_SYS_SOCKET - gl_MODULE_INDICATOR([sys_socket]) AC_PROG_MKDIR_P gl_HEADER_SYS_STAT_H AC_PROG_MKDIR_P @@ -346,6 +342,8 @@ AC_DEFUN([gl_FILE_LIST], [ lib/bind.c lib/c-ctype.c lib/c-ctype.h + lib/close-hook.c + lib/close-hook.h lib/close.c lib/connect.c lib/errno.in.h @@ -383,6 +381,7 @@ AC_DEFUN([gl_FILE_LIST], [ lib/readline.h lib/realloc.c lib/recv.c + lib/select.c lib/send.c lib/setsockopt.c lib/shutdown.c @@ -410,7 +409,6 @@ AC_DEFUN([gl_FILE_LIST], [ lib/version-etc.h lib/w32sock.h lib/wchar.in.h - lib/winsock-select.c lib/xsize.h m4/00gnulib.m4 m4/alloca.m4 @@ -452,6 +450,7 @@ AC_DEFUN([gl_FILE_LIST], [ m4/read-file.m4 m4/readline.m4 m4/realloc.m4 + m4/select.m4 m4/servent.m4 m4/size_max.m4 m4/snprintf.m4 diff --git a/gl/m4/printf.m4 b/gl/m4/printf.m4 index 4207ace49f..87aa45c5e7 100644 --- a/gl/m4/printf.m4 +++ b/gl/m4/printf.m4 @@ -1,4 +1,4 @@ -# printf.m4 serial 31 +# printf.m4 serial 33 dnl Copyright (C) 2003, 2007-2009 Free Software Foundation, Inc. dnl This file is free software; the Free Software Foundation dnl gives unlimited permission to copy and/or distribute it, @@ -558,7 +558,7 @@ int main () if (sprintf (buf, "%F", 1.0 / 0.0) < 0 || (strcmp (buf, "INF") != 0 && strcmp (buf, "INFINITY") != 0)) return 1; - /* This catches a Cygwin 2007 bug. */ + /* This catches a Cygwin 1.5.x bug. */ if (sprintf (buf, "%.F", 1234.0) < 0 || strcmp (buf, "1234") != 0) return 1; @@ -653,7 +653,8 @@ int main () { char buf[100]; /* Test whether %ls works at all. - This test fails on OpenBSD 4.0, IRIX 6.5, Solaris 2.6, Haiku. */ + This test fails on OpenBSD 4.0, IRIX 6.5, Solaris 2.6, Haiku, but not on + Cygwin 1.5. */ { static const wchar_t wstring[] = { 'a', 'b', 'c', 0 }; buf[0] = '\0'; @@ -661,6 +662,15 @@ int main () || strcmp (buf, "abc") != 0) return 1; } + /* This test fails on IRIX 6.5, Solaris 2.6, Cygwin 1.5, Haiku (with an + assertion failure inside libc), but not on OpenBSD 4.0. */ + { + static const wchar_t wstring[] = { 'a', 0 }; + buf[0] = '\0'; + if (sprintf (buf, "%ls", wstring) < 0 + || strcmp (buf, "a") != 0) + return 1; + } /* Test whether precisions in %ls are supported as specified in ISO C 99 section 7.19.6.1: "If a precision is specified, no more than that many bytes are written @@ -682,8 +692,9 @@ int main () changequote(,)dnl case "$host_os" in openbsd*) gl_cv_func_printf_directive_ls="guessing no";; - solaris*) gl_cv_func_printf_directive_ls="guessing no";; irix*) gl_cv_func_printf_directive_ls="guessing no";; + solaris*) gl_cv_func_printf_directive_ls="guessing no";; + cygwin*) gl_cv_func_printf_directive_ls="guessing no";; beos* | haiku*) gl_cv_func_printf_directive_ls="guessing no";; *) gl_cv_func_printf_directive_ls="guessing yes";; esac @@ -1384,8 +1395,9 @@ dnl glibc 2.3.6 . . . . # . . . . . . . . . . dnl FreeBSD 5.4, 6.1 . . . . # . . . . . . # . # . . . . . . dnl MacOS X 10.3.9 . . . . # . . . . . . # . # . . . . . . dnl OpenBSD 3.9, 4.0 . . # # # # . # . # . # . # . . . . . . -dnl Cygwin 2007 (= Cygwin 1.5.24) . . . . # # . . . . ? # ? ? . . . . . . -dnl Cygwin 2006 (= Cygwin 1.5.19) # . . . # # . ? . # ? # ? ? . . . . . . +dnl Cygwin 1.7.0 (2009) . . . # . . . ? . . . . . ? . . . . . . +dnl Cygwin 1.5.25 (2008) . . . # # . . # . . . . . # . . . . . . +dnl Cygwin 1.5.19 (2006) # . . # # # . # . # . # # # . . . . . . dnl Solaris 10 . . # # # . . # . . . # . . . . . . . . dnl Solaris 2.6 ... 9 # . # # # # . # . . . # . . . . . . . . dnl Solaris 2.5.1 # . # # # # . # . . . # . . # # # # # # diff --git a/gl/m4/select.m4 b/gl/m4/select.m4 new file mode 100644 index 0000000000..5397df02f3 --- /dev/null +++ b/gl/m4/select.m4 @@ -0,0 +1,52 @@ +# select.m4 serial 1 +dnl Copyright (C) 2009 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. + +AC_DEFUN([gl_FUNC_SELECT], +[ + AC_REQUIRE([gl_HEADER_SYS_SELECT]) + AC_REQUIRE([AC_CANONICAL_HOST]) dnl for cross-compiles + if test "$ac_cv_header_winsock2_h" = yes; then + AC_LIBOBJ([select]) + else + dnl On Interix 3.5, select(0, NULL, NULL, NULL, timeout) fails with error + dnl EFAULT. + AC_CHECK_HEADERS_ONCE([sys/select.h]) + AC_CACHE_CHECK([whether select supports a 0 argument], + [gl_cv_func_select_supports0], + [ + AC_TRY_RUN([ +#include <sys/types.h> +#include <sys/time.h> +#if HAVE_SYS_SELECT_H +#include <sys/select.h> +#endif +int main () +{ + struct timeval timeout; + timeout.tv_sec = 0; + timeout.tv_usec = 5; + return select (0, (fd_set *)0, (fd_set *)0, (fd_set *)0, &timeout) < 0; +}], [gl_cv_func_select_supports0=yes], [gl_cv_func_select_supports0=no], + [ +changequote(,)dnl + case "$host_os" in + # Guess no on Interix. + interix*) gl_cv_func_select_supports0="guessing no";; + # Guess yes otherwise. + *) gl_cv_func_select_supports0="guessing yes";; + esac +changequote([,])dnl + ]) + ]) + case "$gl_cv_func_select_supports0" in + *yes) ;; + *) + REPLACE_SELECT=1 + AC_LIBOBJ([select]) + ;; + esac + fi +]) diff --git a/gl/m4/stdarg.m4 b/gl/m4/stdarg.m4 index 21910e4bec..a9ada4f4e0 100644 --- a/gl/m4/stdarg.m4 +++ b/gl/m4/stdarg.m4 @@ -1,5 +1,5 @@ -# stdarg.m4 serial 2 -dnl Copyright (C) 2006, 2008 Free Software Foundation, Inc. +# stdarg.m4 serial 3 +dnl Copyright (C) 2006, 2008-2009 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. @@ -46,7 +46,7 @@ void (*func) (va_list, va_list) = va_copy; else dnl Provide a substitute in <config.h>, either __va_copy or as a simple dnl assignment. - AC_CACHE_VAL([gl_cv_func___va_copy], [ + gl_CACHE_VAL_SILENT([gl_cv_func___va_copy], [ AC_TRY_COMPILE([#include <stdarg.h>], [ #ifndef __va_copy error, bail out diff --git a/gl/m4/sys_select_h.m4 b/gl/m4/sys_select_h.m4 index c537e7918a..c48be2ce38 100644 --- a/gl/m4/sys_select_h.m4 +++ b/gl/m4/sys_select_h.m4 @@ -1,5 +1,5 @@ -# sys_select_h.m4 serial 6 -dnl Copyright (C) 2006-2008 Free Software Foundation, Inc. +# sys_select_h.m4 serial 7 +dnl Copyright (C) 2006-2009 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. @@ -42,4 +42,6 @@ AC_DEFUN([gl_SYS_SELECT_MODULE_INDICATOR], AC_DEFUN([gl_SYS_SELECT_H_DEFAULTS], [ GNULIB_SELECT=0; AC_SUBST([GNULIB_SELECT]) + dnl Assume proper GNU behavior unless another module says otherwise. + REPLACE_SELECT=0; AC_SUBST([REPLACE_SELECT]) ]) diff --git a/gl/readline.c b/gl/readline.c index a8db7ec68e..4be5f3457f 100644 --- a/gl/readline.c +++ b/gl/readline.c @@ -1,5 +1,5 @@ /* readline.c --- Simple implementation of readline. - Copyright (C) 2005, 2006, 2007 Free Software Foundation, Inc. + Copyright (C) 2005, 2006, 2007, 2009 Free Software Foundation, Inc. Written by Simon Josefsson This program is free software: you can redistribute it and/or modify @@ -39,7 +39,10 @@ readline (const char *prompt) size_t size = 0; if (prompt) - fputs (prompt, stdout); + { + fputs (prompt, stdout); + fflush (stdout); + } if (getline (&out, &size, stdin) < 0) return NULL; diff --git a/gl/winsock-select.c b/gl/select.c index 0b116cb1aa..82e438c116 100644 --- a/gl/winsock-select.c +++ b/gl/select.c @@ -1,7 +1,7 @@ /* Emulation for select(2) Contributed by Paolo Bonzini. - Copyright 2008 Free Software Foundation, Inc. + Copyright 2008-2009 Free Software Foundation, Inc. This file is part of gnulib. @@ -23,6 +23,8 @@ #include <alloca.h> #if (defined _WIN32 || defined __WIN32__) && ! defined __CYGWIN__ +/* Native Win32. */ + #include <sys/types.h> #include <stdbool.h> #include <errno.h> @@ -420,4 +422,25 @@ rpl_select (int nfds, fd_set *rfds, fd_set *wfds, fd_set *xfds, return rc; } -#endif /* Native Win32. */ +#else /* ! Native Win32. */ + +#include <sys/select.h> + +#undef select + +int +rpl_select (int nfds, fd_set *rfds, fd_set *wfds, fd_set *xfds, + struct timeval *timeout) +{ + /* Interix 3.5 has a bug: it does not support nfds == 0. */ + if (nfds == 0) + { + nfds = 1; + rfds = NULL; + wfds = NULL; + xfds = NULL; + } + return select (nfds, rfds, wfds, xfds, timeout); +} + +#endif diff --git a/gl/setsockopt.c b/gl/setsockopt.c index 09f048e48a..96a00cc2e7 100644 --- a/gl/setsockopt.c +++ b/gl/setsockopt.c @@ -1,6 +1,6 @@ /* setsockopt.c --- wrappers for Windows setsockopt function - Copyright (C) 2008 Free Software Foundation, Inc. + Copyright (C) 2008-2009 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 @@ -23,16 +23,31 @@ /* Get winsock2.h. */ #include <sys/socket.h> +/* Get struct timeval. */ +#include <sys/time.h> + /* Get set_winsock_errno, FD_TO_SOCKET etc. */ #include "w32sock.h" #undef setsockopt int -rpl_setsockopt (int fd, int level, int optname, const void *optval, int optlen) +rpl_setsockopt (int fd, int level, int optname, const void *optval, socklen_t optlen) { + int r; SOCKET sock = FD_TO_SOCKET (fd); - int r = setsockopt (sock, level, optname, optval, optlen); + + if (level == SOL_SOCKET && (optname == SO_RCVTIMEO || optname == SO_SNDTIMEO)) + { + const struct timeval *tv = optval; + int milliseconds = tv->tv_sec * 1000 + tv->tv_usec / 1000; + r = setsockopt (sock, level, optname, &milliseconds, sizeof (int)); + } + else + { + r = setsockopt (sock, level, optname, optval, optlen); + } + if (r < 0) set_winsock_errno (); diff --git a/gl/stdint.in.h b/gl/stdint.in.h index f141c8f606..53aa34a870 100644 --- a/gl/stdint.in.h +++ b/gl/stdint.in.h @@ -435,7 +435,7 @@ typedef int _verify_intmax_size[2 * (sizeof (intmax_t) == sizeof (uintmax_t)) - #undef PTRDIFF_MIN #undef PTRDIFF_MAX #if @APPLE_UNIVERSAL_BUILD@ -# if _LP64 +# ifdef _LP64 # define PTRDIFF_MIN _STDINT_MIN (1, 64, 0l) # define PTRDIFF_MAX _STDINT_MAX (1, 64, 0l) # else @@ -463,7 +463,7 @@ typedef int _verify_intmax_size[2 * (sizeof (intmax_t) == sizeof (uintmax_t)) - /* size_t limit */ #undef SIZE_MAX #if @APPLE_UNIVERSAL_BUILD@ -# if _LP64 +# ifdef _LP64 # define SIZE_MAX _STDINT_MAX (0, 64, 0ul) # else # define SIZE_MAX _STDINT_MAX (0, 32, 0ul) diff --git a/gl/sys_select.in.h b/gl/sys_select.in.h index ff2a0f7457..e87b7d04bb 100644 --- a/gl/sys_select.in.h +++ b/gl/sys_select.in.h @@ -1,5 +1,5 @@ /* Substitute for <sys/select.h>. - Copyright (C) 2007-2008 Free Software Foundation, Inc. + Copyright (C) 2007-2009 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 @@ -66,7 +66,7 @@ extern "C" { # endif # if @GNULIB_SELECT@ -# if @HAVE_WINSOCK2_H@ +# if @HAVE_WINSOCK2_H@ || @REPLACE_SELECT@ # undef select # define select rpl_select extern int rpl_select (int, fd_set *, fd_set *, fd_set *, struct timeval *); diff --git a/gl/sys_socket.in.h b/gl/sys_socket.in.h index 5d9b3cdb50..311d2d69c7 100644 --- a/gl/sys_socket.in.h +++ b/gl/sys_socket.in.h @@ -1,6 +1,6 @@ /* Provide a sys/socket header file for systems lacking it (read: MinGW) and for systems where it is incomplete. - Copyright (C) 2005-2008 Free Software Foundation, Inc. + Copyright (C) 2005-2009 Free Software Foundation, Inc. Written by Simon Josefsson. This program is free software; you can redistribute it and/or modify @@ -256,7 +256,7 @@ extern int rpl_getsockname (int, struct sockaddr *, int *); # if @HAVE_WINSOCK2_H@ # undef getsockopt # define getsockopt rpl_getsockopt -extern int rpl_getsockopt (int, int, int, void *, int *); +extern int rpl_getsockopt (int, int, int, void *, socklen_t *); # endif # elif @HAVE_WINSOCK2_H@ # undef getsockopt @@ -358,7 +358,7 @@ extern int rpl_sendto (int, const void *, int, int, struct sockaddr *, int); # if @HAVE_WINSOCK2_H@ # undef setsockopt # define setsockopt rpl_setsockopt -extern int rpl_setsockopt (int, int, int, const void *, int); +extern int rpl_setsockopt (int, int, int, const void *, socklen_t); # endif # elif @HAVE_WINSOCK2_H@ # undef setsockopt diff --git a/gl/tests/Makefile.am b/gl/tests/Makefile.am index db02b328a8..92458c1b1a 100644 --- a/gl/tests/Makefile.am +++ b/gl/tests/Makefile.am @@ -213,6 +213,8 @@ EXTRA_DIST += test-snprintf.c libtests_a_SOURCES += sockets.h sockets.c +EXTRA_DIST += w32sock.h + ## end gnulib module sockets ## begin gnulib module sockets-tests diff --git a/gl/tests/sockets.c b/gl/tests/sockets.c index 658119ea43..9d5c547928 100644 --- a/gl/tests/sockets.c +++ b/gl/tests/sockets.c @@ -1,6 +1,6 @@ /* sockets.c --- wrappers for Windows socket functions - Copyright (C) 2008 Free Software Foundation, Inc. + Copyright (C) 2008-2009 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,10 +19,57 @@ #include <config.h> +/* Specification. */ +#include "sockets.h" + +#if WINDOWS_SOCKETS + /* This includes winsock2.h on MinGW. */ #include <sys/socket.h> -#include "sockets.h" +#include "close-hook.h" + +/* Get set_winsock_errno, FD_TO_SOCKET etc. */ +#include "w32sock.h" + +static int +close_fd_maybe_socket (int fd, const struct close_hook *remaining_list) +{ + SOCKET sock; + WSANETWORKEVENTS ev; + + /* Test whether fd refers to a socket. */ + sock = FD_TO_SOCKET (fd); + ev.lNetworkEvents = 0xDEADBEEF; + WSAEnumNetworkEvents (sock, NULL, &ev); + if (ev.lNetworkEvents != 0xDEADBEEF) + { + /* fd refers to a socket. */ + /* FIXME: other applications, like squid, use an undocumented + _free_osfhnd free function. But this is not enough: The 'osfile' + flags for fd also needs to be cleared, but it is hard to access it. + Instead, here we just close twice the file descriptor. */ + if (closesocket (sock)) + { + set_winsock_errno (); + return -1; + } + else + { + /* This call frees the file descriptor and does a + CloseHandle ((HANDLE) _get_osfhandle (fd)), which fails. */ + _close (fd); + return 0; + } + } + else + /* Some other type of file descriptor. */ + return execute_close_hooks (fd, remaining_list); +} + +static struct close_hook close_sockets_hook; + +#endif int gl_sockets_startup (int version) @@ -37,6 +84,8 @@ gl_sockets_startup (int version) if (data.wVersion < version) return 2; + + register_close_hook (close_fd_maybe_socket, &close_sockets_hook); #endif return 0; @@ -48,6 +97,8 @@ gl_sockets_cleanup (void) #if WINDOWS_SOCKETS int err; + unregister_close_hook (&close_sockets_hook); + err = WSACleanup (); if (err != 0) return 1; diff --git a/gl/tests/sockets.h b/gl/tests/sockets.h index bf180ac95d..b42e368d21 100644 --- a/gl/tests/sockets.h +++ b/gl/tests/sockets.h @@ -33,13 +33,19 @@ int gl_sockets_cleanup (void); Winsock wrappers but needs to pass on the socket handle to some other library that only accepts sockets. */ #if WINDOWS_SOCKETS + +#include <sys/socket.h> + static inline SOCKET gl_fd_to_handle (int fd) { return _get_osfhandle (fd); } + #else + #define gl_fd_to_handle(x) (x) -#endif -#endif +#endif /* WINDOWS_SOCKETS */ + +#endif /* SOCKETS_H */ diff --git a/gl/tests/test-getaddrinfo.c b/gl/tests/test-getaddrinfo.c index 5e33bb24f1..eeea3f7c43 100644 --- a/gl/tests/test-getaddrinfo.c +++ b/gl/tests/test-getaddrinfo.c @@ -19,7 +19,9 @@ #include <config.h> #include <netdb.h> + #include <arpa/inet.h> +#include <errno.h> #include <netinet/in.h> #include <stdio.h> #include <string.h> @@ -49,6 +51,7 @@ int simple (char *host, char *service) struct addrinfo hints; struct addrinfo *ai0, *ai; int res; + int err; /* Once we skipped the test, do not try anything else */ if (skip) @@ -64,6 +67,7 @@ int simple (char *host, char *service) hints.ai_socktype = SOCK_STREAM; res = getaddrinfo (host, service, 0, &ai0); + err = errno; dbgprintf ("res %d: %s\n", res, gai_strerror (res)); @@ -83,13 +87,16 @@ int simple (char *host, char *service) if (res == EAI_NONAME) return 0; /* Solaris reports EAI_SERVICE for "http" and "https". Don't - fail the test merely because of this. */ + fail the test merely because of this. */ if (res == EAI_SERVICE) return 0; /* AIX reports EAI_NODATA for "https". Don't fail the test merely because of this. */ if (res == EAI_NODATA) return 0; + /* Provide details if errno was set. */ + if (res == EAI_SYSTEM) + dbgprintf ("system error: %s\n", strerror (err)); return 1; } diff --git a/gl/tests/test-sockets.c b/gl/tests/test-sockets.c index a37a1978c4..3c85a431c5 100644 --- a/gl/tests/test-sockets.c +++ b/gl/tests/test-sockets.c @@ -40,7 +40,7 @@ main (int argc, char *argv[]) return 1; } - gl_fd_to_handle (0); + (void) gl_fd_to_handle (0); return 0; } diff --git a/gl/unistd.in.h b/gl/unistd.in.h index f0a674079d..fa8d84a3d9 100644 --- a/gl/unistd.in.h +++ b/gl/unistd.in.h @@ -131,10 +131,6 @@ extern int chown (const char *file, uid_t uid, gid_t gid); #if @GNULIB_CLOSE@ -# if @UNISTD_H_HAVE_WINSOCK2_H@ -/* Need a gnulib internal function. */ -# define HAVE__GL_CLOSE_FD_MAYBE_SOCKET 1 -# endif # if @REPLACE_CLOSE@ /* Automatically included by modules that need a replacement for close. */ # undef close diff --git a/gl/vasnprintf.c b/gl/vasnprintf.c index 1b9d5ded74..a583ebd299 100644 --- a/gl/vasnprintf.c +++ b/gl/vasnprintf.c @@ -413,7 +413,7 @@ divide (mpn_t a, mpn_t b, mpn_t *q) Normalise [q[m-1],...,q[0]], yields q. If m>=n>1, perform a multiple-precision division: We have a/b < beta^(m-n+1). - s:=intDsize-1-(hightest bit in b[n-1]), 0<=s<intDsize. + s:=intDsize-1-(highest bit in b[n-1]), 0<=s<intDsize. Shift a and b left by s bits, copying them. r:=a. r=[r[m],...,r[0]], b=[b[n-1],...,b[0]] with b[n-1]>=beta/2. For j=m-n,...,0: {Here 0 <= r < b*beta^(j+1).} |