diff options
45 files changed, 1076 insertions, 213 deletions
diff --git a/GNUmakefile b/GNUmakefile index 0fdd3fa735..33eb3aa4d5 100644 --- a/GNUmakefile +++ b/GNUmakefile @@ -5,7 +5,7 @@ # It is necessary if you want to build targets usually of interest # only to the maintainer. -# Copyright (C) 2001, 2003, 2006-2008 Free Software Foundation, Inc. +# Copyright (C) 2001, 2003, 2006-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 @@ -38,6 +38,9 @@ ifeq ($(_have-Makefile),yes) # Make tar archive easier to reproduce. export TAR_OPTIONS = --owner=0 --group=0 --numeric-owner +# Allow the user to add to this in the Makefile. +ALL_RECURSIVE_TARGETS = + include Makefile # Some projects override e.g., _autoreconf here. @@ -61,7 +64,7 @@ ifeq ($(_have-git-version-gen)0,yes$(MAKELEVEL)) && $(_build-aux)/git-version-gen .tarball-version) ifneq ($(_curr-ver),$(VERSION)) ifeq ($(_curr-ver),UNKNOWN) - $(info WARNING: unable to verify if $(VERSION) is correct version) + $(info WARNING: unable to verify if $(VERSION) is the correct version) else ifneq (,$(_is-install-target)) # GNU Coding Standards state that 'make install' should not cause @@ -107,6 +110,18 @@ abort-due-to-no-makefile: endif # Tell version 3.79 and up of GNU make to not build goals in this -# directory in parallel. This is necessary in case someone tries to -# build multiple targets on one command line. +# directory in parallel, in case someone tries to build multiple +# targets, and one of them can cause a recursive target to be invoked. + +# Only set this if Automake doesn't provide it. +AM_RECURSIVE_TARGETS ?= $(RECURSIVE_TARGETS:-recursive=) \ + $(RECURSIVE_CLEAN_TARGETS:-recursive=) \ + dist distcheck tags ctags + +ALL_RECURSIVE_TARGETS += $(AM_RECURSIVE_TARGETS) + +ifneq ($(word 2, $(MAKECMDGOALS)), ) +ifneq ($(filter $(ALL_RECURSIVE_TARGETS), $(MAKECMDGOALS)), ) .NOTPARALLEL: +endif +endif diff --git a/build-aux/gnupload b/build-aux/gnupload index 5d4289ffc9..7c34784e41 100755 --- a/build-aux/gnupload +++ b/build-aux/gnupload @@ -1,9 +1,9 @@ #!/bin/sh # Sign files and upload them. -scriptversion=2009-01-30.00 +scriptversion=2009-03-05.20 -# Copyright (C) 2004, 2005, 2006, 2007, 2008, 2009 Free Software Foundation +# Copyright (C) 2004, 2005, 2006, 2007, 2008, 2009 Free Software Foundation # # 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,101 +23,193 @@ scriptversion=2009-01-30.00 set -e GPG='gpg --batch --no-tty' +conffile=.gnuploadrc to= -delete=false +dry_run=false +symlink_files= +delete_files= +delete_symlinks= +collect_var= +dbg= -usage="Usage: $0 [OPTIONS]... FILES... +usage="Usage: $0 [OPTIONS]... [COMMAND] FILES... [[COMMAND] FILES...] -Sign all FILES, and upload them to (or delete them from) selected -destinations, according to +Sign all FILES, and upload them to selected destinations, according to <http://www.gnu.org/prep/maintain/html_node/Automated-FTP-Uploads.html>. +Commands: + --delete delete FILES from destination + --symlink create symbolic links + --rmsymlink remove symbolic links + -- treat the remaining arguments as files to upload + Options: --help print this help text and exit --to DEST specify one destination for FILES (multiple --to options are allowed) --user NAME sign with key NAME - --delete delete FILES from destination instead of uploading + --symlink-regex[=EXPR] use sed script EXPR to compute symbolic link names + --dry-run do nothing, show what would have been done --version output version information and exit +If --symlink-regex is given without EXPR, then the link target name +is created by replacing the version information with \`-latest', e.g.: + + foo-1.3.4.tar.gz -> foo-latest.tar.gz + Recognized destinations are: alpha.gnu.org:DIRECTORY savannah.gnu.org:DIRECTORY savannah.nongnu.org:DIRECTORY ftp.gnu.org:DIRECTORY build directive files and upload files by FTP + download.gnu.org.ua:{alpha|ftp}/DIRECTORY + build directive files and upload files by SFTP [user@]host:DIRECTORY upload files with scp -Deletion only works for ftp.gnu.org and alpha.gnu.org (using the -archive: directive). Otherwise it is a no-op. Deleting a file foo also -deletes foo.sig; do not specify the .sig explicitly. +Options and commands are applied in order. If the file $conffile exists +in the current working directory, its contents are prepended to the +actual command line options. Use this to keep your defaults. Comments +(#) and empty lines in $conffile are allowed. -Simple single-target single-file examples: - gnupload --to alpha.gnu.org:automake automake-1.8.2b.tar.gz - gnupload --to ftp.gnu.org:automake automake-1.8.3.tar.gz - gnupload --to alpha.gnu.org:automake --delete automake-oops.tar.gz +Examples: +1. Upload automake-1.8.2b.tar.gz and automake-1.8.2b.tar.bz2 to two sites: + gnupload --to sources.redhat.com:~ftp/pub/automake \\ + --to alpha.gnu.org:automake \\ + automake-1.8.2b.tar.gz automake-1.8.2b.tar.bz2 -Multiple-target multiple-file example: +2. Same as above, but also create symbolic links to automake-latest.tar.*: gnupload --to sources.redhat.com:~ftp/pub/automake \\ --to alpha.gnu.org:automake \\ + --symlink-regex \\ automake-1.8.2b.tar.gz automake-1.8.2b.tar.bz2 -You can get the latest version of this script from savannah: -<http://git.savannah.gnu.org/cgit/automake.git/plain/lib/gnupload> +3. Symlink automake-1.8.2b.tar.gz to automake-latest.tar.gz and +automake-1.8.2b.tar.bz2 to automake-latest.tar.bz2 on both sites: + + gnupload --to sources.redhat.com:~ftp/pub/automake \\ + --to alpha.gnu.org:automake \\ + --symlink automake-1.8.2b.tar.gz automake-latest.tar.gz \\ + automake-1.8.2b.tar.bz2 automake-latest.tar.bz2 + +4. Delete automake-1.8.2a.tar.gz and .bz2, remove symlink +automake-latest.tar.gz and upload automake-1.8.2b.tar.gz: + + gnupload --to sources.redhat.com:~ftp/pub/automake \\ + --to alpha.gnu.org:automake \\ + --delete automake-1.8.2a.tar.gz automake-1.8.2a.tar.bz2 \\ + --rmsymlink automake-latest.tar.gz \\ + -- \\ + automake-1.8.2b.tar.gz automake-1.8.2b.tar.bz2 Report bugs to <bug-automake@gnu.org>. Send patches to <automake-patches@gnu.org>." +# Read local configuration file +if test -r "$conffile"; then + echo "$0: Reading configuration file $conffile" + eval set x "`sed 's/#.*$//;/^$/d' \"$conffile\" | tr '\012\015' ' '` \"\$@\"" + shift +fi + while test -n "$1"; do case $1 in - --delete) - delete=true - shift - ;; + -*) + collect_var= + case $1 in --help) echo "$usage" exit $? ;; --to) if test -z "$2"; then - echo "$0: Missing argument for --to" 1>&2 + echo "$0: Missing argument for --to" 1>&2 exit 1 else to="$to $2" - shift 2 + shift fi ;; --user) if test -z "$2"; then - echo "$0: Missing argument for --user" 1>&2 + echo "$0: Missing argument for --user" 1>&2 exit 1 else GPG="$GPG --local-user $2" - shift 2 + shift fi ;; + --delete) + collect_var=delete_files + ;; + --rmsymlink) + collect_var=delete_symlinks + ;; + --symlink-regex=*) + symlink_expr=`expr "$1" : '[^=]*=\(.*\)'` + ;; + --symlink-regex) + symlink_expr='s|-[0-9][0-9\.]*\(-[0-9][0-9]*\)\{0,1\}\.|-latest.|' + ;; + --symlink) + collect_var=symlink_files + ;; + --dry-run|-n) + dry_run=: + ;; --version) echo "gnupload $scriptversion" exit $? ;; + --) + shift + break + ;; -*) echo "$0: Unknown option \`$1', try \`$0 --help'" 1>&2 exit 1 ;; - *) + esac + ;; + *) + if test -z "$collect_var"; then break - ;; + else + eval "$collect_var=\"\$$collect_var $1\"" + fi + ;; esac + shift done -if test $# = 0; then - echo "$0: No file to upload or delete" 1>&2 +dprint() +{ + echo "Running $*..." +} + +if $dry_run; then + dbg=dprint +fi + +if test -z "$to"; then + echo "$0: Missing destination sites" >&2 exit 1 -else - : fi -if $delete; then :; else +if test -n "$symlink_files"; then + x=`echo "$symlink_files" | sed 's/[^ ]//g;s/ //g'` + if test -n "$x"; then + echo "$0: Odd number of symlink arguments" >&2 + exit 1 + fi +fi + +if test $# = 0; then + if test -z "${symlink_files}${delete_files}${delete_symlinks}"; then + echo "$0: No file to upload" 1>&2 + exit 1 + fi +else # Make sure all files exist. We don't want to ask # for the passphrase if the script will fail. for file @@ -125,8 +217,15 @@ if $delete; then :; else if test ! -f $file; then echo "$0: Cannot find \`$file'" 1>&2 exit 1 - else - : + elif test -n "$symlink_expr"; then + linkname=`echo $file | sed "$symlink_expr"` + if test -z "$linkname"; then + echo "$0: symlink expression produces empty results" >&2 + exit 1 + elif test "$linkname" = $file; then + echo "$0: symlink expression does not alter file name" >&2 + exit 1 + fi fi done fi @@ -146,72 +245,164 @@ read -r passphrase stty echo echo -# Nothing to sign if deleting. -if $delete; then :; else +if test $# -ne 0; then for file do echo "Signing $file..." rm -f $file.sig - echo $passphrase | $GPG --passphrase-fd 0 -ba -o $file.sig $file + echo "$passphrase" | $dbg $GPG --passphrase-fd 0 -ba -o $file.sig $file + done +fi + + +# mkdirective DESTDIR BASE FILE STMT +# Arguments: See upload, below +mkdirective () +{ + stmt="$4" + if test -n "$3"; then + stmt=" +filename: $3$stmt" + fi + + cat >${2}.directive<<EOF +version: 1.1 +directory: $1 +comment: gnupload v. $scriptversion$stmt +EOF + if $dry_run; then + echo "File ${2}.directive:" + cat ${2}.directive + echo "File ${2}.directive:" | sed 's/./-/g' + fi +} + +mksymlink () +{ + while test $# -ne 0 + do + echo "symlink: $1 $2" + shift + shift + done +} + +# upload DEST DESTDIR BASE FILE STMT FILES +# Arguments: +# DEST Destination site; +# DESTDIR Destination directory; +# BASE Base name for the directive file; +# FILE Name of the file to distribute (may be empty); +# STMT Additional statements for the directive file; +# FILES List of files to upload. +upload () +{ + dest=$1 + destdir=$2 + base=$3 + file=$4 + stmt=$5 + files=$6 + + rm -f $base.directive $base.directive.asc + case $dest in + alpha.gnu.org:*) + mkdirective "$destdir" "$base" "$file" "$stmt" + echo "$passphrase" | $dbg $GPG --passphrase-fd 0 --clearsign $base.directive + $dbg ncftpput ftp-upload.gnu.org /incoming/alpha $files $base.directive.asc + ;; + ftp.gnu.org:*) + mkdirective "$destdir" "$base" "$file" "$stmt" + echo "$passphrase" | $dbg $GPG --passphrase-fd 0 --clearsign $base.directive + $dbg ncftpput ftp-upload.gnu.org /incoming/ftp $files $base.directive.asc + ;; + savannah.gnu.org:*) + if test -z "$files"; then + echo "$0: warning: standalone directives not applicable for $dest" >&2 + fi + $dbg ncftpput savannah.gnu.org /incoming/savannah/$destdir $files + ;; + savannah.nongnu.org:*) + if test -z "$files"; then + echo "$0: warning: standalone directives not applicable for $dest" >&2 + fi + $dbg ncftpput savannah.nongnu.org /incoming/savannah/$destdir $files + ;; + download.gnu.org.ua:alpha/*|download.gnu.org.ua:ftp/*) + destdir_p1=`echo "$destdir" | sed 's,^[^/]*/,,'` + destdir_topdir=`echo "$destdir" | sed 's,/.*,,'` + mkdirective "$destdir_p1" "$base" "$file" "$stmt" + echo "$passphrase" | $dbg $GPG --passphrase-fd 0 --clearsign $base.directive + for f in $files $base.directive.asc + do + echo put $f + done | $dbg sftp -b - puszcza.gnu.org.ua:/incoming/$destdir_topdir + ;; + /*) + dest_host=`echo "$dest" | sed 's,:.*,,'` + mkdirective "$destdir" "$base" "$file" "$stmt" + echo "$passphrase" | $dbg $GPG --passphrase-fd 0 --clearsign $base.directive + $dbg cp $files $base.directive.asc $dest_host + ;; + *) + if test -z "$files"; then + echo "$0: warning: standalone directives not applicable for $dest" >&2 + fi + $dbg scp $files $dest + ;; + esac + rm -f $base.directive $base.directive.asc +} + +##### +# Process any standalone directives +stmt= +if test -n "$symlink_files"; then + stmt="$stmt +`mksymlink $symlink_files`" +fi + +for file in $delete_files +do + stmt="$stmt +archive: $file" +done + +for file in $delete_symlinks +do + stmt="$stmt +rmsymlink: $file" +done + +if test -n "$stmt"; then + for dest in $to + do + destdir=`echo $dest | sed 's/[^:]*://'` + upload "$dest" "$destdir" "`hostname`-$$" "" "$stmt" done fi +# Process actual uploads for dest in $to do for file do - # Prepare arguments. - if $delete; then - echo "Removing $file from $dest..." - files= # nothing to upload if deleting - directive="archive: $file" - else - echo "Uploading $file to $dest..." - files="$file $file.sig" - directive="filename: "`basename -- "$file"` - fi + echo "Uploading $file to $dest..." + stmt= + files="$file $file.sig" destdir=`echo $dest | sed 's/[^:]*://'` - - case $dest in - alpha.gnu.org:*) - rm -f $file.directive $file.directive.asc - cat >$file.directive<<EOF -version: 1.1 -directory: $destdir -$directive -EOF - echo "$passphrase" | $GPG --passphrase-fd 0 --clearsign $file.directive - ncftpput ftp-upload.gnu.org /incoming/alpha $files $file.directive.asc - rm -f $file.directive $file.directive.asc - ;; - ftp.gnu.org:*) - rm -f $file.directive $file.directive.asc - cat >$file.directive<<EOF -version: 1.1 -directory: $destdir -$directive -EOF - echo "$passphrase" | $GPG --passphrase-fd 0 --clearsign $file.directive - ncftpput ftp-upload.gnu.org /incoming/ftp $files $file.directive.asc - rm -f $file.directive $file.directive.asc - ;; - savannah.gnu.org:*) - # We only know how to implement delete for {ftp,alpha}.gnu.org. - $delete \ - || ncftpput savannah.gnu.org /incoming/savannah/$destdir $files - ;; - savannah.nongnu.org:*) - $delete \ - || ncftpput savannah.nongnu.org /incoming/savannah/$destdir $files - ;; - *) - $delete \ - || scp $files $dest - ;; - esac + if test -n "$symlink_expr"; then + linkname=`echo $file | sed "$symlink_expr"` + stmt="$stmt +symlink: $file $linkname +symlink: $file.sig $linkname.sig" + fi + upload "$dest" "$destdir" "$file" "$file" "$stmt" "$files" done done +exit 0 + # Local variables: # eval: (add-hook 'write-file-hooks 'time-stamp) # time-stamp-start: "scriptversion=" 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).} diff --git a/lib/gl/Makefile.am b/lib/gl/Makefile.am index fd1e88972f..e06f9e1d19 100644 --- a/lib/gl/Makefile.am +++ b/lib/gl/Makefile.am @@ -29,6 +29,7 @@ SUBDIRS += tests EXTRA_DIST += m4/gnulib-cache.m4 AM_CPPFLAGS = +AM_CFLAGS = noinst_LTLIBRARIES += liblgnu.la @@ -78,6 +79,14 @@ liblgnu_la_SOURCES += c-ctype.h c-ctype.c ## end gnulib module c-ctype +## begin gnulib module close-hook + +liblgnu_la_SOURCES += close-hook.c + +EXTRA_DIST += close-hook.h + +## end gnulib module close-hook + ## begin gnulib module errno BUILT_SOURCES += $(ERRNO_H) @@ -270,6 +279,8 @@ EXTRA_liblgnu_la_SOURCES += snprintf.c liblgnu_la_SOURCES += sockets.h sockets.c +EXTRA_DIST += w32sock.h + ## end gnulib module sockets ## begin gnulib module stdbool diff --git a/lib/gl/close-hook.c b/lib/gl/close-hook.c new file mode 100644 index 0000000000..045dcf7210 --- /dev/null +++ b/lib/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 Lesser General Public License as published + by the Free Software Foundation; either version 2.1 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 Lesser 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/lib/gl/close-hook.h b/lib/gl/close-hook.h new file mode 100644 index 0000000000..483d69c8da --- /dev/null +++ b/lib/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 Lesser General Public License as published + by the Free Software Foundation; either version 2.1 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 Lesser 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/lib/gl/fseeko.c b/lib/gl/fseeko.c index 7ba8e58431..b2ed87c420 100644 --- a/lib/gl/fseeko.c +++ b/lib/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/lib/gl/m4/gnulib-common.m4 b/lib/gl/m4/gnulib-common.m4 index 50e399aa1c..c8fda20330 100644 --- a/lib/gl/m4/gnulib-common.m4 +++ b/lib/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/lib/gl/m4/gnulib-comp.m4 b/lib/gl/m4/gnulib-comp.m4 index 77ca8b8fd9..2319787e96 100644 --- a/lib/gl/m4/gnulib-comp.m4 +++ b/lib/gl/m4/gnulib-comp.m4 @@ -79,7 +79,6 @@ AC_DEFUN([lgl_INIT], gl_FUNC_STRVERSCMP gl_STRING_MODULE_INDICATOR([strverscmp]) gl_HEADER_SYS_SOCKET - gl_MODULE_INDICATOR([sys_socket]) AC_PROG_MKDIR_P gl_HEADER_SYS_STAT_H AC_PROG_MKDIR_P @@ -236,6 +235,8 @@ AC_DEFUN([lgl_FILE_LIST], [ lib/byteswap.in.h lib/c-ctype.c lib/c-ctype.h + lib/close-hook.c + lib/close-hook.h lib/errno.in.h lib/float+.h lib/float.in.h @@ -277,6 +278,7 @@ AC_DEFUN([lgl_FILE_LIST], [ lib/vasnprintf.c lib/vasnprintf.h lib/vasprintf.c + lib/w32sock.h lib/wchar.in.h lib/xsize.h m4/00gnulib.m4 diff --git a/lib/gl/m4/printf.m4 b/lib/gl/m4/printf.m4 index 4207ace49f..87aa45c5e7 100644 --- a/lib/gl/m4/printf.m4 +++ b/lib/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/lib/gl/sockets.c b/lib/gl/sockets.c index 4d03346e64..758bad98ae 100644 --- a/lib/gl/sockets.c +++ b/lib/gl/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 Lesser 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/lib/gl/sockets.h b/lib/gl/sockets.h index 6785824bd0..315d1b6422 100644 --- a/lib/gl/sockets.h +++ b/lib/gl/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/lib/gl/stdint.in.h b/lib/gl/stdint.in.h index 7cbfc2cf7e..e7a3be57b0 100644 --- a/lib/gl/stdint.in.h +++ b/lib/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/lib/gl/sys_socket.in.h b/lib/gl/sys_socket.in.h index c8247e9ab3..575bbb7517 100644 --- a/lib/gl/sys_socket.in.h +++ b/lib/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/lib/gl/tests/test-sockets.c b/lib/gl/tests/test-sockets.c index a37a1978c4..3c85a431c5 100644 --- a/lib/gl/tests/test-sockets.c +++ b/lib/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/lib/gl/unistd.in.h b/lib/gl/unistd.in.h index c1a2d2ba99..4c1fc3fdaa 100644 --- a/lib/gl/unistd.in.h +++ b/lib/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/lib/gl/vasnprintf.c b/lib/gl/vasnprintf.c index f7cf309c4d..67834fa913 100644 --- a/lib/gl/vasnprintf.c +++ b/lib/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).} diff --git a/lib/gl/w32sock.h b/lib/gl/w32sock.h new file mode 100644 index 0000000000..12977f7cab --- /dev/null +++ b/lib/gl/w32sock.h @@ -0,0 +1,62 @@ +/* w32sock.h --- internal auxilliary functions for Windows socket functions + + Copyright (C) 2008 Free Software Foundation, Inc. + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU Lesser General Public License as published by + the Free Software Foundation; either version 2.1 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 Lesser General Public License + along with this program. If not, see <http://www.gnu.org/licenses/>. */ + +/* Written by Paolo Bonzini */ + +#include <errno.h> + +/* Get O_RDWR and O_BINARY. */ +#include <fcntl.h> + +/* Get _get_osfhandle() and _open_osfhandle(). */ +#include <io.h> + +#define FD_TO_SOCKET(fd) ((SOCKET) _get_osfhandle ((fd))) +#define SOCKET_TO_FD(fh) (_open_osfhandle ((long) (fh), O_RDWR | O_BINARY)) + +static inline void +set_winsock_errno (void) +{ + int err = WSAGetLastError (); + WSASetLastError (0); + + /* Map some WSAE* errors to the runtime library's error codes. */ + switch (err) + { + case WSA_INVALID_HANDLE: + errno = EBADF; + break; + case WSA_NOT_ENOUGH_MEMORY: + errno = ENOMEM; + break; + case WSA_INVALID_PARAMETER: + errno = EINVAL; + break; + case WSAEWOULDBLOCK: + errno = EWOULDBLOCK; + break; + case WSAENAMETOOLONG: + errno = ENAMETOOLONG; + break; + case WSAENOTEMPTY: + errno = ENOTEMPTY; + break; + default: + errno = (err > 10000 && err < 10025) ? err - 10000 : err; + break; + } +} diff --git a/libextra/gl/m4/gnulib-common.m4 b/libextra/gl/m4/gnulib-common.m4 index 50e399aa1c..c8fda20330 100644 --- a/libextra/gl/m4/gnulib-common.m4 +++ b/libextra/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" +]) @@ -2,7 +2,7 @@ # This Makefile fragment is intended to be useful by any GNU-like project. # This file originate from coreutils, CPPI, Bison, and Autoconf. -# Copyright (C) 2001-2008 Free Software Foundation, Inc. +# Copyright (C) 2001-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 @@ -110,15 +110,15 @@ syntax-check: $(syntax-check-rules) # Code Coverage init-coverage: - make clean + $(MAKE) $(AM_MAKEFLAGS) clean lcov --directory . --zerocounters COVERAGE_CCOPTS ?= "-g --coverage" COVERAGE_OUT ?= doc/coverage build-coverage: - make CFLAGS=$(COVERAGE_CCOPTS) CXXFLAGS=$(COVERAGE_CCOPTS) - make CFLAGS=$(COVERAGE_CCOPTS) CXXFLAGS=$(COVERAGE_CCOPTS) check + $(MAKE) $(AM_MAKEFLAGS) CFLAGS=$(COVERAGE_CCOPTS) CXXFLAGS=$(COVERAGE_CCOPTS) + $(MAKE) $(AM_MAKEFLAGS) CFLAGS=$(COVERAGE_CCOPTS) CXXFLAGS=$(COVERAGE_CCOPTS) check mkdir -p $(COVERAGE_OUT) lcov --directory . --output-file $(COVERAGE_OUT)/$(PACKAGE).info \ --capture |