diff options
Diffstat (limited to 'gl/tests')
63 files changed, 57 insertions, 7658 deletions
diff --git a/gl/tests/Makefile.am b/gl/tests/Makefile.am index 866652b870..617c63c031 100644 --- a/gl/tests/Makefile.am +++ b/gl/tests/Makefile.am @@ -22,7 +22,7 @@ # # Generated by gnulib-tool. -AUTOMAKE_OPTIONS = 1.9.6 foreign subdir-objects +AUTOMAKE_OPTIONS = 1.9.6 foreign SUBDIRS = . TESTS = @@ -58,15 +58,6 @@ AM_LIBTOOLFLAGS = --preserve-dup-deps TESTS_ENVIRONMENT += EXEEXT='@EXEEXT@' srcdir='$(srcdir)' -## begin gnulib module accept-tests - -TESTS += test-accept -check_PROGRAMS += test-accept -test_accept_LDADD = $(LDADD) @LIBSOCKET@ -EXTRA_DIST += test-accept.c signature.h macros.h - -## end gnulib module accept-tests - ## begin gnulib module alloca-opt-tests TESTS += test-alloca-opt @@ -76,6 +67,42 @@ EXTRA_DIST += test-alloca-opt.c ## end gnulib module alloca-opt-tests +## begin gnulib module arpa_inet + +BUILT_SOURCES += arpa/inet.h + +# We need the following in order to create <arpa/inet.h> when the system +# doesn't have one. +arpa/inet.h: arpa_inet.in.h $(top_builddir)/config.status $(CXXDEFS_H) $(WARN_ON_USE_H) $(ARG_NONNULL_H) + $(AM_V_at)$(MKDIR_P) arpa + $(AM_V_GEN)rm -f $@-t $@ && \ + { echo '/* DO NOT EDIT! GENERATED AUTOMATICALLY! */'; \ + sed -e 's|@''GUARD_PREFIX''@|GL|g' \ + -e 's|@''INCLUDE_NEXT''@|$(INCLUDE_NEXT)|g' \ + -e 's|@''PRAGMA_SYSTEM_HEADER''@|@PRAGMA_SYSTEM_HEADER@|g' \ + -e 's|@''PRAGMA_COLUMNS''@|@PRAGMA_COLUMNS@|g' \ + -e 's|@''HAVE_FEATURES_H''@|$(HAVE_FEATURES_H)|g' \ + -e 's|@''NEXT_ARPA_INET_H''@|$(NEXT_ARPA_INET_H)|g' \ + -e 's|@''HAVE_ARPA_INET_H''@|$(HAVE_ARPA_INET_H)|g' \ + -e 's/@''GNULIB_INET_NTOP''@/$(GNULIB_INET_NTOP)/g' \ + -e 's/@''GNULIB_INET_PTON''@/$(GNULIB_INET_PTON)/g' \ + -e 's|@''HAVE_DECL_INET_NTOP''@|$(HAVE_DECL_INET_NTOP)|g' \ + -e 's|@''HAVE_DECL_INET_PTON''@|$(HAVE_DECL_INET_PTON)|g' \ + -e 's|@''REPLACE_INET_NTOP''@|$(REPLACE_INET_NTOP)|g' \ + -e 's|@''REPLACE_INET_PTON''@|$(REPLACE_INET_PTON)|g' \ + -e '/definitions of _GL_FUNCDECL_RPL/r $(CXXDEFS_H)' \ + -e '/definition of _GL_ARG_NONNULL/r $(ARG_NONNULL_H)' \ + -e '/definition of _GL_WARN_ON_USE/r $(WARN_ON_USE_H)' \ + < $(srcdir)/arpa_inet.in.h; \ + } > $@-t && \ + mv $@-t $@ +MOSTLYCLEANFILES += arpa/inet.h arpa/inet.h-t +MOSTLYCLEANDIRS += arpa + +EXTRA_DIST += arpa_inet.in.h + +## end gnulib module arpa_inet + ## begin gnulib module arpa_inet-tests TESTS += test-arpa_inet @@ -133,14 +160,6 @@ EXTRA_DIST += test-c-ctype.c macros.h ## end gnulib module c-ctype-tests -## begin gnulib module close-tests - -TESTS += test-close -check_PROGRAMS += test-close -EXTRA_DIST += test-close.c signature.h macros.h - -## end gnulib module close-tests - ## begin gnulib module connect-tests TESTS += test-connect @@ -150,21 +169,6 @@ EXTRA_DIST += test-connect.c signature.h macros.h ## end gnulib module connect-tests -## begin gnulib module dosname - - -EXTRA_DIST += dosname.h - -## end gnulib module dosname - -## begin gnulib module dup2-tests - -TESTS += test-dup2 -check_PROGRAMS += test-dup2 -EXTRA_DIST += test-dup2.c signature.h macros.h - -## end gnulib module dup2-tests - ## begin gnulib module errno-tests TESTS += test-errno @@ -217,6 +221,14 @@ EXTRA_DIST += test-fcntl-h.c ## end gnulib module fcntl-h-tests +## begin gnulib module fd-hook + +libtests_a_SOURCES += fd-hook.c + +EXTRA_DIST += fd-hook.h + +## end gnulib module fd-hook + ## begin gnulib module fdopen @@ -315,23 +327,6 @@ EXTRA_DIST += test-ftello.c test-ftello.sh test-ftello2.sh test-ftello3.c test-f ## end gnulib module ftello-tests -## begin gnulib module ftruncate - - -EXTRA_DIST += ftruncate.c - -EXTRA_libtests_a_SOURCES += ftruncate.c - -## end gnulib module ftruncate - -## begin gnulib module ftruncate-tests - -TESTS += test-ftruncate.sh -check_PROGRAMS += test-ftruncate -EXTRA_DIST += test-ftruncate.c test-ftruncate.sh signature.h macros.h - -## end gnulib module ftruncate-tests - ## begin gnulib module func-tests TESTS += test-func @@ -348,33 +343,6 @@ EXTRA_DIST += test-fwrite.c signature.h macros.h ## end gnulib module fwrite-tests -## begin gnulib module getaddrinfo-tests - -TESTS += test-getaddrinfo -check_PROGRAMS += test-getaddrinfo -test_getaddrinfo_LDADD = $(LDADD) @GETADDRINFO_LIB@ @LIBINTL@ -EXTRA_DIST += signature.h test-getaddrinfo.c - -## end gnulib module getaddrinfo-tests - -## begin gnulib module getcwd-lgpl - - -EXTRA_DIST += getcwd-lgpl.c - -EXTRA_libtests_a_SOURCES += getcwd-lgpl.c - -## end gnulib module getcwd-lgpl - -## begin gnulib module getcwd-lgpl-tests - -TESTS += test-getcwd-lgpl -check_PROGRAMS += test-getcwd-lgpl -test_getcwd_lgpl_LDADD = $(LDADD) $(LIBINTL) -EXTRA_DIST += test-getcwd-lgpl.c signature.h macros.h - -## end gnulib module getcwd-lgpl-tests - ## begin gnulib module getdelim-tests TESTS += test-getdelim @@ -384,23 +352,6 @@ EXTRA_DIST += test-getdelim.c signature.h macros.h ## end gnulib module getdelim-tests -## begin gnulib module getdtablesize - - -EXTRA_DIST += getdtablesize.c - -EXTRA_libtests_a_SOURCES += getdtablesize.c - -## end gnulib module getdtablesize - -## begin gnulib module getdtablesize-tests - -TESTS += test-getdtablesize -check_PROGRAMS += test-getdtablesize -EXTRA_DIST += test-getdtablesize.c signature.h macros.h - -## end gnulib module getdtablesize-tests - ## begin gnulib module getline-tests TESTS += test-getline @@ -419,15 +370,6 @@ EXTRA_libtests_a_SOURCES += getpagesize.c ## end gnulib module getpagesize -## begin gnulib module getpeername-tests - -TESTS += test-getpeername -check_PROGRAMS += test-getpeername -test_getpeername_LDADD = $(LDADD) @LIBSOCKET@ -EXTRA_DIST += test-getpeername.c signature.h macros.h - -## end gnulib module getpeername-tests - ## begin gnulib module gettimeofday-tests TESTS += test-gettimeofday @@ -447,29 +389,14 @@ EXTRA_DIST += test-iconv.c signature.h macros.h ## end gnulib module iconv-tests -## begin gnulib module ignore-value - - -EXTRA_DIST += ignore-value.h +## begin gnulib module inet_pton -## end gnulib module ignore-value -## begin gnulib module ignore-value-tests +EXTRA_DIST += inet_pton.c -TESTS += test-ignore-value -check_PROGRAMS += test-ignore-value -EXTRA_DIST += test-ignore-value.c +EXTRA_libtests_a_SOURCES += inet_pton.c -## end gnulib module ignore-value-tests - -## begin gnulib module inet_ntop-tests - -TESTS += test-inet_ntop -check_PROGRAMS += test-inet_ntop -test_inet_ntop_LDADD = $(LDADD) @INET_NTOP_LIB@ -EXTRA_DIST += test-inet_ntop.c signature.h macros.h - -## end gnulib module inet_ntop-tests +## end gnulib module inet_pton ## begin gnulib module inet_pton-tests @@ -541,55 +468,6 @@ EXTRA_DIST += test-inttypes.c ## end gnulib module inttypes-tests -## begin gnulib module ioctl - - -EXTRA_DIST += ioctl.c w32sock.h - -EXTRA_libtests_a_SOURCES += ioctl.c - -## end gnulib module ioctl - -## begin gnulib module ioctl-tests - -TESTS += test-ioctl -check_PROGRAMS += test-ioctl -EXTRA_DIST += test-ioctl.c signature.h macros.h - -## end gnulib module ioctl-tests - -## begin gnulib module listen-tests - -TESTS += test-listen -check_PROGRAMS += test-listen -test_listen_LDADD = $(LDADD) @LIBSOCKET@ -EXTRA_DIST += test-listen.c signature.h macros.h - -## end gnulib module listen-tests - -## begin gnulib module lock - -libtests_a_SOURCES += glthread/lock.h glthread/lock.c - -## end gnulib module lock - -## begin gnulib module lstat - - -EXTRA_DIST += lstat.c - -EXTRA_libtests_a_SOURCES += lstat.c - -## end gnulib module lstat - -## begin gnulib module lstat-tests - -TESTS += test-lstat -check_PROGRAMS += test-lstat -EXTRA_DIST += test-lstat.h test-lstat.c signature.h macros.h - -## end gnulib module lstat-tests - ## begin gnulib module memchr-tests TESTS += test-memchr @@ -614,72 +492,6 @@ EXTRA_DIST += test-netinet_in.c ## end gnulib module netinet_in-tests -## begin gnulib module open - - -EXTRA_DIST += open.c - -EXTRA_libtests_a_SOURCES += open.c - -## end gnulib module open - -## begin gnulib module open-tests - -TESTS += test-open -check_PROGRAMS += test-open -EXTRA_DIST += test-open.h test-open.c signature.h macros.h - -## end gnulib module open-tests - -## begin gnulib module pathmax - - -EXTRA_DIST += pathmax.h - -## end gnulib module pathmax - -## begin gnulib module pathmax-tests - -TESTS += test-pathmax -check_PROGRAMS += test-pathmax -EXTRA_DIST += test-pathmax.c - -## end gnulib module pathmax-tests - -## begin gnulib module perror - - -EXTRA_DIST += perror.c - -EXTRA_libtests_a_SOURCES += perror.c - -## end gnulib module perror - -## begin gnulib module perror-tests - -TESTS += test-perror.sh test-perror2 -check_PROGRAMS += test-perror test-perror2 -EXTRA_DIST += macros.h signature.h test-perror.c test-perror2.c test-perror.sh - -## end gnulib module perror-tests - -## begin gnulib module pipe-posix - - -EXTRA_DIST += pipe.c - -EXTRA_libtests_a_SOURCES += pipe.c - -## end gnulib module pipe-posix - -## begin gnulib module pipe-posix-tests - -TESTS += test-pipe -check_PROGRAMS += test-pipe -EXTRA_DIST += test-pipe.c signature.h macros.h - -## end gnulib module pipe-posix-tests - ## begin gnulib module read-file-tests TESTS += test-read-file @@ -688,87 +500,6 @@ EXTRA_DIST += test-read-file.c ## end gnulib module read-file-tests -## begin gnulib module recv-tests - -TESTS += test-recv -check_PROGRAMS += test-recv -test_recv_LDADD = $(LDADD) @LIBSOCKET@ -EXTRA_DIST += test-recv.c signature.h macros.h - -## end gnulib module recv-tests - -## begin gnulib module recvfrom-tests - -TESTS += test-recvfrom -check_PROGRAMS += test-recvfrom -test_recvfrom_LDADD = $(LDADD) @LIBSOCKET@ -EXTRA_DIST += test-recvfrom.c signature.h macros.h - -## end gnulib module recvfrom-tests - -## begin gnulib module same-inode - - -EXTRA_DIST += same-inode.h - -## end gnulib module same-inode - -## begin gnulib module select-tests - -TESTS += test-select test-select-in.sh test-select-out.sh -# test-select-stdin has to be run by hand. -check_PROGRAMS += test-select test-select-fd test-select-stdin -test_select_LDADD = $(LDADD) @LIB_SELECT@ @LIBSOCKET@ $(INET_PTON_LIB) -test_select_fd_LDADD = $(LDADD) @LIB_SELECT@ -test_select_stdin_LDADD = $(LDADD) @LIB_SELECT@ -EXTRA_DIST += macros.h signature.h test-select.c test-select.h test-select-fd.c test-select-in.sh test-select-out.sh test-select-stdin.c - -## end gnulib module select-tests - -## begin gnulib module send-tests - -TESTS += test-send -check_PROGRAMS += test-send -test_send_LDADD = $(LDADD) @LIBSOCKET@ -EXTRA_DIST += test-send.c signature.h macros.h - -## end gnulib module send-tests - -## begin gnulib module sendto-tests - -TESTS += test-sendto -check_PROGRAMS += test-sendto -test_sendto_LDADD = $(LDADD) @LIBSOCKET@ $(INET_PTON_LIB) -EXTRA_DIST += test-sendto.c signature.h macros.h - -## end gnulib module sendto-tests - -## begin gnulib module setsockopt-tests - -TESTS += test-setsockopt -check_PROGRAMS += test-setsockopt -test_setsockopt_LDADD = $(LDADD) @LIBSOCKET@ -EXTRA_DIST += test-setsockopt.c signature.h macros.h - -## end gnulib module setsockopt-tests - -## begin gnulib module shutdown-tests - -TESTS += test-shutdown -check_PROGRAMS += test-shutdown -test_shutdown_LDADD = $(LDADD) @LIBSOCKET@ -EXTRA_DIST += test-shutdown.c signature.h macros.h - -## end gnulib module shutdown-tests - -## begin gnulib module signal-h-tests - -TESTS += test-signal-h -check_PROGRAMS += test-signal-h -EXTRA_DIST += test-signal-h.c - -## end gnulib module signal-h-tests - ## begin gnulib module snippet/_Noreturn # Because this Makefile snippet defines a variable used by other @@ -859,6 +590,14 @@ EXTRA_DIST += test-snprintf.c signature.h macros.h ## end gnulib module snprintf-tests +## begin gnulib module sockets + +libtests_a_SOURCES += sockets.h sockets.c + +EXTRA_DIST += w32sock.h + +## end gnulib module sockets + ## begin gnulib module sockets-tests TESTS += test-sockets @@ -868,24 +607,6 @@ EXTRA_DIST += test-sockets.c ## end gnulib module sockets-tests -## begin gnulib module stat - - -EXTRA_DIST += stat.c - -EXTRA_libtests_a_SOURCES += stat.c - -## end gnulib module stat - -## begin gnulib module stat-tests - -TESTS += test-stat -check_PROGRAMS += test-stat -test_stat_LDADD = $(LDADD) $(LIBINTL) -EXTRA_DIST += test-stat.h test-stat.c signature.h macros.h - -## end gnulib module stat-tests - ## begin gnulib module stdalign-tests TESTS += test-stdalign @@ -934,31 +655,6 @@ EXTRA_DIST += test-stdlib.c test-sys_wait.h ## end gnulib module stdlib-tests -## begin gnulib module strerror-tests - -TESTS += test-strerror -check_PROGRAMS += test-strerror -EXTRA_DIST += test-strerror.c signature.h macros.h - -## end gnulib module strerror-tests - -## begin gnulib module strerror_r-posix - - -EXTRA_DIST += strerror_r.c - -EXTRA_libtests_a_SOURCES += strerror_r.c - -## end gnulib module strerror_r-posix - -## begin gnulib module strerror_r-posix-tests - -TESTS += test-strerror_r -check_PROGRAMS += test-strerror_r -EXTRA_DIST += test-strerror_r.c signature.h macros.h - -## end gnulib module strerror_r-posix-tests - ## begin gnulib module string-tests TESTS += test-string @@ -991,71 +687,6 @@ EXTRA_DIST += test-strverscmp.c signature.h macros.h ## end gnulib module strverscmp-tests -## begin gnulib module symlink - - -EXTRA_DIST += symlink.c - -EXTRA_libtests_a_SOURCES += symlink.c - -## end gnulib module symlink - -## begin gnulib module symlink-tests - -TESTS += test-symlink -check_PROGRAMS += test-symlink -EXTRA_DIST += test-symlink.h test-symlink.c signature.h macros.h - -## end gnulib module symlink-tests - -## begin gnulib module sys_ioctl - -BUILT_SOURCES += sys/ioctl.h - -# We need the following in order to create <sys/ioctl.h> when the system -# does not have a complete one. -sys/ioctl.h: sys_ioctl.in.h $(top_builddir)/config.status $(CXXDEFS_H) $(WARN_ON_USE_H) - $(AM_V_at)$(MKDIR_P) sys - $(AM_V_GEN)rm -f $@-t $@ && \ - { echo '/* DO NOT EDIT! GENERATED AUTOMATICALLY! */'; \ - sed -e 's|@''GUARD_PREFIX''@|GL|g' \ - -e 's|@''HAVE_SYS_IOCTL_H''@|$(HAVE_SYS_IOCTL_H)|g' \ - -e 's|@''INCLUDE_NEXT''@|$(INCLUDE_NEXT)|g' \ - -e 's|@''PRAGMA_SYSTEM_HEADER''@|@PRAGMA_SYSTEM_HEADER@|g' \ - -e 's|@''PRAGMA_COLUMNS''@|@PRAGMA_COLUMNS@|g' \ - -e 's|@''NEXT_SYS_IOCTL_H''@|$(NEXT_SYS_IOCTL_H)|g' \ - -e 's/@''GNULIB_IOCTL''@/$(GNULIB_IOCTL)/g' \ - -e 's|@''SYS_IOCTL_H_HAVE_WINSOCK2_H''@|$(SYS_IOCTL_H_HAVE_WINSOCK2_H)|g' \ - -e 's|@''SYS_IOCTL_H_HAVE_WINSOCK2_H_AND_USE_SOCKETS''@|$(SYS_IOCTL_H_HAVE_WINSOCK2_H_AND_USE_SOCKETS)|g' \ - -e 's|@''REPLACE_IOCTL''@|$(REPLACE_IOCTL)|g' \ - -e '/definitions of _GL_FUNCDECL_RPL/r $(CXXDEFS_H)' \ - -e '/definition of _GL_WARN_ON_USE/r $(WARN_ON_USE_H)' \ - < $(srcdir)/sys_ioctl.in.h; \ - } > $@-t && \ - mv $@-t $@ -MOSTLYCLEANFILES += sys/ioctl.h sys/ioctl.h-t -MOSTLYCLEANDIRS += sys - -EXTRA_DIST += sys_ioctl.in.h - -## end gnulib module sys_ioctl - -## begin gnulib module sys_ioctl-tests - -TESTS += test-sys_ioctl -check_PROGRAMS += test-sys_ioctl -EXTRA_DIST += test-sys_ioctl.c - -## end gnulib module sys_ioctl-tests - -## begin gnulib module sys_select-tests - -TESTS += test-sys_select -check_PROGRAMS += test-sys_select -EXTRA_DIST += test-sys_select.c signature.h - -## end gnulib module sys_select-tests - ## begin gnulib module sys_socket-tests TESTS += test-sys_socket @@ -1104,14 +735,6 @@ EXTRA_DIST += test-init.sh ## end gnulib module test-framework-sh-tests -## begin gnulib module threadlib - -libtests_a_SOURCES += glthread/threadlib.c - -EXTRA_DIST += $(top_srcdir)/build-aux/config.rpath - -## end gnulib module threadlib - ## begin gnulib module time-tests TESTS += test-time diff --git a/gl/tests/dosname.h b/gl/tests/dosname.h deleted file mode 100644 index b92adfac2e..0000000000 --- a/gl/tests/dosname.h +++ /dev/null @@ -1,53 +0,0 @@ -/* File names on MS-DOS/Windows systems. - - Copyright (C) 2000-2001, 2004-2006, 2009-2014 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 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/>. - - From Paul Eggert and Jim Meyering. */ - -#ifndef _DOSNAME_H -#define _DOSNAME_H - -#if (defined _WIN32 || defined __WIN32__ || \ - defined __MSDOS__ || defined __CYGWIN__ || \ - defined __EMX__ || defined __DJGPP__) - /* This internal macro assumes ASCII, but all hosts that support drive - letters use ASCII. */ -# define _IS_DRIVE_LETTER(C) (((unsigned int) (C) | ('a' - 'A')) - 'a' \ - <= 'z' - 'a') -# define FILE_SYSTEM_PREFIX_LEN(Filename) \ - (_IS_DRIVE_LETTER ((Filename)[0]) && (Filename)[1] == ':' ? 2 : 0) -# ifndef __CYGWIN__ -# define FILE_SYSTEM_DRIVE_PREFIX_CAN_BE_RELATIVE 1 -# endif -# define ISSLASH(C) ((C) == '/' || (C) == '\\') -#else -# define FILE_SYSTEM_PREFIX_LEN(Filename) 0 -# define ISSLASH(C) ((C) == '/') -#endif - -#ifndef FILE_SYSTEM_DRIVE_PREFIX_CAN_BE_RELATIVE -# define FILE_SYSTEM_DRIVE_PREFIX_CAN_BE_RELATIVE 0 -#endif - -#if FILE_SYSTEM_DRIVE_PREFIX_CAN_BE_RELATIVE -# define IS_ABSOLUTE_FILE_NAME(F) ISSLASH ((F)[FILE_SYSTEM_PREFIX_LEN (F)]) -# else -# define IS_ABSOLUTE_FILE_NAME(F) \ - (ISSLASH ((F)[0]) || FILE_SYSTEM_PREFIX_LEN (F) != 0) -#endif -#define IS_RELATIVE_FILE_NAME(F) (! IS_ABSOLUTE_FILE_NAME (F)) - -#endif /* DOSNAME_H_ */ diff --git a/gl/tests/ftruncate.c b/gl/tests/ftruncate.c deleted file mode 100644 index d7a5f203a0..0000000000 --- a/gl/tests/ftruncate.c +++ /dev/null @@ -1,188 +0,0 @@ -/* ftruncate emulations for native Windows. - Copyright (C) 1992-2014 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, 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 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 <unistd.h> - -#if HAVE_CHSIZE -/* A native Windows platform. */ - -# include <errno.h> - -# if _GL_WINDOWS_64_BIT_OFF_T - -/* Large File Support: off_t is 64-bit, but chsize() takes only a 32-bit - argument. So, define a 64-bit safe SetFileSize function ourselves. */ - -/* Ensure that <windows.h> declares GetFileSizeEx. */ -# undef _WIN32_WINNT -# define _WIN32_WINNT 0x500 - -/* Get declarations of the native Windows API functions. */ -# define WIN32_LEAN_AND_MEAN -# include <windows.h> - -/* Get _get_osfhandle. */ -# include "msvc-nothrow.h" - -static BOOL -SetFileSize (HANDLE h, LONGLONG size) -{ - LARGE_INTEGER old_size; - - if (!GetFileSizeEx (h, &old_size)) - return FALSE; - - if (size != old_size.QuadPart) - { - /* Duplicate the handle, so we are free to modify its file position. */ - HANDLE curr_process = GetCurrentProcess (); - HANDLE tmph; - - if (!DuplicateHandle (curr_process, /* SourceProcessHandle */ - h, /* SourceHandle */ - curr_process, /* TargetProcessHandle */ - (PHANDLE) &tmph, /* TargetHandle */ - (DWORD) 0, /* DesiredAccess */ - FALSE, /* InheritHandle */ - DUPLICATE_SAME_ACCESS)) /* Options */ - return FALSE; - - if (size < old_size.QuadPart) - { - /* Reduce the size. */ - LONG size_hi = (LONG) (size >> 32); - if (SetFilePointer (tmph, (LONG) size, &size_hi, FILE_BEGIN) - == INVALID_SET_FILE_POINTER - && GetLastError() != NO_ERROR) - { - CloseHandle (tmph); - return FALSE; - } - if (!SetEndOfFile (tmph)) - { - CloseHandle (tmph); - return FALSE; - } - } - else - { - /* Increase the size by adding zero bytes at the end. */ - static char zero_bytes[1024]; - LONG pos_hi = 0; - LONG pos_lo = SetFilePointer (tmph, (LONG) 0, &pos_hi, FILE_END); - LONGLONG pos; - if (pos_lo == INVALID_SET_FILE_POINTER - && GetLastError() != NO_ERROR) - { - CloseHandle (tmph); - return FALSE; - } - pos = ((LONGLONG) pos_hi << 32) | (ULONGLONG) (ULONG) pos_lo; - while (pos < size) - { - DWORD written; - LONGLONG count = size - pos; - if (count > sizeof (zero_bytes)) - count = sizeof (zero_bytes); - if (!WriteFile (tmph, zero_bytes, (DWORD) count, &written, NULL) - || written == 0) - { - CloseHandle (tmph); - return FALSE; - } - pos += (ULONGLONG) (ULONG) written; - } - } - /* Close the handle. */ - CloseHandle (tmph); - } - return TRUE; -} - -int -ftruncate (int fd, off_t length) -{ - HANDLE handle = (HANDLE) _get_osfhandle (fd); - - if (handle == INVALID_HANDLE_VALUE) - { - errno = EBADF; - return -1; - } - if (length < 0) - { - errno = EINVAL; - return -1; - } - if (!SetFileSize (handle, length)) - { - switch (GetLastError ()) - { - case ERROR_ACCESS_DENIED: - errno = EACCES; - break; - case ERROR_HANDLE_DISK_FULL: - case ERROR_DISK_FULL: - case ERROR_DISK_TOO_FRAGMENTED: - errno = ENOSPC; - break; - default: - errno = EIO; - break; - } - return -1; - } - return 0; -} - -# else - -# include <io.h> - -# if HAVE_MSVC_INVALID_PARAMETER_HANDLER -# include "msvc-inval.h" -static int -chsize_nothrow (int fd, long length) -{ - int result; - - TRY_MSVC_INVAL - { - result = chsize (fd, length); - } - CATCH_MSVC_INVAL - { - result = -1; - errno = EBADF; - } - DONE_MSVC_INVAL; - - return result; -} -# define chsize chsize_nothrow -# endif - -int -ftruncate (int fd, off_t length) -{ - return chsize (fd, length); -} - -# endif -#endif diff --git a/gl/tests/getcwd-lgpl.c b/gl/tests/getcwd-lgpl.c deleted file mode 100644 index 044c000017..0000000000 --- a/gl/tests/getcwd-lgpl.c +++ /dev/null @@ -1,126 +0,0 @@ -/* Copyright (C) 2011-2014 Free Software Foundation, Inc. - This file is part of gnulib. - - 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 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 <unistd.h> - -#include <errno.h> -#include <stdlib.h> -#include <string.h> - -#if GNULIB_GETCWD -/* Favor GPL getcwd.c if both getcwd and getcwd-lgpl modules are in use. */ -typedef int dummy; -#else - -/* Get the name of the current working directory, and put it in SIZE - bytes of BUF. Returns NULL if the directory couldn't be determined - (perhaps because the absolute name was longer than PATH_MAX, or - because of missing read/search permissions on parent directories) - or SIZE was too small. If successful, returns BUF. If BUF is - NULL, an array is allocated with 'malloc'; the array is SIZE bytes - long, unless SIZE == 0, in which case it is as big as - necessary. */ - -# undef getcwd -char * -rpl_getcwd (char *buf, size_t size) -{ - char *ptr; - char *result; - - /* Handle single size operations. */ - if (buf) - { - if (!size) - { - errno = EINVAL; - return NULL; - } - return getcwd (buf, size); - } - - if (size) - { - buf = malloc (size); - if (!buf) - { - errno = ENOMEM; - return NULL; - } - result = getcwd (buf, size); - if (!result) - { - int saved_errno = errno; - free (buf); - errno = saved_errno; - } - return result; - } - - /* Flexible sizing requested. Avoid over-allocation for the common - case of a name that fits within a 4k page, minus some space for - local variables, to be sure we don't skip over a guard page. */ - { - char tmp[4032]; - size = sizeof tmp; - ptr = getcwd (tmp, size); - if (ptr) - { - result = strdup (ptr); - if (!result) - errno = ENOMEM; - return result; - } - if (errno != ERANGE) - return NULL; - } - - /* My what a large directory name we have. */ - do - { - size <<= 1; - ptr = realloc (buf, size); - if (ptr == NULL) - { - free (buf); - errno = ENOMEM; - return NULL; - } - buf = ptr; - result = getcwd (buf, size); - } - while (!result && errno == ERANGE); - - if (!result) - { - int saved_errno = errno; - free (buf); - errno = saved_errno; - } - else - { - /* Trim to fit, if possible. */ - result = realloc (buf, strlen (buf) + 1); - if (!result) - result = buf; - } - return result; -} - -#endif diff --git a/gl/tests/getdtablesize.c b/gl/tests/getdtablesize.c deleted file mode 100644 index 946738cdb6..0000000000 --- a/gl/tests/getdtablesize.c +++ /dev/null @@ -1,107 +0,0 @@ -/* getdtablesize() function for platforms that don't have it. - Copyright (C) 2008-2014 Free Software Foundation, Inc. - Written by Bruno Haible <bruno@clisp.org>, 2008. - - 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 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 <unistd.h> - -#if (defined _WIN32 || defined __WIN32__) && ! defined __CYGWIN__ - -# include <stdio.h> - -# include "msvc-inval.h" - -# if HAVE_MSVC_INVALID_PARAMETER_HANDLER -static int -_setmaxstdio_nothrow (int newmax) -{ - int result; - - TRY_MSVC_INVAL - { - result = _setmaxstdio (newmax); - } - CATCH_MSVC_INVAL - { - result = -1; - } - DONE_MSVC_INVAL; - - return result; -} -# define _setmaxstdio _setmaxstdio_nothrow -# endif - -/* Cache for the previous getdtablesize () result. Safe to cache because - Windows also lacks setrlimit. */ -static int dtablesize; - -int -getdtablesize (void) -{ - if (dtablesize == 0) - { - /* We are looking for the number N such that the valid file descriptors - are 0..N-1. It can be obtained through a loop as follows: - { - int fd; - for (fd = 3; fd < 65536; fd++) - if (dup2 (0, fd) == -1) - break; - return fd; - } - On Windows XP, the result is 2048. - The drawback of this loop is that it allocates memory for a libc - internal array that is never freed. - - The number N can also be obtained as the upper bound for - _getmaxstdio (). _getmaxstdio () returns the maximum number of open - FILE objects. The sanity check in _setmaxstdio reveals the maximum - number of file descriptors. This too allocates memory, but it is - freed when we call _setmaxstdio with the original value. */ - int orig_max_stdio = _getmaxstdio (); - unsigned int bound; - for (bound = 0x10000; _setmaxstdio (bound) < 0; bound = bound / 2) - ; - _setmaxstdio (orig_max_stdio); - dtablesize = bound; - } - return dtablesize; -} - -#elif HAVE_GETDTABLESIZE - -# include <sys/resource.h> -# undef getdtablesize - -int -rpl_getdtablesize(void) -{ - /* To date, this replacement is only compiled for Cygwin 1.7.25, - which auto-increased the RLIMIT_NOFILE soft limit until it - hits the compile-time constant hard limit of 3200. Although - that version of cygwin supported a child process inheriting - a smaller soft limit, the smaller limit is not enforced, so - we might as well just report the hard limit. */ - struct rlimit lim; - if (!getrlimit (RLIMIT_NOFILE, &lim) && lim.rlim_max != RLIM_INFINITY) - return lim.rlim_max; - return getdtablesize (); -} - -#endif diff --git a/gl/tests/glthread/lock.c b/gl/tests/glthread/lock.c deleted file mode 100644 index 33c15a0d7f..0000000000 --- a/gl/tests/glthread/lock.c +++ /dev/null @@ -1,1057 +0,0 @@ -/* Locking in multithreaded situations. - Copyright (C) 2005-2014 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, 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 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/>. */ - -/* Written by Bruno Haible <bruno@clisp.org>, 2005. - Based on GCC's gthr-posix.h, gthr-posix95.h, gthr-solaris.h, - gthr-win32.h. */ - -#include <config.h> - -#include "glthread/lock.h" - -/* ========================================================================= */ - -#if USE_POSIX_THREADS - -/* -------------------------- gl_lock_t datatype -------------------------- */ - -/* ------------------------- gl_rwlock_t datatype ------------------------- */ - -# if HAVE_PTHREAD_RWLOCK - -# if !defined PTHREAD_RWLOCK_INITIALIZER - -int -glthread_rwlock_init_multithreaded (gl_rwlock_t *lock) -{ - int err; - - err = pthread_rwlock_init (&lock->rwlock, NULL); - if (err != 0) - return err; - lock->initialized = 1; - return 0; -} - -int -glthread_rwlock_rdlock_multithreaded (gl_rwlock_t *lock) -{ - if (!lock->initialized) - { - int err; - - err = pthread_mutex_lock (&lock->guard); - if (err != 0) - return err; - if (!lock->initialized) - { - err = glthread_rwlock_init_multithreaded (lock); - if (err != 0) - { - pthread_mutex_unlock (&lock->guard); - return err; - } - } - err = pthread_mutex_unlock (&lock->guard); - if (err != 0) - return err; - } - return pthread_rwlock_rdlock (&lock->rwlock); -} - -int -glthread_rwlock_wrlock_multithreaded (gl_rwlock_t *lock) -{ - if (!lock->initialized) - { - int err; - - err = pthread_mutex_lock (&lock->guard); - if (err != 0) - return err; - if (!lock->initialized) - { - err = glthread_rwlock_init_multithreaded (lock); - if (err != 0) - { - pthread_mutex_unlock (&lock->guard); - return err; - } - } - err = pthread_mutex_unlock (&lock->guard); - if (err != 0) - return err; - } - return pthread_rwlock_wrlock (&lock->rwlock); -} - -int -glthread_rwlock_unlock_multithreaded (gl_rwlock_t *lock) -{ - if (!lock->initialized) - return EINVAL; - return pthread_rwlock_unlock (&lock->rwlock); -} - -int -glthread_rwlock_destroy_multithreaded (gl_rwlock_t *lock) -{ - int err; - - if (!lock->initialized) - return EINVAL; - err = pthread_rwlock_destroy (&lock->rwlock); - if (err != 0) - return err; - lock->initialized = 0; - return 0; -} - -# endif - -# else - -int -glthread_rwlock_init_multithreaded (gl_rwlock_t *lock) -{ - int err; - - err = pthread_mutex_init (&lock->lock, NULL); - if (err != 0) - return err; - err = pthread_cond_init (&lock->waiting_readers, NULL); - if (err != 0) - return err; - err = pthread_cond_init (&lock->waiting_writers, NULL); - if (err != 0) - return err; - lock->waiting_writers_count = 0; - lock->runcount = 0; - return 0; -} - -int -glthread_rwlock_rdlock_multithreaded (gl_rwlock_t *lock) -{ - int err; - - err = pthread_mutex_lock (&lock->lock); - if (err != 0) - return err; - /* Test whether only readers are currently running, and whether the runcount - field will not overflow. */ - /* POSIX says: "It is implementation-defined whether the calling thread - acquires the lock when a writer does not hold the lock and there are - writers blocked on the lock." Let's say, no: give the writers a higher - priority. */ - while (!(lock->runcount + 1 > 0 && lock->waiting_writers_count == 0)) - { - /* This thread has to wait for a while. Enqueue it among the - waiting_readers. */ - err = pthread_cond_wait (&lock->waiting_readers, &lock->lock); - if (err != 0) - { - pthread_mutex_unlock (&lock->lock); - return err; - } - } - lock->runcount++; - return pthread_mutex_unlock (&lock->lock); -} - -int -glthread_rwlock_wrlock_multithreaded (gl_rwlock_t *lock) -{ - int err; - - err = pthread_mutex_lock (&lock->lock); - if (err != 0) - return err; - /* Test whether no readers or writers are currently running. */ - while (!(lock->runcount == 0)) - { - /* This thread has to wait for a while. Enqueue it among the - waiting_writers. */ - lock->waiting_writers_count++; - err = pthread_cond_wait (&lock->waiting_writers, &lock->lock); - if (err != 0) - { - lock->waiting_writers_count--; - pthread_mutex_unlock (&lock->lock); - return err; - } - lock->waiting_writers_count--; - } - lock->runcount--; /* runcount becomes -1 */ - return pthread_mutex_unlock (&lock->lock); -} - -int -glthread_rwlock_unlock_multithreaded (gl_rwlock_t *lock) -{ - int err; - - err = pthread_mutex_lock (&lock->lock); - if (err != 0) - return err; - if (lock->runcount < 0) - { - /* Drop a writer lock. */ - if (!(lock->runcount == -1)) - { - pthread_mutex_unlock (&lock->lock); - return EINVAL; - } - lock->runcount = 0; - } - else - { - /* Drop a reader lock. */ - if (!(lock->runcount > 0)) - { - pthread_mutex_unlock (&lock->lock); - return EINVAL; - } - lock->runcount--; - } - if (lock->runcount == 0) - { - /* POSIX recommends that "write locks shall take precedence over read - locks", to avoid "writer starvation". */ - if (lock->waiting_writers_count > 0) - { - /* Wake up one of the waiting writers. */ - err = pthread_cond_signal (&lock->waiting_writers); - if (err != 0) - { - pthread_mutex_unlock (&lock->lock); - return err; - } - } - else - { - /* Wake up all waiting readers. */ - err = pthread_cond_broadcast (&lock->waiting_readers); - if (err != 0) - { - pthread_mutex_unlock (&lock->lock); - return err; - } - } - } - return pthread_mutex_unlock (&lock->lock); -} - -int -glthread_rwlock_destroy_multithreaded (gl_rwlock_t *lock) -{ - int err; - - err = pthread_mutex_destroy (&lock->lock); - if (err != 0) - return err; - err = pthread_cond_destroy (&lock->waiting_readers); - if (err != 0) - return err; - err = pthread_cond_destroy (&lock->waiting_writers); - if (err != 0) - return err; - return 0; -} - -# endif - -/* --------------------- gl_recursive_lock_t datatype --------------------- */ - -# if HAVE_PTHREAD_MUTEX_RECURSIVE - -# if defined PTHREAD_RECURSIVE_MUTEX_INITIALIZER || defined PTHREAD_RECURSIVE_MUTEX_INITIALIZER_NP - -int -glthread_recursive_lock_init_multithreaded (gl_recursive_lock_t *lock) -{ - pthread_mutexattr_t attributes; - int err; - - err = pthread_mutexattr_init (&attributes); - if (err != 0) - return err; - err = pthread_mutexattr_settype (&attributes, PTHREAD_MUTEX_RECURSIVE); - if (err != 0) - { - pthread_mutexattr_destroy (&attributes); - return err; - } - err = pthread_mutex_init (lock, &attributes); - if (err != 0) - { - pthread_mutexattr_destroy (&attributes); - return err; - } - err = pthread_mutexattr_destroy (&attributes); - if (err != 0) - return err; - return 0; -} - -# else - -int -glthread_recursive_lock_init_multithreaded (gl_recursive_lock_t *lock) -{ - pthread_mutexattr_t attributes; - int err; - - err = pthread_mutexattr_init (&attributes); - if (err != 0) - return err; - err = pthread_mutexattr_settype (&attributes, PTHREAD_MUTEX_RECURSIVE); - if (err != 0) - { - pthread_mutexattr_destroy (&attributes); - return err; - } - err = pthread_mutex_init (&lock->recmutex, &attributes); - if (err != 0) - { - pthread_mutexattr_destroy (&attributes); - return err; - } - err = pthread_mutexattr_destroy (&attributes); - if (err != 0) - return err; - lock->initialized = 1; - return 0; -} - -int -glthread_recursive_lock_lock_multithreaded (gl_recursive_lock_t *lock) -{ - if (!lock->initialized) - { - int err; - - err = pthread_mutex_lock (&lock->guard); - if (err != 0) - return err; - if (!lock->initialized) - { - err = glthread_recursive_lock_init_multithreaded (lock); - if (err != 0) - { - pthread_mutex_unlock (&lock->guard); - return err; - } - } - err = pthread_mutex_unlock (&lock->guard); - if (err != 0) - return err; - } - return pthread_mutex_lock (&lock->recmutex); -} - -int -glthread_recursive_lock_unlock_multithreaded (gl_recursive_lock_t *lock) -{ - if (!lock->initialized) - return EINVAL; - return pthread_mutex_unlock (&lock->recmutex); -} - -int -glthread_recursive_lock_destroy_multithreaded (gl_recursive_lock_t *lock) -{ - int err; - - if (!lock->initialized) - return EINVAL; - err = pthread_mutex_destroy (&lock->recmutex); - if (err != 0) - return err; - lock->initialized = 0; - return 0; -} - -# endif - -# else - -int -glthread_recursive_lock_init_multithreaded (gl_recursive_lock_t *lock) -{ - int err; - - err = pthread_mutex_init (&lock->mutex, NULL); - if (err != 0) - return err; - lock->owner = (pthread_t) 0; - lock->depth = 0; - return 0; -} - -int -glthread_recursive_lock_lock_multithreaded (gl_recursive_lock_t *lock) -{ - pthread_t self = pthread_self (); - if (lock->owner != self) - { - int err; - - err = pthread_mutex_lock (&lock->mutex); - if (err != 0) - return err; - lock->owner = self; - } - if (++(lock->depth) == 0) /* wraparound? */ - { - lock->depth--; - return EAGAIN; - } - return 0; -} - -int -glthread_recursive_lock_unlock_multithreaded (gl_recursive_lock_t *lock) -{ - if (lock->owner != pthread_self ()) - return EPERM; - if (lock->depth == 0) - return EINVAL; - if (--(lock->depth) == 0) - { - lock->owner = (pthread_t) 0; - return pthread_mutex_unlock (&lock->mutex); - } - else - return 0; -} - -int -glthread_recursive_lock_destroy_multithreaded (gl_recursive_lock_t *lock) -{ - if (lock->owner != (pthread_t) 0) - return EBUSY; - return pthread_mutex_destroy (&lock->mutex); -} - -# endif - -/* -------------------------- gl_once_t datatype -------------------------- */ - -static const pthread_once_t fresh_once = PTHREAD_ONCE_INIT; - -int -glthread_once_singlethreaded (pthread_once_t *once_control) -{ - /* We don't know whether pthread_once_t is an integer type, a floating-point - type, a pointer type, or a structure type. */ - char *firstbyte = (char *)once_control; - if (*firstbyte == *(const char *)&fresh_once) - { - /* First time use of once_control. Invert the first byte. */ - *firstbyte = ~ *(const char *)&fresh_once; - return 1; - } - else - return 0; -} - -#endif - -/* ========================================================================= */ - -#if USE_PTH_THREADS - -/* Use the GNU Pth threads library. */ - -/* -------------------------- gl_lock_t datatype -------------------------- */ - -/* ------------------------- gl_rwlock_t datatype ------------------------- */ - -/* --------------------- gl_recursive_lock_t datatype --------------------- */ - -/* -------------------------- gl_once_t datatype -------------------------- */ - -static void -glthread_once_call (void *arg) -{ - void (**gl_once_temp_addr) (void) = (void (**) (void)) arg; - void (*initfunction) (void) = *gl_once_temp_addr; - initfunction (); -} - -int -glthread_once_multithreaded (pth_once_t *once_control, void (*initfunction) (void)) -{ - void (*temp) (void) = initfunction; - return (!pth_once (once_control, glthread_once_call, &temp) ? errno : 0); -} - -int -glthread_once_singlethreaded (pth_once_t *once_control) -{ - /* We know that pth_once_t is an integer type. */ - if (*once_control == PTH_ONCE_INIT) - { - /* First time use of once_control. Invert the marker. */ - *once_control = ~ PTH_ONCE_INIT; - return 1; - } - else - return 0; -} - -#endif - -/* ========================================================================= */ - -#if USE_SOLARIS_THREADS - -/* Use the old Solaris threads library. */ - -/* -------------------------- gl_lock_t datatype -------------------------- */ - -/* ------------------------- gl_rwlock_t datatype ------------------------- */ - -/* --------------------- gl_recursive_lock_t datatype --------------------- */ - -int -glthread_recursive_lock_init_multithreaded (gl_recursive_lock_t *lock) -{ - int err; - - err = mutex_init (&lock->mutex, USYNC_THREAD, NULL); - if (err != 0) - return err; - lock->owner = (thread_t) 0; - lock->depth = 0; - return 0; -} - -int -glthread_recursive_lock_lock_multithreaded (gl_recursive_lock_t *lock) -{ - thread_t self = thr_self (); - if (lock->owner != self) - { - int err; - - err = mutex_lock (&lock->mutex); - if (err != 0) - return err; - lock->owner = self; - } - if (++(lock->depth) == 0) /* wraparound? */ - { - lock->depth--; - return EAGAIN; - } - return 0; -} - -int -glthread_recursive_lock_unlock_multithreaded (gl_recursive_lock_t *lock) -{ - if (lock->owner != thr_self ()) - return EPERM; - if (lock->depth == 0) - return EINVAL; - if (--(lock->depth) == 0) - { - lock->owner = (thread_t) 0; - return mutex_unlock (&lock->mutex); - } - else - return 0; -} - -int -glthread_recursive_lock_destroy_multithreaded (gl_recursive_lock_t *lock) -{ - if (lock->owner != (thread_t) 0) - return EBUSY; - return mutex_destroy (&lock->mutex); -} - -/* -------------------------- gl_once_t datatype -------------------------- */ - -int -glthread_once_multithreaded (gl_once_t *once_control, void (*initfunction) (void)) -{ - if (!once_control->inited) - { - int err; - - /* Use the mutex to guarantee that if another thread is already calling - the initfunction, this thread waits until it's finished. */ - err = mutex_lock (&once_control->mutex); - if (err != 0) - return err; - if (!once_control->inited) - { - once_control->inited = 1; - initfunction (); - } - return mutex_unlock (&once_control->mutex); - } - else - return 0; -} - -int -glthread_once_singlethreaded (gl_once_t *once_control) -{ - /* We know that gl_once_t contains an integer type. */ - if (!once_control->inited) - { - /* First time use of once_control. Invert the marker. */ - once_control->inited = ~ 0; - return 1; - } - else - return 0; -} - -#endif - -/* ========================================================================= */ - -#if USE_WINDOWS_THREADS - -/* -------------------------- gl_lock_t datatype -------------------------- */ - -void -glthread_lock_init_func (gl_lock_t *lock) -{ - InitializeCriticalSection (&lock->lock); - lock->guard.done = 1; -} - -int -glthread_lock_lock_func (gl_lock_t *lock) -{ - if (!lock->guard.done) - { - if (InterlockedIncrement (&lock->guard.started) == 0) - /* This thread is the first one to need this lock. Initialize it. */ - glthread_lock_init (lock); - else - /* Yield the CPU while waiting for another thread to finish - initializing this lock. */ - while (!lock->guard.done) - Sleep (0); - } - EnterCriticalSection (&lock->lock); - return 0; -} - -int -glthread_lock_unlock_func (gl_lock_t *lock) -{ - if (!lock->guard.done) - return EINVAL; - LeaveCriticalSection (&lock->lock); - return 0; -} - -int -glthread_lock_destroy_func (gl_lock_t *lock) -{ - if (!lock->guard.done) - return EINVAL; - DeleteCriticalSection (&lock->lock); - lock->guard.done = 0; - return 0; -} - -/* ------------------------- gl_rwlock_t datatype ------------------------- */ - -/* In this file, the waitqueues are implemented as circular arrays. */ -#define gl_waitqueue_t gl_carray_waitqueue_t - -static void -gl_waitqueue_init (gl_waitqueue_t *wq) -{ - wq->array = NULL; - wq->count = 0; - wq->alloc = 0; - wq->offset = 0; -} - -/* Enqueues the current thread, represented by an event, in a wait queue. - Returns INVALID_HANDLE_VALUE if an allocation failure occurs. */ -static HANDLE -gl_waitqueue_add (gl_waitqueue_t *wq) -{ - HANDLE event; - unsigned int index; - - if (wq->count == wq->alloc) - { - unsigned int new_alloc = 2 * wq->alloc + 1; - HANDLE *new_array = - (HANDLE *) realloc (wq->array, new_alloc * sizeof (HANDLE)); - if (new_array == NULL) - /* No more memory. */ - return INVALID_HANDLE_VALUE; - /* Now is a good opportunity to rotate the array so that its contents - starts at offset 0. */ - if (wq->offset > 0) - { - unsigned int old_count = wq->count; - unsigned int old_alloc = wq->alloc; - unsigned int old_offset = wq->offset; - unsigned int i; - if (old_offset + old_count > old_alloc) - { - unsigned int limit = old_offset + old_count - old_alloc; - for (i = 0; i < limit; i++) - new_array[old_alloc + i] = new_array[i]; - } - for (i = 0; i < old_count; i++) - new_array[i] = new_array[old_offset + i]; - wq->offset = 0; - } - wq->array = new_array; - wq->alloc = new_alloc; - } - /* Whether the created event is a manual-reset one or an auto-reset one, - does not matter, since we will wait on it only once. */ - event = CreateEvent (NULL, TRUE, FALSE, NULL); - if (event == INVALID_HANDLE_VALUE) - /* No way to allocate an event. */ - return INVALID_HANDLE_VALUE; - index = wq->offset + wq->count; - if (index >= wq->alloc) - index -= wq->alloc; - wq->array[index] = event; - wq->count++; - return event; -} - -/* Notifies the first thread from a wait queue and dequeues it. */ -static void -gl_waitqueue_notify_first (gl_waitqueue_t *wq) -{ - SetEvent (wq->array[wq->offset + 0]); - wq->offset++; - wq->count--; - if (wq->count == 0 || wq->offset == wq->alloc) - wq->offset = 0; -} - -/* Notifies all threads from a wait queue and dequeues them all. */ -static void -gl_waitqueue_notify_all (gl_waitqueue_t *wq) -{ - unsigned int i; - - for (i = 0; i < wq->count; i++) - { - unsigned int index = wq->offset + i; - if (index >= wq->alloc) - index -= wq->alloc; - SetEvent (wq->array[index]); - } - wq->count = 0; - wq->offset = 0; -} - -void -glthread_rwlock_init_func (gl_rwlock_t *lock) -{ - InitializeCriticalSection (&lock->lock); - gl_waitqueue_init (&lock->waiting_readers); - gl_waitqueue_init (&lock->waiting_writers); - lock->runcount = 0; - lock->guard.done = 1; -} - -int -glthread_rwlock_rdlock_func (gl_rwlock_t *lock) -{ - if (!lock->guard.done) - { - if (InterlockedIncrement (&lock->guard.started) == 0) - /* This thread is the first one to need this lock. Initialize it. */ - glthread_rwlock_init (lock); - else - /* Yield the CPU while waiting for another thread to finish - initializing this lock. */ - while (!lock->guard.done) - Sleep (0); - } - EnterCriticalSection (&lock->lock); - /* Test whether only readers are currently running, and whether the runcount - field will not overflow. */ - if (!(lock->runcount + 1 > 0)) - { - /* This thread has to wait for a while. Enqueue it among the - waiting_readers. */ - HANDLE event = gl_waitqueue_add (&lock->waiting_readers); - if (event != INVALID_HANDLE_VALUE) - { - DWORD result; - LeaveCriticalSection (&lock->lock); - /* Wait until another thread signals this event. */ - result = WaitForSingleObject (event, INFINITE); - if (result == WAIT_FAILED || result == WAIT_TIMEOUT) - abort (); - CloseHandle (event); - /* The thread which signalled the event already did the bookkeeping: - removed us from the waiting_readers, incremented lock->runcount. */ - if (!(lock->runcount > 0)) - abort (); - return 0; - } - else - { - /* Allocation failure. Weird. */ - do - { - LeaveCriticalSection (&lock->lock); - Sleep (1); - EnterCriticalSection (&lock->lock); - } - while (!(lock->runcount + 1 > 0)); - } - } - lock->runcount++; - LeaveCriticalSection (&lock->lock); - return 0; -} - -int -glthread_rwlock_wrlock_func (gl_rwlock_t *lock) -{ - if (!lock->guard.done) - { - if (InterlockedIncrement (&lock->guard.started) == 0) - /* This thread is the first one to need this lock. Initialize it. */ - glthread_rwlock_init (lock); - else - /* Yield the CPU while waiting for another thread to finish - initializing this lock. */ - while (!lock->guard.done) - Sleep (0); - } - EnterCriticalSection (&lock->lock); - /* Test whether no readers or writers are currently running. */ - if (!(lock->runcount == 0)) - { - /* This thread has to wait for a while. Enqueue it among the - waiting_writers. */ - HANDLE event = gl_waitqueue_add (&lock->waiting_writers); - if (event != INVALID_HANDLE_VALUE) - { - DWORD result; - LeaveCriticalSection (&lock->lock); - /* Wait until another thread signals this event. */ - result = WaitForSingleObject (event, INFINITE); - if (result == WAIT_FAILED || result == WAIT_TIMEOUT) - abort (); - CloseHandle (event); - /* The thread which signalled the event already did the bookkeeping: - removed us from the waiting_writers, set lock->runcount = -1. */ - if (!(lock->runcount == -1)) - abort (); - return 0; - } - else - { - /* Allocation failure. Weird. */ - do - { - LeaveCriticalSection (&lock->lock); - Sleep (1); - EnterCriticalSection (&lock->lock); - } - while (!(lock->runcount == 0)); - } - } - lock->runcount--; /* runcount becomes -1 */ - LeaveCriticalSection (&lock->lock); - return 0; -} - -int -glthread_rwlock_unlock_func (gl_rwlock_t *lock) -{ - if (!lock->guard.done) - return EINVAL; - EnterCriticalSection (&lock->lock); - if (lock->runcount < 0) - { - /* Drop a writer lock. */ - if (!(lock->runcount == -1)) - abort (); - lock->runcount = 0; - } - else - { - /* Drop a reader lock. */ - if (!(lock->runcount > 0)) - { - LeaveCriticalSection (&lock->lock); - return EPERM; - } - lock->runcount--; - } - if (lock->runcount == 0) - { - /* POSIX recommends that "write locks shall take precedence over read - locks", to avoid "writer starvation". */ - if (lock->waiting_writers.count > 0) - { - /* Wake up one of the waiting writers. */ - lock->runcount--; - gl_waitqueue_notify_first (&lock->waiting_writers); - } - else - { - /* Wake up all waiting readers. */ - lock->runcount += lock->waiting_readers.count; - gl_waitqueue_notify_all (&lock->waiting_readers); - } - } - LeaveCriticalSection (&lock->lock); - return 0; -} - -int -glthread_rwlock_destroy_func (gl_rwlock_t *lock) -{ - if (!lock->guard.done) - return EINVAL; - if (lock->runcount != 0) - return EBUSY; - DeleteCriticalSection (&lock->lock); - if (lock->waiting_readers.array != NULL) - free (lock->waiting_readers.array); - if (lock->waiting_writers.array != NULL) - free (lock->waiting_writers.array); - lock->guard.done = 0; - return 0; -} - -/* --------------------- gl_recursive_lock_t datatype --------------------- */ - -void -glthread_recursive_lock_init_func (gl_recursive_lock_t *lock) -{ - lock->owner = 0; - lock->depth = 0; - InitializeCriticalSection (&lock->lock); - lock->guard.done = 1; -} - -int -glthread_recursive_lock_lock_func (gl_recursive_lock_t *lock) -{ - if (!lock->guard.done) - { - if (InterlockedIncrement (&lock->guard.started) == 0) - /* This thread is the first one to need this lock. Initialize it. */ - glthread_recursive_lock_init (lock); - else - /* Yield the CPU while waiting for another thread to finish - initializing this lock. */ - while (!lock->guard.done) - Sleep (0); - } - { - DWORD self = GetCurrentThreadId (); - if (lock->owner != self) - { - EnterCriticalSection (&lock->lock); - lock->owner = self; - } - if (++(lock->depth) == 0) /* wraparound? */ - { - lock->depth--; - return EAGAIN; - } - } - return 0; -} - -int -glthread_recursive_lock_unlock_func (gl_recursive_lock_t *lock) -{ - if (lock->owner != GetCurrentThreadId ()) - return EPERM; - if (lock->depth == 0) - return EINVAL; - if (--(lock->depth) == 0) - { - lock->owner = 0; - LeaveCriticalSection (&lock->lock); - } - return 0; -} - -int -glthread_recursive_lock_destroy_func (gl_recursive_lock_t *lock) -{ - if (lock->owner != 0) - return EBUSY; - DeleteCriticalSection (&lock->lock); - lock->guard.done = 0; - return 0; -} - -/* -------------------------- gl_once_t datatype -------------------------- */ - -void -glthread_once_func (gl_once_t *once_control, void (*initfunction) (void)) -{ - if (once_control->inited <= 0) - { - if (InterlockedIncrement (&once_control->started) == 0) - { - /* This thread is the first one to come to this once_control. */ - InitializeCriticalSection (&once_control->lock); - EnterCriticalSection (&once_control->lock); - once_control->inited = 0; - initfunction (); - once_control->inited = 1; - LeaveCriticalSection (&once_control->lock); - } - else - { - /* Undo last operation. */ - InterlockedDecrement (&once_control->started); - /* Some other thread has already started the initialization. - Yield the CPU while waiting for the other thread to finish - initializing and taking the lock. */ - while (once_control->inited < 0) - Sleep (0); - if (once_control->inited <= 0) - { - /* Take the lock. This blocks until the other thread has - finished calling the initfunction. */ - EnterCriticalSection (&once_control->lock); - LeaveCriticalSection (&once_control->lock); - if (!(once_control->inited > 0)) - abort (); - } - } - } -} - -#endif - -/* ========================================================================= */ diff --git a/gl/tests/glthread/lock.h b/gl/tests/glthread/lock.h deleted file mode 100644 index 36096c4b6a..0000000000 --- a/gl/tests/glthread/lock.h +++ /dev/null @@ -1,927 +0,0 @@ -/* Locking in multithreaded situations. - Copyright (C) 2005-2014 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, 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 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/>. */ - -/* Written by Bruno Haible <bruno@clisp.org>, 2005. - Based on GCC's gthr-posix.h, gthr-posix95.h, gthr-solaris.h, - gthr-win32.h. */ - -/* This file contains locking primitives for use with a given thread library. - It does not contain primitives for creating threads or for other - synchronization primitives. - - Normal (non-recursive) locks: - Type: gl_lock_t - Declaration: gl_lock_define(extern, name) - Initializer: gl_lock_define_initialized(, name) - Initialization: gl_lock_init (name); - Taking the lock: gl_lock_lock (name); - Releasing the lock: gl_lock_unlock (name); - De-initialization: gl_lock_destroy (name); - Equivalent functions with control of error handling: - Initialization: err = glthread_lock_init (&name); - Taking the lock: err = glthread_lock_lock (&name); - Releasing the lock: err = glthread_lock_unlock (&name); - De-initialization: err = glthread_lock_destroy (&name); - - Read-Write (non-recursive) locks: - Type: gl_rwlock_t - Declaration: gl_rwlock_define(extern, name) - Initializer: gl_rwlock_define_initialized(, name) - Initialization: gl_rwlock_init (name); - Taking the lock: gl_rwlock_rdlock (name); - gl_rwlock_wrlock (name); - Releasing the lock: gl_rwlock_unlock (name); - De-initialization: gl_rwlock_destroy (name); - Equivalent functions with control of error handling: - Initialization: err = glthread_rwlock_init (&name); - Taking the lock: err = glthread_rwlock_rdlock (&name); - err = glthread_rwlock_wrlock (&name); - Releasing the lock: err = glthread_rwlock_unlock (&name); - De-initialization: err = glthread_rwlock_destroy (&name); - - Recursive locks: - Type: gl_recursive_lock_t - Declaration: gl_recursive_lock_define(extern, name) - Initializer: gl_recursive_lock_define_initialized(, name) - Initialization: gl_recursive_lock_init (name); - Taking the lock: gl_recursive_lock_lock (name); - Releasing the lock: gl_recursive_lock_unlock (name); - De-initialization: gl_recursive_lock_destroy (name); - Equivalent functions with control of error handling: - Initialization: err = glthread_recursive_lock_init (&name); - Taking the lock: err = glthread_recursive_lock_lock (&name); - Releasing the lock: err = glthread_recursive_lock_unlock (&name); - De-initialization: err = glthread_recursive_lock_destroy (&name); - - Once-only execution: - Type: gl_once_t - Initializer: gl_once_define(extern, name) - Execution: gl_once (name, initfunction); - Equivalent functions with control of error handling: - Execution: err = glthread_once (&name, initfunction); -*/ - - -#ifndef _LOCK_H -#define _LOCK_H - -#include <errno.h> -#include <stdlib.h> - -/* ========================================================================= */ - -#if USE_POSIX_THREADS - -/* Use the POSIX threads library. */ - -# include <pthread.h> - -# ifdef __cplusplus -extern "C" { -# endif - -# if PTHREAD_IN_USE_DETECTION_HARD - -/* The pthread_in_use() detection needs to be done at runtime. */ -# define pthread_in_use() \ - glthread_in_use () -extern int glthread_in_use (void); - -# endif - -# if USE_POSIX_THREADS_WEAK - -/* Use weak references to the POSIX threads library. */ - -/* Weak references avoid dragging in external libraries if the other parts - of the program don't use them. Here we use them, because we don't want - every program that uses libintl to depend on libpthread. This assumes - that libpthread would not be loaded after libintl; i.e. if libintl is - loaded first, by an executable that does not depend on libpthread, and - then a module is dynamically loaded that depends on libpthread, libintl - will not be multithread-safe. */ - -/* The way to test at runtime whether libpthread is present is to test - whether a function pointer's value, such as &pthread_mutex_init, is - non-NULL. However, some versions of GCC have a bug through which, in - PIC mode, &foo != NULL always evaluates to true if there is a direct - call to foo(...) in the same function. To avoid this, we test the - address of a function in libpthread that we don't use. */ - -# pragma weak pthread_mutex_init -# pragma weak pthread_mutex_lock -# pragma weak pthread_mutex_unlock -# pragma weak pthread_mutex_destroy -# pragma weak pthread_rwlock_init -# pragma weak pthread_rwlock_rdlock -# pragma weak pthread_rwlock_wrlock -# pragma weak pthread_rwlock_unlock -# pragma weak pthread_rwlock_destroy -# pragma weak pthread_once -# pragma weak pthread_cond_init -# pragma weak pthread_cond_wait -# pragma weak pthread_cond_signal -# pragma weak pthread_cond_broadcast -# pragma weak pthread_cond_destroy -# pragma weak pthread_mutexattr_init -# pragma weak pthread_mutexattr_settype -# pragma weak pthread_mutexattr_destroy -# ifndef pthread_self -# pragma weak pthread_self -# endif - -# if !PTHREAD_IN_USE_DETECTION_HARD -# pragma weak pthread_cancel -# define pthread_in_use() (pthread_cancel != NULL) -# endif - -# else - -# if !PTHREAD_IN_USE_DETECTION_HARD -# define pthread_in_use() 1 -# endif - -# endif - -/* -------------------------- gl_lock_t datatype -------------------------- */ - -typedef pthread_mutex_t gl_lock_t; -# define gl_lock_define(STORAGECLASS, NAME) \ - STORAGECLASS pthread_mutex_t NAME; -# define gl_lock_define_initialized(STORAGECLASS, NAME) \ - STORAGECLASS pthread_mutex_t NAME = gl_lock_initializer; -# define gl_lock_initializer \ - PTHREAD_MUTEX_INITIALIZER -# define glthread_lock_init(LOCK) \ - (pthread_in_use () ? pthread_mutex_init (LOCK, NULL) : 0) -# define glthread_lock_lock(LOCK) \ - (pthread_in_use () ? pthread_mutex_lock (LOCK) : 0) -# define glthread_lock_unlock(LOCK) \ - (pthread_in_use () ? pthread_mutex_unlock (LOCK) : 0) -# define glthread_lock_destroy(LOCK) \ - (pthread_in_use () ? pthread_mutex_destroy (LOCK) : 0) - -/* ------------------------- gl_rwlock_t datatype ------------------------- */ - -# if HAVE_PTHREAD_RWLOCK - -# ifdef PTHREAD_RWLOCK_INITIALIZER - -typedef pthread_rwlock_t gl_rwlock_t; -# define gl_rwlock_define(STORAGECLASS, NAME) \ - STORAGECLASS pthread_rwlock_t NAME; -# define gl_rwlock_define_initialized(STORAGECLASS, NAME) \ - STORAGECLASS pthread_rwlock_t NAME = gl_rwlock_initializer; -# define gl_rwlock_initializer \ - PTHREAD_RWLOCK_INITIALIZER -# define glthread_rwlock_init(LOCK) \ - (pthread_in_use () ? pthread_rwlock_init (LOCK, NULL) : 0) -# define glthread_rwlock_rdlock(LOCK) \ - (pthread_in_use () ? pthread_rwlock_rdlock (LOCK) : 0) -# define glthread_rwlock_wrlock(LOCK) \ - (pthread_in_use () ? pthread_rwlock_wrlock (LOCK) : 0) -# define glthread_rwlock_unlock(LOCK) \ - (pthread_in_use () ? pthread_rwlock_unlock (LOCK) : 0) -# define glthread_rwlock_destroy(LOCK) \ - (pthread_in_use () ? pthread_rwlock_destroy (LOCK) : 0) - -# else - -typedef struct - { - int initialized; - pthread_mutex_t guard; /* protects the initialization */ - pthread_rwlock_t rwlock; /* read-write lock */ - } - gl_rwlock_t; -# define gl_rwlock_define(STORAGECLASS, NAME) \ - STORAGECLASS gl_rwlock_t NAME; -# define gl_rwlock_define_initialized(STORAGECLASS, NAME) \ - STORAGECLASS gl_rwlock_t NAME = gl_rwlock_initializer; -# define gl_rwlock_initializer \ - { 0, PTHREAD_MUTEX_INITIALIZER } -# define glthread_rwlock_init(LOCK) \ - (pthread_in_use () ? glthread_rwlock_init_multithreaded (LOCK) : 0) -# define glthread_rwlock_rdlock(LOCK) \ - (pthread_in_use () ? glthread_rwlock_rdlock_multithreaded (LOCK) : 0) -# define glthread_rwlock_wrlock(LOCK) \ - (pthread_in_use () ? glthread_rwlock_wrlock_multithreaded (LOCK) : 0) -# define glthread_rwlock_unlock(LOCK) \ - (pthread_in_use () ? glthread_rwlock_unlock_multithreaded (LOCK) : 0) -# define glthread_rwlock_destroy(LOCK) \ - (pthread_in_use () ? glthread_rwlock_destroy_multithreaded (LOCK) : 0) -extern int glthread_rwlock_init_multithreaded (gl_rwlock_t *lock); -extern int glthread_rwlock_rdlock_multithreaded (gl_rwlock_t *lock); -extern int glthread_rwlock_wrlock_multithreaded (gl_rwlock_t *lock); -extern int glthread_rwlock_unlock_multithreaded (gl_rwlock_t *lock); -extern int glthread_rwlock_destroy_multithreaded (gl_rwlock_t *lock); - -# endif - -# else - -typedef struct - { - pthread_mutex_t lock; /* protects the remaining fields */ - pthread_cond_t waiting_readers; /* waiting readers */ - pthread_cond_t waiting_writers; /* waiting writers */ - unsigned int waiting_writers_count; /* number of waiting writers */ - int runcount; /* number of readers running, or -1 when a writer runs */ - } - gl_rwlock_t; -# define gl_rwlock_define(STORAGECLASS, NAME) \ - STORAGECLASS gl_rwlock_t NAME; -# define gl_rwlock_define_initialized(STORAGECLASS, NAME) \ - STORAGECLASS gl_rwlock_t NAME = gl_rwlock_initializer; -# define gl_rwlock_initializer \ - { PTHREAD_MUTEX_INITIALIZER, PTHREAD_COND_INITIALIZER, PTHREAD_COND_INITIALIZER, 0, 0 } -# define glthread_rwlock_init(LOCK) \ - (pthread_in_use () ? glthread_rwlock_init_multithreaded (LOCK) : 0) -# define glthread_rwlock_rdlock(LOCK) \ - (pthread_in_use () ? glthread_rwlock_rdlock_multithreaded (LOCK) : 0) -# define glthread_rwlock_wrlock(LOCK) \ - (pthread_in_use () ? glthread_rwlock_wrlock_multithreaded (LOCK) : 0) -# define glthread_rwlock_unlock(LOCK) \ - (pthread_in_use () ? glthread_rwlock_unlock_multithreaded (LOCK) : 0) -# define glthread_rwlock_destroy(LOCK) \ - (pthread_in_use () ? glthread_rwlock_destroy_multithreaded (LOCK) : 0) -extern int glthread_rwlock_init_multithreaded (gl_rwlock_t *lock); -extern int glthread_rwlock_rdlock_multithreaded (gl_rwlock_t *lock); -extern int glthread_rwlock_wrlock_multithreaded (gl_rwlock_t *lock); -extern int glthread_rwlock_unlock_multithreaded (gl_rwlock_t *lock); -extern int glthread_rwlock_destroy_multithreaded (gl_rwlock_t *lock); - -# endif - -/* --------------------- gl_recursive_lock_t datatype --------------------- */ - -# if HAVE_PTHREAD_MUTEX_RECURSIVE - -# if defined PTHREAD_RECURSIVE_MUTEX_INITIALIZER || defined PTHREAD_RECURSIVE_MUTEX_INITIALIZER_NP - -typedef pthread_mutex_t gl_recursive_lock_t; -# define gl_recursive_lock_define(STORAGECLASS, NAME) \ - STORAGECLASS pthread_mutex_t NAME; -# define gl_recursive_lock_define_initialized(STORAGECLASS, NAME) \ - STORAGECLASS pthread_mutex_t NAME = gl_recursive_lock_initializer; -# ifdef PTHREAD_RECURSIVE_MUTEX_INITIALIZER -# define gl_recursive_lock_initializer \ - PTHREAD_RECURSIVE_MUTEX_INITIALIZER -# else -# define gl_recursive_lock_initializer \ - PTHREAD_RECURSIVE_MUTEX_INITIALIZER_NP -# endif -# define glthread_recursive_lock_init(LOCK) \ - (pthread_in_use () ? glthread_recursive_lock_init_multithreaded (LOCK) : 0) -# define glthread_recursive_lock_lock(LOCK) \ - (pthread_in_use () ? pthread_mutex_lock (LOCK) : 0) -# define glthread_recursive_lock_unlock(LOCK) \ - (pthread_in_use () ? pthread_mutex_unlock (LOCK) : 0) -# define glthread_recursive_lock_destroy(LOCK) \ - (pthread_in_use () ? pthread_mutex_destroy (LOCK) : 0) -extern int glthread_recursive_lock_init_multithreaded (gl_recursive_lock_t *lock); - -# else - -typedef struct - { - pthread_mutex_t recmutex; /* recursive mutex */ - pthread_mutex_t guard; /* protects the initialization */ - int initialized; - } - gl_recursive_lock_t; -# define gl_recursive_lock_define(STORAGECLASS, NAME) \ - STORAGECLASS gl_recursive_lock_t NAME; -# define gl_recursive_lock_define_initialized(STORAGECLASS, NAME) \ - STORAGECLASS gl_recursive_lock_t NAME = gl_recursive_lock_initializer; -# define gl_recursive_lock_initializer \ - { PTHREAD_MUTEX_INITIALIZER, PTHREAD_MUTEX_INITIALIZER, 0 } -# define glthread_recursive_lock_init(LOCK) \ - (pthread_in_use () ? glthread_recursive_lock_init_multithreaded (LOCK) : 0) -# define glthread_recursive_lock_lock(LOCK) \ - (pthread_in_use () ? glthread_recursive_lock_lock_multithreaded (LOCK) : 0) -# define glthread_recursive_lock_unlock(LOCK) \ - (pthread_in_use () ? glthread_recursive_lock_unlock_multithreaded (LOCK) : 0) -# define glthread_recursive_lock_destroy(LOCK) \ - (pthread_in_use () ? glthread_recursive_lock_destroy_multithreaded (LOCK) : 0) -extern int glthread_recursive_lock_init_multithreaded (gl_recursive_lock_t *lock); -extern int glthread_recursive_lock_lock_multithreaded (gl_recursive_lock_t *lock); -extern int glthread_recursive_lock_unlock_multithreaded (gl_recursive_lock_t *lock); -extern int glthread_recursive_lock_destroy_multithreaded (gl_recursive_lock_t *lock); - -# endif - -# else - -/* Old versions of POSIX threads on Solaris did not have recursive locks. - We have to implement them ourselves. */ - -typedef struct - { - pthread_mutex_t mutex; - pthread_t owner; - unsigned long depth; - } - gl_recursive_lock_t; -# define gl_recursive_lock_define(STORAGECLASS, NAME) \ - STORAGECLASS gl_recursive_lock_t NAME; -# define gl_recursive_lock_define_initialized(STORAGECLASS, NAME) \ - STORAGECLASS gl_recursive_lock_t NAME = gl_recursive_lock_initializer; -# define gl_recursive_lock_initializer \ - { PTHREAD_MUTEX_INITIALIZER, (pthread_t) 0, 0 } -# define glthread_recursive_lock_init(LOCK) \ - (pthread_in_use () ? glthread_recursive_lock_init_multithreaded (LOCK) : 0) -# define glthread_recursive_lock_lock(LOCK) \ - (pthread_in_use () ? glthread_recursive_lock_lock_multithreaded (LOCK) : 0) -# define glthread_recursive_lock_unlock(LOCK) \ - (pthread_in_use () ? glthread_recursive_lock_unlock_multithreaded (LOCK) : 0) -# define glthread_recursive_lock_destroy(LOCK) \ - (pthread_in_use () ? glthread_recursive_lock_destroy_multithreaded (LOCK) : 0) -extern int glthread_recursive_lock_init_multithreaded (gl_recursive_lock_t *lock); -extern int glthread_recursive_lock_lock_multithreaded (gl_recursive_lock_t *lock); -extern int glthread_recursive_lock_unlock_multithreaded (gl_recursive_lock_t *lock); -extern int glthread_recursive_lock_destroy_multithreaded (gl_recursive_lock_t *lock); - -# endif - -/* -------------------------- gl_once_t datatype -------------------------- */ - -typedef pthread_once_t gl_once_t; -# define gl_once_define(STORAGECLASS, NAME) \ - STORAGECLASS pthread_once_t NAME = PTHREAD_ONCE_INIT; -# define glthread_once(ONCE_CONTROL, INITFUNCTION) \ - (pthread_in_use () \ - ? pthread_once (ONCE_CONTROL, INITFUNCTION) \ - : (glthread_once_singlethreaded (ONCE_CONTROL) ? (INITFUNCTION (), 0) : 0)) -extern int glthread_once_singlethreaded (pthread_once_t *once_control); - -# ifdef __cplusplus -} -# endif - -#endif - -/* ========================================================================= */ - -#if USE_PTH_THREADS - -/* Use the GNU Pth threads library. */ - -# include <pth.h> - -# ifdef __cplusplus -extern "C" { -# endif - -# if USE_PTH_THREADS_WEAK - -/* Use weak references to the GNU Pth threads library. */ - -# pragma weak pth_mutex_init -# pragma weak pth_mutex_acquire -# pragma weak pth_mutex_release -# pragma weak pth_rwlock_init -# pragma weak pth_rwlock_acquire -# pragma weak pth_rwlock_release -# pragma weak pth_once - -# pragma weak pth_cancel -# define pth_in_use() (pth_cancel != NULL) - -# else - -# define pth_in_use() 1 - -# endif - -/* -------------------------- gl_lock_t datatype -------------------------- */ - -typedef pth_mutex_t gl_lock_t; -# define gl_lock_define(STORAGECLASS, NAME) \ - STORAGECLASS pth_mutex_t NAME; -# define gl_lock_define_initialized(STORAGECLASS, NAME) \ - STORAGECLASS pth_mutex_t NAME = gl_lock_initializer; -# define gl_lock_initializer \ - PTH_MUTEX_INIT -# define glthread_lock_init(LOCK) \ - (pth_in_use () && !pth_mutex_init (LOCK) ? errno : 0) -# define glthread_lock_lock(LOCK) \ - (pth_in_use () && !pth_mutex_acquire (LOCK, 0, NULL) ? errno : 0) -# define glthread_lock_unlock(LOCK) \ - (pth_in_use () && !pth_mutex_release (LOCK) ? errno : 0) -# define glthread_lock_destroy(LOCK) \ - ((void)(LOCK), 0) - -/* ------------------------- gl_rwlock_t datatype ------------------------- */ - -typedef pth_rwlock_t gl_rwlock_t; -# define gl_rwlock_define(STORAGECLASS, NAME) \ - STORAGECLASS pth_rwlock_t NAME; -# define gl_rwlock_define_initialized(STORAGECLASS, NAME) \ - STORAGECLASS pth_rwlock_t NAME = gl_rwlock_initializer; -# define gl_rwlock_initializer \ - PTH_RWLOCK_INIT -# define glthread_rwlock_init(LOCK) \ - (pth_in_use () && !pth_rwlock_init (LOCK) ? errno : 0) -# define glthread_rwlock_rdlock(LOCK) \ - (pth_in_use () && !pth_rwlock_acquire (LOCK, PTH_RWLOCK_RD, 0, NULL) ? errno : 0) -# define glthread_rwlock_wrlock(LOCK) \ - (pth_in_use () && !pth_rwlock_acquire (LOCK, PTH_RWLOCK_RW, 0, NULL) ? errno : 0) -# define glthread_rwlock_unlock(LOCK) \ - (pth_in_use () && !pth_rwlock_release (LOCK) ? errno : 0) -# define glthread_rwlock_destroy(LOCK) \ - ((void)(LOCK), 0) - -/* --------------------- gl_recursive_lock_t datatype --------------------- */ - -/* In Pth, mutexes are recursive by default. */ -typedef pth_mutex_t gl_recursive_lock_t; -# define gl_recursive_lock_define(STORAGECLASS, NAME) \ - STORAGECLASS pth_mutex_t NAME; -# define gl_recursive_lock_define_initialized(STORAGECLASS, NAME) \ - STORAGECLASS pth_mutex_t NAME = gl_recursive_lock_initializer; -# define gl_recursive_lock_initializer \ - PTH_MUTEX_INIT -# define glthread_recursive_lock_init(LOCK) \ - (pth_in_use () && !pth_mutex_init (LOCK) ? errno : 0) -# define glthread_recursive_lock_lock(LOCK) \ - (pth_in_use () && !pth_mutex_acquire (LOCK, 0, NULL) ? errno : 0) -# define glthread_recursive_lock_unlock(LOCK) \ - (pth_in_use () && !pth_mutex_release (LOCK) ? errno : 0) -# define glthread_recursive_lock_destroy(LOCK) \ - ((void)(LOCK), 0) - -/* -------------------------- gl_once_t datatype -------------------------- */ - -typedef pth_once_t gl_once_t; -# define gl_once_define(STORAGECLASS, NAME) \ - STORAGECLASS pth_once_t NAME = PTH_ONCE_INIT; -# define glthread_once(ONCE_CONTROL, INITFUNCTION) \ - (pth_in_use () \ - ? glthread_once_multithreaded (ONCE_CONTROL, INITFUNCTION) \ - : (glthread_once_singlethreaded (ONCE_CONTROL) ? (INITFUNCTION (), 0) : 0)) -extern int glthread_once_multithreaded (pth_once_t *once_control, void (*initfunction) (void)); -extern int glthread_once_singlethreaded (pth_once_t *once_control); - -# ifdef __cplusplus -} -# endif - -#endif - -/* ========================================================================= */ - -#if USE_SOLARIS_THREADS - -/* Use the old Solaris threads library. */ - -# include <thread.h> -# include <synch.h> - -# ifdef __cplusplus -extern "C" { -# endif - -# if USE_SOLARIS_THREADS_WEAK - -/* Use weak references to the old Solaris threads library. */ - -# pragma weak mutex_init -# pragma weak mutex_lock -# pragma weak mutex_unlock -# pragma weak mutex_destroy -# pragma weak rwlock_init -# pragma weak rw_rdlock -# pragma weak rw_wrlock -# pragma weak rw_unlock -# pragma weak rwlock_destroy -# pragma weak thr_self - -# pragma weak thr_suspend -# define thread_in_use() (thr_suspend != NULL) - -# else - -# define thread_in_use() 1 - -# endif - -/* -------------------------- gl_lock_t datatype -------------------------- */ - -typedef mutex_t gl_lock_t; -# define gl_lock_define(STORAGECLASS, NAME) \ - STORAGECLASS mutex_t NAME; -# define gl_lock_define_initialized(STORAGECLASS, NAME) \ - STORAGECLASS mutex_t NAME = gl_lock_initializer; -# define gl_lock_initializer \ - DEFAULTMUTEX -# define glthread_lock_init(LOCK) \ - (thread_in_use () ? mutex_init (LOCK, USYNC_THREAD, NULL) : 0) -# define glthread_lock_lock(LOCK) \ - (thread_in_use () ? mutex_lock (LOCK) : 0) -# define glthread_lock_unlock(LOCK) \ - (thread_in_use () ? mutex_unlock (LOCK) : 0) -# define glthread_lock_destroy(LOCK) \ - (thread_in_use () ? mutex_destroy (LOCK) : 0) - -/* ------------------------- gl_rwlock_t datatype ------------------------- */ - -typedef rwlock_t gl_rwlock_t; -# define gl_rwlock_define(STORAGECLASS, NAME) \ - STORAGECLASS rwlock_t NAME; -# define gl_rwlock_define_initialized(STORAGECLASS, NAME) \ - STORAGECLASS rwlock_t NAME = gl_rwlock_initializer; -# define gl_rwlock_initializer \ - DEFAULTRWLOCK -# define glthread_rwlock_init(LOCK) \ - (thread_in_use () ? rwlock_init (LOCK, USYNC_THREAD, NULL) : 0) -# define glthread_rwlock_rdlock(LOCK) \ - (thread_in_use () ? rw_rdlock (LOCK) : 0) -# define glthread_rwlock_wrlock(LOCK) \ - (thread_in_use () ? rw_wrlock (LOCK) : 0) -# define glthread_rwlock_unlock(LOCK) \ - (thread_in_use () ? rw_unlock (LOCK) : 0) -# define glthread_rwlock_destroy(LOCK) \ - (thread_in_use () ? rwlock_destroy (LOCK) : 0) - -/* --------------------- gl_recursive_lock_t datatype --------------------- */ - -/* Old Solaris threads did not have recursive locks. - We have to implement them ourselves. */ - -typedef struct - { - mutex_t mutex; - thread_t owner; - unsigned long depth; - } - gl_recursive_lock_t; -# define gl_recursive_lock_define(STORAGECLASS, NAME) \ - STORAGECLASS gl_recursive_lock_t NAME; -# define gl_recursive_lock_define_initialized(STORAGECLASS, NAME) \ - STORAGECLASS gl_recursive_lock_t NAME = gl_recursive_lock_initializer; -# define gl_recursive_lock_initializer \ - { DEFAULTMUTEX, (thread_t) 0, 0 } -# define glthread_recursive_lock_init(LOCK) \ - (thread_in_use () ? glthread_recursive_lock_init_multithreaded (LOCK) : 0) -# define glthread_recursive_lock_lock(LOCK) \ - (thread_in_use () ? glthread_recursive_lock_lock_multithreaded (LOCK) : 0) -# define glthread_recursive_lock_unlock(LOCK) \ - (thread_in_use () ? glthread_recursive_lock_unlock_multithreaded (LOCK) : 0) -# define glthread_recursive_lock_destroy(LOCK) \ - (thread_in_use () ? glthread_recursive_lock_destroy_multithreaded (LOCK) : 0) -extern int glthread_recursive_lock_init_multithreaded (gl_recursive_lock_t *lock); -extern int glthread_recursive_lock_lock_multithreaded (gl_recursive_lock_t *lock); -extern int glthread_recursive_lock_unlock_multithreaded (gl_recursive_lock_t *lock); -extern int glthread_recursive_lock_destroy_multithreaded (gl_recursive_lock_t *lock); - -/* -------------------------- gl_once_t datatype -------------------------- */ - -typedef struct - { - volatile int inited; - mutex_t mutex; - } - gl_once_t; -# define gl_once_define(STORAGECLASS, NAME) \ - STORAGECLASS gl_once_t NAME = { 0, DEFAULTMUTEX }; -# define glthread_once(ONCE_CONTROL, INITFUNCTION) \ - (thread_in_use () \ - ? glthread_once_multithreaded (ONCE_CONTROL, INITFUNCTION) \ - : (glthread_once_singlethreaded (ONCE_CONTROL) ? (INITFUNCTION (), 0) : 0)) -extern int glthread_once_multithreaded (gl_once_t *once_control, void (*initfunction) (void)); -extern int glthread_once_singlethreaded (gl_once_t *once_control); - -# ifdef __cplusplus -} -# endif - -#endif - -/* ========================================================================= */ - -#if USE_WINDOWS_THREADS - -# define WIN32_LEAN_AND_MEAN /* avoid including junk */ -# include <windows.h> - -# ifdef __cplusplus -extern "C" { -# endif - -/* We can use CRITICAL_SECTION directly, rather than the native Windows Event, - Mutex, Semaphore types, because - - we need only to synchronize inside a single process (address space), - not inter-process locking, - - we don't need to support trylock operations. (TryEnterCriticalSection - does not work on Windows 95/98/ME. Packages that need trylock usually - define their own mutex type.) */ - -/* There is no way to statically initialize a CRITICAL_SECTION. It needs - to be done lazily, once only. For this we need spinlocks. */ - -typedef struct { volatile int done; volatile long started; } gl_spinlock_t; - -/* -------------------------- gl_lock_t datatype -------------------------- */ - -typedef struct - { - gl_spinlock_t guard; /* protects the initialization */ - CRITICAL_SECTION lock; - } - gl_lock_t; -# define gl_lock_define(STORAGECLASS, NAME) \ - STORAGECLASS gl_lock_t NAME; -# define gl_lock_define_initialized(STORAGECLASS, NAME) \ - STORAGECLASS gl_lock_t NAME = gl_lock_initializer; -# define gl_lock_initializer \ - { { 0, -1 } } -# define glthread_lock_init(LOCK) \ - (glthread_lock_init_func (LOCK), 0) -# define glthread_lock_lock(LOCK) \ - glthread_lock_lock_func (LOCK) -# define glthread_lock_unlock(LOCK) \ - glthread_lock_unlock_func (LOCK) -# define glthread_lock_destroy(LOCK) \ - glthread_lock_destroy_func (LOCK) -extern void glthread_lock_init_func (gl_lock_t *lock); -extern int glthread_lock_lock_func (gl_lock_t *lock); -extern int glthread_lock_unlock_func (gl_lock_t *lock); -extern int glthread_lock_destroy_func (gl_lock_t *lock); - -/* ------------------------- gl_rwlock_t datatype ------------------------- */ - -/* It is impossible to implement read-write locks using plain locks, without - introducing an extra thread dedicated to managing read-write locks. - Therefore here we need to use the low-level Event type. */ - -typedef struct - { - HANDLE *array; /* array of waiting threads, each represented by an event */ - unsigned int count; /* number of waiting threads */ - unsigned int alloc; /* length of allocated array */ - unsigned int offset; /* index of first waiting thread in array */ - } - gl_carray_waitqueue_t; -typedef struct - { - gl_spinlock_t guard; /* protects the initialization */ - CRITICAL_SECTION lock; /* protects the remaining fields */ - gl_carray_waitqueue_t waiting_readers; /* waiting readers */ - gl_carray_waitqueue_t waiting_writers; /* waiting writers */ - int runcount; /* number of readers running, or -1 when a writer runs */ - } - gl_rwlock_t; -# define gl_rwlock_define(STORAGECLASS, NAME) \ - STORAGECLASS gl_rwlock_t NAME; -# define gl_rwlock_define_initialized(STORAGECLASS, NAME) \ - STORAGECLASS gl_rwlock_t NAME = gl_rwlock_initializer; -# define gl_rwlock_initializer \ - { { 0, -1 } } -# define glthread_rwlock_init(LOCK) \ - (glthread_rwlock_init_func (LOCK), 0) -# define glthread_rwlock_rdlock(LOCK) \ - glthread_rwlock_rdlock_func (LOCK) -# define glthread_rwlock_wrlock(LOCK) \ - glthread_rwlock_wrlock_func (LOCK) -# define glthread_rwlock_unlock(LOCK) \ - glthread_rwlock_unlock_func (LOCK) -# define glthread_rwlock_destroy(LOCK) \ - glthread_rwlock_destroy_func (LOCK) -extern void glthread_rwlock_init_func (gl_rwlock_t *lock); -extern int glthread_rwlock_rdlock_func (gl_rwlock_t *lock); -extern int glthread_rwlock_wrlock_func (gl_rwlock_t *lock); -extern int glthread_rwlock_unlock_func (gl_rwlock_t *lock); -extern int glthread_rwlock_destroy_func (gl_rwlock_t *lock); - -/* --------------------- gl_recursive_lock_t datatype --------------------- */ - -/* The native Windows documentation says that CRITICAL_SECTION already - implements a recursive lock. But we need not rely on it: It's easy to - implement a recursive lock without this assumption. */ - -typedef struct - { - gl_spinlock_t guard; /* protects the initialization */ - DWORD owner; - unsigned long depth; - CRITICAL_SECTION lock; - } - gl_recursive_lock_t; -# define gl_recursive_lock_define(STORAGECLASS, NAME) \ - STORAGECLASS gl_recursive_lock_t NAME; -# define gl_recursive_lock_define_initialized(STORAGECLASS, NAME) \ - STORAGECLASS gl_recursive_lock_t NAME = gl_recursive_lock_initializer; -# define gl_recursive_lock_initializer \ - { { 0, -1 }, 0, 0 } -# define glthread_recursive_lock_init(LOCK) \ - (glthread_recursive_lock_init_func (LOCK), 0) -# define glthread_recursive_lock_lock(LOCK) \ - glthread_recursive_lock_lock_func (LOCK) -# define glthread_recursive_lock_unlock(LOCK) \ - glthread_recursive_lock_unlock_func (LOCK) -# define glthread_recursive_lock_destroy(LOCK) \ - glthread_recursive_lock_destroy_func (LOCK) -extern void glthread_recursive_lock_init_func (gl_recursive_lock_t *lock); -extern int glthread_recursive_lock_lock_func (gl_recursive_lock_t *lock); -extern int glthread_recursive_lock_unlock_func (gl_recursive_lock_t *lock); -extern int glthread_recursive_lock_destroy_func (gl_recursive_lock_t *lock); - -/* -------------------------- gl_once_t datatype -------------------------- */ - -typedef struct - { - volatile int inited; - volatile long started; - CRITICAL_SECTION lock; - } - gl_once_t; -# define gl_once_define(STORAGECLASS, NAME) \ - STORAGECLASS gl_once_t NAME = { -1, -1 }; -# define glthread_once(ONCE_CONTROL, INITFUNCTION) \ - (glthread_once_func (ONCE_CONTROL, INITFUNCTION), 0) -extern void glthread_once_func (gl_once_t *once_control, void (*initfunction) (void)); - -# ifdef __cplusplus -} -# endif - -#endif - -/* ========================================================================= */ - -#if !(USE_POSIX_THREADS || USE_PTH_THREADS || USE_SOLARIS_THREADS || USE_WINDOWS_THREADS) - -/* Provide dummy implementation if threads are not supported. */ - -/* -------------------------- gl_lock_t datatype -------------------------- */ - -typedef int gl_lock_t; -# define gl_lock_define(STORAGECLASS, NAME) -# define gl_lock_define_initialized(STORAGECLASS, NAME) -# define glthread_lock_init(NAME) 0 -# define glthread_lock_lock(NAME) 0 -# define glthread_lock_unlock(NAME) 0 -# define glthread_lock_destroy(NAME) 0 - -/* ------------------------- gl_rwlock_t datatype ------------------------- */ - -typedef int gl_rwlock_t; -# define gl_rwlock_define(STORAGECLASS, NAME) -# define gl_rwlock_define_initialized(STORAGECLASS, NAME) -# define glthread_rwlock_init(NAME) 0 -# define glthread_rwlock_rdlock(NAME) 0 -# define glthread_rwlock_wrlock(NAME) 0 -# define glthread_rwlock_unlock(NAME) 0 -# define glthread_rwlock_destroy(NAME) 0 - -/* --------------------- gl_recursive_lock_t datatype --------------------- */ - -typedef int gl_recursive_lock_t; -# define gl_recursive_lock_define(STORAGECLASS, NAME) -# define gl_recursive_lock_define_initialized(STORAGECLASS, NAME) -# define glthread_recursive_lock_init(NAME) 0 -# define glthread_recursive_lock_lock(NAME) 0 -# define glthread_recursive_lock_unlock(NAME) 0 -# define glthread_recursive_lock_destroy(NAME) 0 - -/* -------------------------- gl_once_t datatype -------------------------- */ - -typedef int gl_once_t; -# define gl_once_define(STORAGECLASS, NAME) \ - STORAGECLASS gl_once_t NAME = 0; -# define glthread_once(ONCE_CONTROL, INITFUNCTION) \ - (*(ONCE_CONTROL) == 0 ? (*(ONCE_CONTROL) = ~ 0, INITFUNCTION (), 0) : 0) - -#endif - -/* ========================================================================= */ - -/* Macros with built-in error handling. */ - -/* -------------------------- gl_lock_t datatype -------------------------- */ - -#define gl_lock_init(NAME) \ - do \ - { \ - if (glthread_lock_init (&NAME)) \ - abort (); \ - } \ - while (0) -#define gl_lock_lock(NAME) \ - do \ - { \ - if (glthread_lock_lock (&NAME)) \ - abort (); \ - } \ - while (0) -#define gl_lock_unlock(NAME) \ - do \ - { \ - if (glthread_lock_unlock (&NAME)) \ - abort (); \ - } \ - while (0) -#define gl_lock_destroy(NAME) \ - do \ - { \ - if (glthread_lock_destroy (&NAME)) \ - abort (); \ - } \ - while (0) - -/* ------------------------- gl_rwlock_t datatype ------------------------- */ - -#define gl_rwlock_init(NAME) \ - do \ - { \ - if (glthread_rwlock_init (&NAME)) \ - abort (); \ - } \ - while (0) -#define gl_rwlock_rdlock(NAME) \ - do \ - { \ - if (glthread_rwlock_rdlock (&NAME)) \ - abort (); \ - } \ - while (0) -#define gl_rwlock_wrlock(NAME) \ - do \ - { \ - if (glthread_rwlock_wrlock (&NAME)) \ - abort (); \ - } \ - while (0) -#define gl_rwlock_unlock(NAME) \ - do \ - { \ - if (glthread_rwlock_unlock (&NAME)) \ - abort (); \ - } \ - while (0) -#define gl_rwlock_destroy(NAME) \ - do \ - { \ - if (glthread_rwlock_destroy (&NAME)) \ - abort (); \ - } \ - while (0) - -/* --------------------- gl_recursive_lock_t datatype --------------------- */ - -#define gl_recursive_lock_init(NAME) \ - do \ - { \ - if (glthread_recursive_lock_init (&NAME)) \ - abort (); \ - } \ - while (0) -#define gl_recursive_lock_lock(NAME) \ - do \ - { \ - if (glthread_recursive_lock_lock (&NAME)) \ - abort (); \ - } \ - while (0) -#define gl_recursive_lock_unlock(NAME) \ - do \ - { \ - if (glthread_recursive_lock_unlock (&NAME)) \ - abort (); \ - } \ - while (0) -#define gl_recursive_lock_destroy(NAME) \ - do \ - { \ - if (glthread_recursive_lock_destroy (&NAME)) \ - abort (); \ - } \ - while (0) - -/* -------------------------- gl_once_t datatype -------------------------- */ - -#define gl_once(NAME, INITFUNCTION) \ - do \ - { \ - if (glthread_once (&NAME, INITFUNCTION)) \ - abort (); \ - } \ - while (0) - -/* ========================================================================= */ - -#endif /* _LOCK_H */ diff --git a/gl/tests/glthread/threadlib.c b/gl/tests/glthread/threadlib.c deleted file mode 100644 index 26870de241..0000000000 --- a/gl/tests/glthread/threadlib.c +++ /dev/null @@ -1,73 +0,0 @@ -/* Multithreading primitives. - Copyright (C) 2005-2014 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, 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 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/>. */ - -/* Written by Bruno Haible <bruno@clisp.org>, 2005. */ - -#include <config.h> - -/* ========================================================================= */ - -#if USE_POSIX_THREADS - -/* Use the POSIX threads library. */ - -# include <pthread.h> -# include <stdlib.h> - -# if PTHREAD_IN_USE_DETECTION_HARD - -/* The function to be executed by a dummy thread. */ -static void * -dummy_thread_func (void *arg) -{ - return arg; -} - -int -glthread_in_use (void) -{ - static int tested; - static int result; /* 1: linked with -lpthread, 0: only with libc */ - - if (!tested) - { - pthread_t thread; - - if (pthread_create (&thread, NULL, dummy_thread_func, NULL) != 0) - /* Thread creation failed. */ - result = 0; - else - { - /* Thread creation works. */ - void *retval; - if (pthread_join (thread, &retval) != 0) - abort (); - result = 1; - } - tested = 1; - } - return result; -} - -# endif - -#endif - -/* ========================================================================= */ - -/* This declaration is solely to ensure that after preprocessing - this file is never empty. */ -typedef int dummy; diff --git a/gl/tests/ignore-value.h b/gl/tests/ignore-value.h deleted file mode 100644 index 4dd0946d4b..0000000000 --- a/gl/tests/ignore-value.h +++ /dev/null @@ -1,50 +0,0 @@ -/* ignore a function return without a compiler warning - - Copyright (C) 2008-2014 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 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/>. */ - -/* Written by Jim Meyering, Eric Blake and Pádraig Brady. */ - -/* Use "ignore_value" to avoid a warning when using a function declared with - gcc's warn_unused_result attribute, but for which you really do want to - ignore the result. Traditionally, people have used a "(void)" cast to - indicate that a function's return value is deliberately unused. However, - if the function is declared with __attribute__((warn_unused_result)), - gcc issues a warning even with the cast. - - Caution: most of the time, you really should heed gcc's warning, and - check the return value. However, in those exceptional cases in which - you're sure you know what you're doing, use this function. - - For the record, here's one of the ignorable warnings: - "copy.c:233: warning: ignoring return value of 'fchown', - declared with attribute warn_unused_result". */ - -#ifndef _GL_IGNORE_VALUE_H -#define _GL_IGNORE_VALUE_H - -/* Normally casting an expression to void discards its value, but GCC - versions 3.4 and newer have __attribute__ ((__warn_unused_result__)) - which may cause unwanted diagnostics in that case. Use __typeof__ - and __extension__ to work around the problem, if the workaround is - known to be needed. */ -#if 3 < __GNUC__ + (4 <= __GNUC_MINOR__) -# define ignore_value(x) \ - (__extension__ ({ __typeof__ (x) __x = (x); (void) __x; })) -#else -# define ignore_value(x) ((void) (x)) -#endif - -#endif diff --git a/gl/tests/ioctl.c b/gl/tests/ioctl.c deleted file mode 100644 index 89afb4eaf4..0000000000 --- a/gl/tests/ioctl.c +++ /dev/null @@ -1,88 +0,0 @@ -/* ioctl.c --- wrappers for Windows ioctl function - - Copyright (C) 2008-2014 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 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/>. */ - -/* Written by Paolo Bonzini */ - -#include <config.h> - -#include <sys/ioctl.h> - -#include <stdarg.h> - -#if HAVE_IOCTL - -/* Provide a wrapper with the POSIX prototype. */ -# undef ioctl -int -rpl_ioctl (int fd, int request, ... /* {void *,char *} arg */) -{ - void *buf; - va_list args; - - va_start (args, request); - buf = va_arg (args, void *); - va_end (args); - - /* Cast 'request' so that when the system's ioctl function takes a 64-bit - request argument, the value gets zero-extended, not sign-extended. */ - return ioctl (fd, (unsigned int) request, buf); -} - -#else /* mingw */ - -# include <errno.h> - -/* Get HANDLE. */ -# define WIN32_LEAN_AND_MEAN -# include <windows.h> - -# include "fd-hook.h" -/* Get _get_osfhandle. */ -# include "msvc-nothrow.h" - -static int -primary_ioctl (int fd, int request, void *arg) -{ - /* We don't support FIONBIO on pipes here. If you want to make pipe - fds non-blocking, use the gnulib 'nonblocking' module, until - gnulib implements fcntl F_GETFL / F_SETFL with O_NONBLOCK. */ - - if ((HANDLE) _get_osfhandle (fd) != INVALID_HANDLE_VALUE) - errno = ENOSYS; - else - errno = EBADF; - return -1; -} - -int -ioctl (int fd, int request, ... /* {void *,char *} arg */) -{ - void *arg; - va_list args; - - va_start (args, request); - arg = va_arg (args, void *); - va_end (args); - -# if WINDOWS_SOCKETS - return execute_all_ioctl_hooks (primary_ioctl, fd, request, arg); -# else - return primary_ioctl (fd, request, arg); -# endif -} - -#endif diff --git a/gl/tests/lstat.c b/gl/tests/lstat.c deleted file mode 100644 index f70fd435c0..0000000000 --- a/gl/tests/lstat.c +++ /dev/null @@ -1,97 +0,0 @@ -/* Work around a bug of lstat on some systems - - Copyright (C) 1997-2006, 2008-2014 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 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/>. */ - -/* written by Jim Meyering */ - -/* If the user's config.h happens to include <sys/stat.h>, let it include only - the system's <sys/stat.h> here, so that orig_lstat doesn't recurse to - rpl_lstat. */ -#define __need_system_sys_stat_h -#include <config.h> - -#if !HAVE_LSTAT -/* On systems that lack symlinks, our replacement <sys/stat.h> already - defined lstat as stat, so there is nothing further to do other than - avoid an empty file. */ -typedef int dummy; -#else /* HAVE_LSTAT */ - -/* Get the original definition of lstat. It might be defined as a macro. */ -# include <sys/types.h> -# include <sys/stat.h> -# undef __need_system_sys_stat_h - -static int -orig_lstat (const char *filename, struct stat *buf) -{ - return lstat (filename, buf); -} - -/* Specification. */ -/* Write "sys/stat.h" here, not <sys/stat.h>, otherwise OSF/1 5.1 DTK cc - eliminates this include because of the preliminary #include <sys/stat.h> - above. */ -# include "sys/stat.h" - -# include <string.h> -# include <errno.h> - -/* lstat works differently on Linux and Solaris systems. POSIX (see - "pathname resolution" in the glossary) requires that programs like - 'ls' take into consideration the fact that FILE has a trailing slash - when FILE is a symbolic link. On Linux and Solaris 10 systems, the - lstat function already has the desired semantics (in treating - 'lstat ("symlink/", sbuf)' just like 'lstat ("symlink/.", sbuf)', - but on Solaris 9 and earlier it does not. - - If FILE has a trailing slash and specifies a symbolic link, - then use stat() to get more info on the referent of FILE. - If the referent is a non-directory, then set errno to ENOTDIR - and return -1. Otherwise, return stat's result. */ - -int -rpl_lstat (const char *file, struct stat *sbuf) -{ - size_t len; - int lstat_result = orig_lstat (file, sbuf); - - if (lstat_result != 0) - return lstat_result; - - /* This replacement file can blindly check against '/' rather than - using the ISSLASH macro, because all platforms with '\\' either - lack symlinks (mingw) or have working lstat (cygwin) and thus do - not compile this file. 0 len should have already been filtered - out above, with a failure return of ENOENT. */ - len = strlen (file); - if (file[len - 1] != '/' || S_ISDIR (sbuf->st_mode)) - return 0; - - /* At this point, a trailing slash is only permitted on - symlink-to-dir; but it should have found information on the - directory, not the symlink. Call stat() to get info about the - link's referent. Our replacement stat guarantees valid results, - even if the symlink is not pointing to a directory. */ - if (!S_ISLNK (sbuf->st_mode)) - { - errno = ENOTDIR; - return -1; - } - return stat (file, sbuf); -} - -#endif /* HAVE_LSTAT */ diff --git a/gl/tests/open.c b/gl/tests/open.c deleted file mode 100644 index d6f8e0df89..0000000000 --- a/gl/tests/open.c +++ /dev/null @@ -1,181 +0,0 @@ -/* Open a descriptor to a file. - Copyright (C) 2007-2014 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 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/>. */ - -/* Written by Bruno Haible <bruno@clisp.org>, 2007. */ - -/* If the user's config.h happens to include <fcntl.h>, let it include only - the system's <fcntl.h> here, so that orig_open doesn't recurse to - rpl_open. */ -#define __need_system_fcntl_h -#include <config.h> - -/* Get the original definition of open. It might be defined as a macro. */ -#include <fcntl.h> -#include <sys/types.h> -#undef __need_system_fcntl_h - -static int -orig_open (const char *filename, int flags, mode_t mode) -{ - return open (filename, flags, mode); -} - -/* Specification. */ -/* Write "fcntl.h" here, not <fcntl.h>, otherwise OSF/1 5.1 DTK cc eliminates - this include because of the preliminary #include <fcntl.h> above. */ -#include "fcntl.h" - -#include <errno.h> -#include <stdarg.h> -#include <string.h> -#include <sys/types.h> -#include <sys/stat.h> -#include <unistd.h> - -#ifndef REPLACE_OPEN_DIRECTORY -# define REPLACE_OPEN_DIRECTORY 0 -#endif - -int -open (const char *filename, int flags, ...) -{ - mode_t mode; - int fd; - - mode = 0; - if (flags & O_CREAT) - { - va_list arg; - va_start (arg, flags); - - /* We have to use PROMOTED_MODE_T instead of mode_t, otherwise GCC 4 - creates crashing code when 'mode_t' is smaller than 'int'. */ - mode = va_arg (arg, PROMOTED_MODE_T); - - va_end (arg); - } - -#if GNULIB_defined_O_NONBLOCK - /* The only known platform that lacks O_NONBLOCK is mingw, but it - also lacks named pipes and Unix sockets, which are the only two - file types that require non-blocking handling in open(). - Therefore, it is safe to ignore O_NONBLOCK here. It is handy - that mingw also lacks openat(), so that is also covered here. */ - flags &= ~O_NONBLOCK; -#endif - -#if (defined _WIN32 || defined __WIN32__) && ! defined __CYGWIN__ - if (strcmp (filename, "/dev/null") == 0) - filename = "NUL"; -#endif - -#if OPEN_TRAILING_SLASH_BUG - /* If the filename ends in a slash and one of O_CREAT, O_WRONLY, O_RDWR - is specified, then fail. - Rationale: POSIX <http://www.opengroup.org/susv3/basedefs/xbd_chap04.html> - says that - "A pathname that contains at least one non-slash character and that - ends with one or more trailing slashes shall be resolved as if a - single dot character ( '.' ) were appended to the pathname." - and - "The special filename dot shall refer to the directory specified by - its predecessor." - If the named file already exists as a directory, then - - if O_CREAT is specified, open() must fail because of the semantics - of O_CREAT, - - if O_WRONLY or O_RDWR is specified, open() must fail because POSIX - <http://www.opengroup.org/susv3/functions/open.html> says that it - fails with errno = EISDIR in this case. - If the named file does not exist or does not name a directory, then - - if O_CREAT is specified, open() must fail since open() cannot create - directories, - - if O_WRONLY or O_RDWR is specified, open() must fail because the - file does not contain a '.' directory. */ - if (flags & (O_CREAT | O_WRONLY | O_RDWR)) - { - size_t len = strlen (filename); - if (len > 0 && filename[len - 1] == '/') - { - errno = EISDIR; - return -1; - } - } -#endif - - fd = orig_open (filename, flags, mode); - -#if REPLACE_FCHDIR - /* Implementing fchdir and fdopendir requires the ability to open a - directory file descriptor. If open doesn't support that (as on - mingw), we use a dummy file that behaves the same as directories - on Linux (ie. always reports EOF on attempts to read()), and - override fstat() in fchdir.c to hide the fact that we have a - dummy. */ - if (REPLACE_OPEN_DIRECTORY && fd < 0 && errno == EACCES - && ((flags & O_ACCMODE) == O_RDONLY - || (O_SEARCH != O_RDONLY && (flags & O_ACCMODE) == O_SEARCH))) - { - struct stat statbuf; - if (stat (filename, &statbuf) == 0 && S_ISDIR (statbuf.st_mode)) - { - /* Maximum recursion depth of 1. */ - fd = open ("/dev/null", flags, mode); - if (0 <= fd) - fd = _gl_register_fd (fd, filename); - } - else - errno = EACCES; - } -#endif - -#if OPEN_TRAILING_SLASH_BUG - /* If the filename ends in a slash and fd does not refer to a directory, - then fail. - Rationale: POSIX <http://www.opengroup.org/susv3/basedefs/xbd_chap04.html> - says that - "A pathname that contains at least one non-slash character and that - ends with one or more trailing slashes shall be resolved as if a - single dot character ( '.' ) were appended to the pathname." - and - "The special filename dot shall refer to the directory specified by - its predecessor." - If the named file without the slash is not a directory, open() must fail - with ENOTDIR. */ - if (fd >= 0) - { - /* We know len is positive, since open did not fail with ENOENT. */ - size_t len = strlen (filename); - if (filename[len - 1] == '/') - { - struct stat statbuf; - - if (fstat (fd, &statbuf) >= 0 && !S_ISDIR (statbuf.st_mode)) - { - close (fd); - errno = ENOTDIR; - return -1; - } - } - } -#endif - -#if REPLACE_FCHDIR - if (!REPLACE_OPEN_DIRECTORY && 0 <= fd) - fd = _gl_register_fd (fd, filename); -#endif - - return fd; -} diff --git a/gl/tests/pathmax.h b/gl/tests/pathmax.h deleted file mode 100644 index 33fc3553d7..0000000000 --- a/gl/tests/pathmax.h +++ /dev/null @@ -1,83 +0,0 @@ -/* Define PATH_MAX somehow. Requires sys/types.h. - Copyright (C) 1992, 1999, 2001, 2003, 2005, 2009-2014 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, 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 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 _PATHMAX_H -# define _PATHMAX_H - -/* POSIX:2008 defines PATH_MAX to be the maximum number of bytes in a filename, - including the terminating NUL byte. - <http://pubs.opengroup.org/onlinepubs/9699919799/basedefs/limits.h.html> - PATH_MAX is not defined on systems which have no limit on filename length, - such as GNU/Hurd. - - This file does *not* define PATH_MAX always. Programs that use this file - can handle the GNU/Hurd case in several ways: - - Either with a package-wide handling, or with a per-file handling, - - Either through a - #ifdef PATH_MAX - or through a fallback like - #ifndef PATH_MAX - # define PATH_MAX 8192 - #endif - or through a fallback like - #ifndef PATH_MAX - # define PATH_MAX pathconf ("/", _PC_PATH_MAX) - #endif - */ - -# include <unistd.h> - -# include <limits.h> - -# ifndef _POSIX_PATH_MAX -# define _POSIX_PATH_MAX 256 -# endif - -/* Don't include sys/param.h if it already has been. */ -# if defined HAVE_SYS_PARAM_H && !defined PATH_MAX && !defined MAXPATHLEN -# include <sys/param.h> -# endif - -# if !defined PATH_MAX && defined MAXPATHLEN -# define PATH_MAX MAXPATHLEN -# endif - -# ifdef __hpux -/* On HP-UX, PATH_MAX designates the maximum number of bytes in a filename, - *not* including the terminating NUL byte, and is set to 1023. - Additionally, when _XOPEN_SOURCE is defined to 500 or more, PATH_MAX is - not defined at all any more. */ -# undef PATH_MAX -# define PATH_MAX 1024 -# endif - -# if (defined _WIN32 || defined __WIN32__) && ! defined __CYGWIN__ -/* The page "Naming Files, Paths, and Namespaces" on msdn.microsoft.com, - section "Maximum Path Length Limitation", - <http://msdn.microsoft.com/en-us/library/aa365247(v=vs.85).aspx#maxpath> - explains that the maximum size of a filename, including the terminating - NUL byte, is 260 = 3 + 256 + 1. - This is the same value as - - FILENAME_MAX in <stdio.h>, - - _MAX_PATH in <stdlib.h>, - - MAX_PATH in <windef.h>. - Undefine the original value, because mingw's <limits.h> gets it wrong. */ -# undef PATH_MAX -# define PATH_MAX 260 -# endif - -#endif /* _PATHMAX_H */ diff --git a/gl/tests/perror.c b/gl/tests/perror.c deleted file mode 100644 index c0548c936a..0000000000 --- a/gl/tests/perror.c +++ /dev/null @@ -1,49 +0,0 @@ -/* Print a message describing error code. - Copyright (C) 2008-2014 Free Software Foundation, Inc. - Written by Bruno Haible and Simon Josefsson. - - 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 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 <stdio.h> - -#include <errno.h> -#include <stdlib.h> -#include <string.h> - -#include "strerror-override.h" - -/* Use the system functions, not the gnulib overrides in this file. */ -#undef fprintf - -void -perror (const char *string) -{ - char stackbuf[STACKBUF_LEN]; - int ret; - - /* Our implementation guarantees that this will be a non-empty - string, even if it returns EINVAL; and stackbuf should be sized - large enough to avoid ERANGE. */ - ret = strerror_r (errno, stackbuf, sizeof stackbuf); - if (ret == ERANGE) - abort (); - - if (string != NULL && *string != '\0') - fprintf (stderr, "%s: %s\n", string, stackbuf); - else - fprintf (stderr, "%s\n", stackbuf); -} diff --git a/gl/tests/pipe.c b/gl/tests/pipe.c deleted file mode 100644 index 4db9041c49..0000000000 --- a/gl/tests/pipe.c +++ /dev/null @@ -1,50 +0,0 @@ -/* Create a pipe. - Copyright (C) 2009-2014 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, 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 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 <unistd.h> - -#if (defined _WIN32 || defined __WIN32__) && ! defined __CYGWIN__ -/* Native Windows API. */ - -/* Get _pipe(). */ -# include <io.h> - -/* Get _O_BINARY. */ -# include <fcntl.h> - -int -pipe (int fd[2]) -{ - /* Mingw changes fd to {-1,-1} on failure, but this violates - http://austingroupbugs.net/view.php?id=467 */ - int tmp[2]; - int result = _pipe (tmp, 4096, _O_BINARY); - if (!result) - { - fd[0] = tmp[0]; - fd[1] = tmp[1]; - } - return result; -} - -#else - -# error "This platform lacks a pipe function, and Gnulib doesn't provide a replacement. This is a bug in Gnulib." - -#endif diff --git a/gl/tests/same-inode.h b/gl/tests/same-inode.h deleted file mode 100644 index 584f606500..0000000000 --- a/gl/tests/same-inode.h +++ /dev/null @@ -1,33 +0,0 @@ -/* Determine whether two stat buffers refer to the same file. - - Copyright (C) 2006, 2009-2014 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 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 SAME_INODE_H -# define SAME_INODE_H 1 - -# ifdef __VMS -# define SAME_INODE(a, b) \ - ((a).st_ino[0] == (b).st_ino[0] \ - && (a).st_ino[1] == (b).st_ino[1] \ - && (a).st_ino[2] == (b).st_ino[2] \ - && (a).st_dev == (b).st_dev) -# else -# define SAME_INODE(a, b) \ - ((a).st_ino == (b).st_ino \ - && (a).st_dev == (b).st_dev) -# endif - -#endif diff --git a/gl/tests/stat.c b/gl/tests/stat.c deleted file mode 100644 index 35f4b0b1a5..0000000000 --- a/gl/tests/stat.c +++ /dev/null @@ -1,138 +0,0 @@ -/* Work around platform bugs in stat. - Copyright (C) 2009-2014 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 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/>. */ - -/* written by Eric Blake */ - -/* If the user's config.h happens to include <sys/stat.h>, let it include only - the system's <sys/stat.h> here, so that orig_stat doesn't recurse to - rpl_stat. */ -#define __need_system_sys_stat_h -#include <config.h> - -/* Get the original definition of stat. It might be defined as a macro. */ -#include <sys/types.h> -#include <sys/stat.h> -#undef __need_system_sys_stat_h - -#if (defined _WIN32 || defined __WIN32__) && ! defined __CYGWIN__ -# if _GL_WINDOWS_64_BIT_ST_SIZE -# undef stat /* avoid warning on mingw64 with _FILE_OFFSET_BITS=64 */ -# define stat _stati64 -# define REPLACE_FUNC_STAT_DIR 1 -# undef REPLACE_FUNC_STAT_FILE -# elif REPLACE_FUNC_STAT_FILE -/* mingw64 has a broken stat() function, based on _stat(), in libmingwex.a. - Bypass it. */ -# define stat _stat -# define REPLACE_FUNC_STAT_DIR 1 -# undef REPLACE_FUNC_STAT_FILE -# endif -#endif - -static int -orig_stat (const char *filename, struct stat *buf) -{ - return stat (filename, buf); -} - -/* Specification. */ -/* Write "sys/stat.h" here, not <sys/stat.h>, otherwise OSF/1 5.1 DTK cc - eliminates this include because of the preliminary #include <sys/stat.h> - above. */ -#include "sys/stat.h" - -#include <errno.h> -#include <limits.h> -#include <stdbool.h> -#include <string.h> -#include "dosname.h" -#include "verify.h" - -#if REPLACE_FUNC_STAT_DIR -# include "pathmax.h" - /* The only known systems where REPLACE_FUNC_STAT_DIR is needed also - have a constant PATH_MAX. */ -# ifndef PATH_MAX -# error "Please port this replacement to your platform" -# endif -#endif - -/* Store information about NAME into ST. Work around bugs with - trailing slashes. Mingw has other bugs (such as st_ino always - being 0 on success) which this wrapper does not work around. But - at least this implementation provides the ability to emulate fchdir - correctly. */ - -int -rpl_stat (char const *name, struct stat *st) -{ - int result = orig_stat (name, st); -#if REPLACE_FUNC_STAT_FILE - /* Solaris 9 mistakenly succeeds when given a non-directory with a - trailing slash. */ - if (result == 0 && !S_ISDIR (st->st_mode)) - { - size_t len = strlen (name); - if (ISSLASH (name[len - 1])) - { - errno = ENOTDIR; - return -1; - } - } -#endif /* REPLACE_FUNC_STAT_FILE */ -#if REPLACE_FUNC_STAT_DIR - - if (result == -1 && errno == ENOENT) - { - /* Due to mingw's oddities, there are some directories (like - c:\) where stat() only succeeds with a trailing slash, and - other directories (like c:\windows) where stat() only - succeeds without a trailing slash. But we want the two to be - synonymous, since chdir() manages either style. Likewise, Mingw also - reports ENOENT for names longer than PATH_MAX, when we want - ENAMETOOLONG, and for stat("file/"), when we want ENOTDIR. - Fortunately, mingw PATH_MAX is small enough for stack - allocation. */ - char fixed_name[PATH_MAX + 1] = {0}; - size_t len = strlen (name); - bool check_dir = false; - verify (PATH_MAX <= 4096); - if (PATH_MAX <= len) - errno = ENAMETOOLONG; - else if (len) - { - strcpy (fixed_name, name); - if (ISSLASH (fixed_name[len - 1])) - { - check_dir = true; - while (len && ISSLASH (fixed_name[len - 1])) - fixed_name[--len] = '\0'; - if (!len) - fixed_name[0] = '/'; - } - else - fixed_name[len++] = '/'; - result = orig_stat (fixed_name, st); - if (result == 0 && check_dir && !S_ISDIR (st->st_mode)) - { - result = -1; - errno = ENOTDIR; - } - } - } -#endif /* REPLACE_FUNC_STAT_DIR */ - return result; -} diff --git a/gl/tests/strerror_r.c b/gl/tests/strerror_r.c deleted file mode 100644 index 4aa96cbbcf..0000000000 --- a/gl/tests/strerror_r.c +++ /dev/null @@ -1,326 +0,0 @@ -/* strerror_r.c --- POSIX compatible system error routine - - Copyright (C) 2010-2014 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 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/>. */ - -/* Written by Bruno Haible <bruno@clisp.org>, 2010. */ - -#include <config.h> - -/* Enable declaration of sys_nerr and sys_errlist in <errno.h> on NetBSD. */ -#define _NETBSD_SOURCE 1 - -/* Specification. */ -#include <string.h> - -#include <errno.h> -#include <stdio.h> -#include <stdlib.h> - -#include "strerror-override.h" - -#if (__GLIBC__ >= 2 || defined __UCLIBC__ || defined __CYGWIN__) && HAVE___XPG_STRERROR_R /* glibc >= 2.3.4, cygwin >= 1.7.9 */ - -# define USE_XPG_STRERROR_R 1 -extern int __xpg_strerror_r (int errnum, char *buf, size_t buflen); - -#elif HAVE_DECL_STRERROR_R && !(__GLIBC__ >= 2 || defined __UCLIBC__ || defined __CYGWIN__) - -/* The system's strerror_r function is OK, except that its third argument - is 'int', not 'size_t', or its return type is wrong. */ - -# include <limits.h> - -# define USE_SYSTEM_STRERROR_R 1 - -#else /* (__GLIBC__ >= 2 || defined __UCLIBC__ || defined __CYGWIN__ ? !HAVE___XPG_STRERROR_R : !HAVE_DECL_STRERROR_R) */ - -/* Use the system's strerror(). Exclude glibc and cygwin because the - system strerror_r has the wrong return type, and cygwin 1.7.9 - strerror_r clobbers strerror. */ -# undef strerror - -# define USE_SYSTEM_STRERROR 1 - -# if defined __NetBSD__ || defined __hpux || ((defined _WIN32 || defined __WIN32__) && !defined __CYGWIN__) || defined __sgi || (defined __sun && !defined _LP64) || defined __CYGWIN__ - -/* No locking needed. */ - -/* Get catgets internationalization functions. */ -# if HAVE_CATGETS -# include <nl_types.h> -# endif - -/* Get sys_nerr, sys_errlist on HP-UX (otherwise only declared in C++ mode). - Get sys_nerr, sys_errlist on IRIX (otherwise only declared with _SGIAPI). */ -# if defined __hpux || defined __sgi -extern int sys_nerr; -extern char *sys_errlist[]; -# endif - -/* Get sys_nerr on Solaris. */ -# if defined __sun && !defined _LP64 -extern int sys_nerr; -# endif - -# else - -# include "glthread/lock.h" - -/* This lock protects the buffer returned by strerror(). We assume that - no other uses of strerror() exist in the program. */ -gl_lock_define_initialized(static, strerror_lock) - -# endif - -#endif - -/* On MSVC, there is no snprintf() function, just a _snprintf(). - It is of lower quality, but sufficient for the simple use here. - We only have to make sure to NUL terminate the result (_snprintf - does not NUL terminate, like strncpy). */ -#if !HAVE_SNPRINTF -static int -local_snprintf (char *buf, size_t buflen, const char *format, ...) -{ - va_list args; - int result; - - va_start (args, format); - result = _vsnprintf (buf, buflen, format, args); - va_end (args); - if (buflen > 0 && (result < 0 || result >= buflen)) - buf[buflen - 1] = '\0'; - return result; -} -# define snprintf local_snprintf -#endif - -/* Copy as much of MSG into BUF as possible, without corrupting errno. - Return 0 if MSG fit in BUFLEN, otherwise return ERANGE. */ -static int -safe_copy (char *buf, size_t buflen, const char *msg) -{ - size_t len = strlen (msg); - int ret; - - if (len < buflen) - { - /* Although POSIX allows memcpy() to corrupt errno, we don't - know of any implementation where this is a real problem. */ - memcpy (buf, msg, len + 1); - ret = 0; - } - else - { - memcpy (buf, msg, buflen - 1); - buf[buflen - 1] = '\0'; - ret = ERANGE; - } - return ret; -} - - -int -strerror_r (int errnum, char *buf, size_t buflen) -#undef strerror_r -{ - /* Filter this out now, so that rest of this replacement knows that - there is room for a non-empty message and trailing NUL. */ - if (buflen <= 1) - { - if (buflen) - *buf = '\0'; - return ERANGE; - } - *buf = '\0'; - - /* Check for gnulib overrides. */ - { - char const *msg = strerror_override (errnum); - - if (msg) - return safe_copy (buf, buflen, msg); - } - - { - int ret; - int saved_errno = errno; - -#if USE_XPG_STRERROR_R - - { - ret = __xpg_strerror_r (errnum, buf, buflen); - if (ret < 0) - ret = errno; - if (!*buf) - { - /* glibc 2.13 would not touch buf on err, so we have to fall - back to GNU strerror_r which always returns a thread-safe - untruncated string to (partially) copy into our buf. */ - safe_copy (buf, buflen, strerror_r (errnum, buf, buflen)); - } - } - -#elif USE_SYSTEM_STRERROR_R - - if (buflen > INT_MAX) - buflen = INT_MAX; - -# ifdef __hpux - /* On HP-UX 11.31, strerror_r always fails when buflen < 80; it - also fails to change buf on EINVAL. */ - { - char stackbuf[80]; - - if (buflen < sizeof stackbuf) - { - ret = strerror_r (errnum, stackbuf, sizeof stackbuf); - if (ret == 0) - ret = safe_copy (buf, buflen, stackbuf); - } - else - ret = strerror_r (errnum, buf, buflen); - } -# else - ret = strerror_r (errnum, buf, buflen); - - /* Some old implementations may return (-1, EINVAL) instead of EINVAL. */ - if (ret < 0) - ret = errno; -# endif - -# ifdef _AIX - /* AIX returns 0 rather than ERANGE when truncating strings; try - again until we are sure we got the entire string. */ - if (!ret && strlen (buf) == buflen - 1) - { - char stackbuf[STACKBUF_LEN]; - size_t len; - strerror_r (errnum, stackbuf, sizeof stackbuf); - len = strlen (stackbuf); - /* STACKBUF_LEN should have been large enough. */ - if (len + 1 == sizeof stackbuf) - abort (); - if (buflen <= len) - ret = ERANGE; - } -# else - /* Solaris 10 does not populate buf on ERANGE. OpenBSD 4.7 - truncates early on ERANGE rather than return a partial integer. - We prefer the maximal string. We set buf[0] earlier, and we - know of no implementation that modifies buf to be an - unterminated string, so this strlen should be portable in - practice (rather than pulling in a safer strnlen). */ - if (ret == ERANGE && strlen (buf) < buflen - 1) - { - char stackbuf[STACKBUF_LEN]; - - /* STACKBUF_LEN should have been large enough. */ - if (strerror_r (errnum, stackbuf, sizeof stackbuf) == ERANGE) - abort (); - safe_copy (buf, buflen, stackbuf); - } -# endif - -#else /* USE_SYSTEM_STRERROR */ - - /* Try to do what strerror (errnum) does, but without clobbering the - buffer used by strerror(). */ - -# if defined __NetBSD__ || defined __hpux || ((defined _WIN32 || defined __WIN32__) && !defined __CYGWIN__) || defined __CYGWIN__ /* NetBSD, HP-UX, native Windows, Cygwin */ - - /* NetBSD: sys_nerr, sys_errlist are declared through _NETBSD_SOURCE - and <errno.h> above. - HP-UX: sys_nerr, sys_errlist are declared explicitly above. - native Windows: sys_nerr, sys_errlist are declared in <stdlib.h>. - Cygwin: sys_nerr, sys_errlist are declared in <errno.h>. */ - if (errnum >= 0 && errnum < sys_nerr) - { -# if HAVE_CATGETS && (defined __NetBSD__ || defined __hpux) -# if defined __NetBSD__ - nl_catd catd = catopen ("libc", NL_CAT_LOCALE); - const char *errmsg = - (catd != (nl_catd)-1 - ? catgets (catd, 1, errnum, sys_errlist[errnum]) - : sys_errlist[errnum]); -# endif -# if defined __hpux - nl_catd catd = catopen ("perror", NL_CAT_LOCALE); - const char *errmsg = - (catd != (nl_catd)-1 - ? catgets (catd, 1, 1 + errnum, sys_errlist[errnum]) - : sys_errlist[errnum]); -# endif -# else - const char *errmsg = sys_errlist[errnum]; -# endif - if (errmsg == NULL || *errmsg == '\0') - ret = EINVAL; - else - ret = safe_copy (buf, buflen, errmsg); -# if HAVE_CATGETS && (defined __NetBSD__ || defined __hpux) - if (catd != (nl_catd)-1) - catclose (catd); -# endif - } - else - ret = EINVAL; - -# elif defined __sgi || (defined __sun && !defined _LP64) /* IRIX, Solaris <= 9 32-bit */ - - /* For a valid error number, the system's strerror() function returns - a pointer to a not copied string, not to a buffer. */ - if (errnum >= 0 && errnum < sys_nerr) - { - char *errmsg = strerror (errnum); - - if (errmsg == NULL || *errmsg == '\0') - ret = EINVAL; - else - ret = safe_copy (buf, buflen, errmsg); - } - else - ret = EINVAL; - -# else - - gl_lock_lock (strerror_lock); - - { - char *errmsg = strerror (errnum); - - /* For invalid error numbers, strerror() on - - IRIX 6.5 returns NULL, - - HP-UX 11 returns an empty string. */ - if (errmsg == NULL || *errmsg == '\0') - ret = EINVAL; - else - ret = safe_copy (buf, buflen, errmsg); - } - - gl_lock_unlock (strerror_lock); - -# endif - -#endif - - if (ret == EINVAL && !*buf) - snprintf (buf, buflen, "Unknown error %d", errnum); - - errno = saved_errno; - return ret; - } -} diff --git a/gl/tests/symlink.c b/gl/tests/symlink.c deleted file mode 100644 index 0e3fae255c..0000000000 --- a/gl/tests/symlink.c +++ /dev/null @@ -1,57 +0,0 @@ -/* Stub for symlink(). - Copyright (C) 2009-2014 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 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 <unistd.h> - -#include <errno.h> -#include <string.h> -#include <sys/stat.h> - - -#if HAVE_SYMLINK - -# undef symlink - -/* Create a symlink, but reject trailing slash. */ -int -rpl_symlink (char const *contents, char const *name) -{ - size_t len = strlen (name); - if (len && name[len - 1] == '/') - { - struct stat st; - if (lstat (name, &st) == 0) - errno = EEXIST; - return -1; - } - return symlink (contents, name); -} - -#else /* !HAVE_SYMLINK */ - -/* The system does not support symlinks. */ -int -symlink (char const *contents _GL_UNUSED, - char const *name _GL_UNUSED) -{ - errno = ENOSYS; - return -1; -} - -#endif /* !HAVE_SYMLINK */ diff --git a/gl/tests/sys_ioctl.in.h b/gl/tests/sys_ioctl.in.h deleted file mode 100644 index c13e317245..0000000000 --- a/gl/tests/sys_ioctl.in.h +++ /dev/null @@ -1,78 +0,0 @@ -/* Substitute for and wrapper around <sys/ioctl.h>. - Copyright (C) 2008-2014 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, 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 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 _@GUARD_PREFIX@_SYS_IOCTL_H - -#if __GNUC__ >= 3 -@PRAGMA_SYSTEM_HEADER@ -#endif -@PRAGMA_COLUMNS@ - -/* The include_next requires a split double-inclusion guard. */ -#if @HAVE_SYS_IOCTL_H@ -# @INCLUDE_NEXT@ @NEXT_SYS_IOCTL_H@ -#endif - -#ifndef _@GUARD_PREFIX@_SYS_IOCTL_H -#define _@GUARD_PREFIX@_SYS_IOCTL_H - -/* AIX 5.1 and Solaris 10 declare ioctl() in <unistd.h> and in <stropts.h>, - but not in <sys/ioctl.h>. - But avoid namespace pollution on glibc systems. */ -#ifndef __GLIBC__ -# include <unistd.h> -#endif - -/* The definitions of _GL_FUNCDECL_RPL etc. are copied here. */ - -/* The definition of _GL_WARN_ON_USE is copied here. */ - - -/* Declare overridden functions. */ - -#if @GNULIB_IOCTL@ -# if @REPLACE_IOCTL@ -# if !(defined __cplusplus && defined GNULIB_NAMESPACE) -# undef ioctl -# define ioctl rpl_ioctl -# endif -_GL_FUNCDECL_RPL (ioctl, int, - (int fd, int request, ... /* {void *,char *} arg */)); -_GL_CXXALIAS_RPL (ioctl, int, - (int fd, int request, ... /* {void *,char *} arg */)); -# else -# if @SYS_IOCTL_H_HAVE_WINSOCK2_H@ || 1 -_GL_FUNCDECL_SYS (ioctl, int, - (int fd, int request, ... /* {void *,char *} arg */)); -# endif -_GL_CXXALIAS_SYS (ioctl, int, - (int fd, int request, ... /* {void *,char *} arg */)); -# endif -_GL_CXXALIASWARN (ioctl); -#elif @SYS_IOCTL_H_HAVE_WINSOCK2_H_AND_USE_SOCKETS@ -# undef ioctl -# define ioctl ioctl_used_without_requesting_gnulib_module_ioctl -#elif defined GNULIB_POSIXCHECK -# undef ioctl -# if HAVE_RAW_DECL_IOCTL -_GL_WARN_ON_USE (ioctl, "ioctl does not portably work on sockets - " - "use gnulib module ioctl for portability"); -# endif -#endif - - -#endif /* _@GUARD_PREFIX@_SYS_IOCTL_H */ -#endif /* _@GUARD_PREFIX@_SYS_IOCTL_H */ diff --git a/gl/tests/test-accept.c b/gl/tests/test-accept.c deleted file mode 100644 index 58d796a9ae..0000000000 --- a/gl/tests/test-accept.c +++ /dev/null @@ -1,56 +0,0 @@ -/* Test accepting a connection to a server socket. - Copyright (C) 2011-2014 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 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> - -#include <sys/socket.h> - -#include "signature.h" -SIGNATURE_CHECK (accept, int, (int, struct sockaddr *, socklen_t *)); - -#include <errno.h> -#include <netinet/in.h> -#include <unistd.h> - -#include "sockets.h" -#include "macros.h" - -int -main (void) -{ - (void) gl_sockets_startup (SOCKETS_1_1); - - /* Test behaviour for invalid file descriptors. */ - { - struct sockaddr_in addr; - socklen_t addrlen = sizeof (addr); - - errno = 0; - ASSERT (accept (-1, (struct sockaddr *) &addr, &addrlen) == -1); - ASSERT (errno == EBADF); - } - { - struct sockaddr_in addr; - socklen_t addrlen = sizeof (addr); - - close (99); - errno = 0; - ASSERT (accept (99, (struct sockaddr *) &addr, &addrlen) == -1); - ASSERT (errno == EBADF); - } - - return 0; -} diff --git a/gl/tests/test-close.c b/gl/tests/test-close.c deleted file mode 100644 index 44bce54a66..0000000000 --- a/gl/tests/test-close.c +++ /dev/null @@ -1,45 +0,0 @@ -/* Test closing a file or socket. - Copyright (C) 2011-2014 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 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> - -#include <unistd.h> - -#include "signature.h" -SIGNATURE_CHECK (close, int, (int)); - -#include <errno.h> - -#include "macros.h" - -int -main (void) -{ - /* Test behaviour for invalid file descriptors. */ - { - errno = 0; - ASSERT (close (-1) == -1); - ASSERT (errno == EBADF); - } - { - close (99); - errno = 0; - ASSERT (close (99) == -1); - ASSERT (errno == EBADF); - } - - return 0; -} diff --git a/gl/tests/test-dup2.c b/gl/tests/test-dup2.c deleted file mode 100644 index c7cb9656e9..0000000000 --- a/gl/tests/test-dup2.c +++ /dev/null @@ -1,218 +0,0 @@ -/* Test duplicating file descriptors. - Copyright (C) 2009-2014 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 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/>. */ - -/* Written by Eric Blake <ebb9@byu.net>, 2009. */ - -#include <config.h> - -#include <unistd.h> - -#include "signature.h" -SIGNATURE_CHECK (dup2, int, (int, int)); - -#include <errno.h> -#include <fcntl.h> - -#if HAVE_SYS_RESOURCE_H -# include <sys/resource.h> -#endif - -#include "binary-io.h" - -#if GNULIB_TEST_CLOEXEC -# include "cloexec.h" -#endif - -#if (defined _WIN32 || defined __WIN32__) && ! defined __CYGWIN__ -/* Get declarations of the native Windows API functions. */ -# define WIN32_LEAN_AND_MEAN -# include <windows.h> -/* Get _get_osfhandle. */ -# include "msvc-nothrow.h" -#endif - -#include "macros.h" - -/* Return non-zero if FD is open. */ -static int -is_open (int fd) -{ -#if (defined _WIN32 || defined __WIN32__) && ! defined __CYGWIN__ - /* On native Windows, the initial state of unassigned standard file - descriptors is that they are open but point to an - INVALID_HANDLE_VALUE, and there is no fcntl. */ - return (HANDLE) _get_osfhandle (fd) != INVALID_HANDLE_VALUE; -#else -# ifndef F_GETFL -# error Please port fcntl to your platform -# endif - return 0 <= fcntl (fd, F_GETFL); -#endif -} - -#if GNULIB_TEST_CLOEXEC -/* Return non-zero if FD is open and inheritable across exec/spawn. */ -static int -is_inheritable (int fd) -{ -# if (defined _WIN32 || defined __WIN32__) && ! defined __CYGWIN__ - /* On native Windows, the initial state of unassigned standard file - descriptors is that they are open but point to an - INVALID_HANDLE_VALUE, and there is no fcntl. */ - HANDLE h = (HANDLE) _get_osfhandle (fd); - DWORD flags; - if (h == INVALID_HANDLE_VALUE || GetHandleInformation (h, &flags) == 0) - return 0; - return (flags & HANDLE_FLAG_INHERIT) != 0; -# else -# ifndef F_GETFD -# error Please port fcntl to your platform -# endif - int i = fcntl (fd, F_GETFD); - return 0 <= i && (i & FD_CLOEXEC) == 0; -# endif -} -#endif /* GNULIB_TEST_CLOEXEC */ - -#if !O_BINARY -# define setmode(f,m) zero () -static int zero (void) { return 0; } -#endif - -/* Return non-zero if FD is open in the given MODE, which is either - O_TEXT or O_BINARY. */ -static int -is_mode (int fd, int mode) -{ - int value = setmode (fd, O_BINARY); - setmode (fd, value); - return mode == value; -} - -int -main (void) -{ - const char *file = "test-dup2.tmp"; - char buffer[1]; - int bad_fd = getdtablesize (); - int fd = open (file, O_CREAT | O_TRUNC | O_RDWR, 0600); - - /* Assume std descriptors were provided by invoker. */ - ASSERT (STDERR_FILENO < fd); - ASSERT (is_open (fd)); - /* Ignore any other fd's leaked into this process. */ - close (fd + 1); - close (fd + 2); - ASSERT (!is_open (fd + 1)); - ASSERT (!is_open (fd + 2)); - - /* Assigning to self must be a no-op. */ - ASSERT (dup2 (fd, fd) == fd); - ASSERT (is_open (fd)); - - /* The source must be valid. */ - errno = 0; - ASSERT (dup2 (-1, fd) == -1); - ASSERT (errno == EBADF); - close (99); - errno = 0; - ASSERT (dup2 (99, fd) == -1); - ASSERT (errno == EBADF); - errno = 0; - ASSERT (dup2 (AT_FDCWD, fd) == -1); - ASSERT (errno == EBADF); - ASSERT (is_open (fd)); - - /* If the source is not open, then the destination is unaffected. */ - errno = 0; - ASSERT (dup2 (fd + 1, fd + 1) == -1); - ASSERT (errno == EBADF); - ASSERT (!is_open (fd + 1)); - errno = 0; - ASSERT (dup2 (fd + 1, fd) == -1); - ASSERT (errno == EBADF); - ASSERT (is_open (fd)); - - /* The destination must be valid. */ - errno = 0; - ASSERT (dup2 (fd, -2) == -1); - ASSERT (errno == EBADF); - if (bad_fd > 256) - { - ASSERT (dup2 (fd, 255) == 255); - ASSERT (dup2 (fd, 256) == 256); - ASSERT (close (255) == 0); - ASSERT (close (256) == 0); - } - ASSERT (dup2 (fd, bad_fd - 1) == bad_fd - 1); - ASSERT (close (bad_fd - 1) == 0); - errno = 0; - ASSERT (dup2 (fd, bad_fd) == -1); - ASSERT (errno == EBADF); - - /* Using dup2 can skip fds. */ - ASSERT (dup2 (fd, fd + 2) == fd + 2); - ASSERT (is_open (fd)); - ASSERT (!is_open (fd + 1)); - ASSERT (is_open (fd + 2)); - - /* Verify that dup2 closes the previous occupant of a fd. */ - ASSERT (open ("/dev/null", O_WRONLY, 0600) == fd + 1); - ASSERT (dup2 (fd + 1, fd) == fd); - ASSERT (close (fd + 1) == 0); - ASSERT (write (fd, "1", 1) == 1); - ASSERT (dup2 (fd + 2, fd) == fd); - ASSERT (lseek (fd, 0, SEEK_END) == 0); - ASSERT (write (fd + 2, "2", 1) == 1); - ASSERT (lseek (fd, 0, SEEK_SET) == 0); - ASSERT (read (fd, buffer, 1) == 1); - ASSERT (*buffer == '2'); - -#if GNULIB_TEST_CLOEXEC - /* Any new fd created by dup2 must not be cloexec. */ - ASSERT (close (fd + 2) == 0); - ASSERT (dup_cloexec (fd) == fd + 1); - ASSERT (!is_inheritable (fd + 1)); - ASSERT (dup2 (fd + 1, fd + 1) == fd + 1); - ASSERT (!is_inheritable (fd + 1)); - ASSERT (dup2 (fd + 1, fd + 2) == fd + 2); - ASSERT (!is_inheritable (fd + 1)); - ASSERT (is_inheritable (fd + 2)); - errno = 0; - ASSERT (dup2 (fd + 1, -1) == -1); - ASSERT (errno == EBADF); - ASSERT (!is_inheritable (fd + 1)); -#endif - - /* On systems that distinguish between text and binary mode, dup2 - reuses the mode of the source. */ - setmode (fd, O_BINARY); - ASSERT (is_mode (fd, O_BINARY)); - ASSERT (dup2 (fd, fd + 1) == fd + 1); - ASSERT (is_mode (fd + 1, O_BINARY)); - setmode (fd, O_TEXT); - ASSERT (is_mode (fd, O_TEXT)); - ASSERT (dup2 (fd, fd + 1) == fd + 1); - ASSERT (is_mode (fd + 1, O_TEXT)); - - /* Clean up. */ - ASSERT (close (fd + 2) == 0); - ASSERT (close (fd + 1) == 0); - ASSERT (close (fd) == 0); - ASSERT (unlink (file) == 0); - - return 0; -} diff --git a/gl/tests/test-ftruncate.c b/gl/tests/test-ftruncate.c deleted file mode 100644 index ae15411fff..0000000000 --- a/gl/tests/test-ftruncate.c +++ /dev/null @@ -1,60 +0,0 @@ -/* Test truncating a file. - Copyright (C) 2011-2014 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 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> - -#include <unistd.h> - -#include "signature.h" -SIGNATURE_CHECK (ftruncate, int, (int, off_t)); - -#include <errno.h> -#include <fcntl.h> - -#include "macros.h" - -int -main (int argc, char *argv[]) -{ - const char *filename = argv[1]; - - /* Test behaviour for invalid file descriptors. */ - { - errno = 0; - ASSERT (ftruncate (-1, 0) == -1); - ASSERT (errno == EBADF); - } - { - close (99); - errno = 0; - ASSERT (ftruncate (99, 0) == -1); - ASSERT (errno == EBADF); - } - - /* Test behaviour for read-only file descriptors. */ - { - int fd = open (filename, O_RDONLY); - ASSERT (fd >= 0); - errno = 0; - ASSERT (ftruncate (fd, 0) == -1); - ASSERT (errno == EBADF || errno == EINVAL - || errno == EACCES /* seen on mingw */ - ); - close (fd); - } - - return 0; -} diff --git a/gl/tests/test-ftruncate.sh b/gl/tests/test-ftruncate.sh deleted file mode 100755 index d7394d2bfe..0000000000 --- a/gl/tests/test-ftruncate.sh +++ /dev/null @@ -1,3 +0,0 @@ -#!/bin/sh - -exec ./test-ftruncate${EXEEXT} "$srcdir/test-ftruncate.sh" diff --git a/gl/tests/test-getaddrinfo.c b/gl/tests/test-getaddrinfo.c deleted file mode 100644 index acf9cd66cc..0000000000 --- a/gl/tests/test-getaddrinfo.c +++ /dev/null @@ -1,169 +0,0 @@ -/* Test the getaddrinfo module. - - Copyright (C) 2006-2014 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 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/>. */ - -/* Written by Simon Josefsson. */ - -#include <config.h> - -#include <netdb.h> - -#include "signature.h" -SIGNATURE_CHECK (freeaddrinfo, void, (struct addrinfo *)); -SIGNATURE_CHECK (gai_strerror, char const *, (int)); -SIGNATURE_CHECK (getaddrinfo, int, (char const *, char const *, - struct addrinfo const *, - struct addrinfo **)); - -#include <arpa/inet.h> -#include <errno.h> -#include <netinet/in.h> -#include <stdio.h> -#include <string.h> - -/* Whether to print debugging messages. */ -#define ENABLE_DEBUGGING 0 - -#if ENABLE_DEBUGGING -# define dbgprintf printf -#else -# define dbgprintf if (0) printf -#endif - -/* BeOS does not have AF_UNSPEC. */ -#ifndef AF_UNSPEC -# define AF_UNSPEC 0 -#endif - -#ifndef EAI_SERVICE -# define EAI_SERVICE 0 -#endif - -static int -simple (char const *host, char const *service) -{ - char buf[BUFSIZ]; - static int skip = 0; - struct addrinfo hints; - struct addrinfo *ai0, *ai; - int res; - int err; - - /* Once we skipped the test, do not try anything else */ - if (skip) - return 0; - - dbgprintf ("Finding %s service %s...\n", host, service); - - /* This initializes "hints" but does not use it. Is there a reason - for this? If so, please fix this comment. */ - memset (&hints, 0, sizeof (hints)); - hints.ai_flags = AI_CANONNAME; - hints.ai_family = AF_UNSPEC; - hints.ai_socktype = SOCK_STREAM; - - res = getaddrinfo (host, service, 0, &ai0); - err = errno; - - dbgprintf ("res %d: %s\n", res, gai_strerror (res)); - - if (res != 0) - { - /* EAI_AGAIN is returned if no network is available. Don't fail - the test merely because someone is down the country on their - in-law's farm. */ - if (res == EAI_AGAIN) - { - skip++; - fprintf (stderr, "skipping getaddrinfo test: no network?\n"); - return 77; - } - /* IRIX reports EAI_NONAME for "https". Don't fail the test - merely because of this. */ - if (res == EAI_NONAME) - return 0; - /* Solaris reports EAI_SERVICE for "http" and "https". Don't - fail the test merely because of this. */ - if (res == EAI_SERVICE) - return 0; -#ifdef EAI_NODATA - /* AIX reports EAI_NODATA for "https". Don't fail the test - merely because of this. */ - if (res == EAI_NODATA) - return 0; -#endif - /* Provide details if errno was set. */ - if (res == EAI_SYSTEM) - fprintf (stderr, "system error: %s\n", strerror (err)); - - return 1; - } - - for (ai = ai0; ai; ai = ai->ai_next) - { - void *ai_addr = ai->ai_addr; - struct sockaddr_in *sock_addr = ai_addr; - dbgprintf ("\tflags %x\n", ai->ai_flags); - dbgprintf ("\tfamily %x\n", ai->ai_family); - dbgprintf ("\tsocktype %x\n", ai->ai_socktype); - dbgprintf ("\tprotocol %x\n", ai->ai_protocol); - dbgprintf ("\taddrlen %ld: ", (unsigned long) ai->ai_addrlen); - dbgprintf ("\tFound %s\n", - inet_ntop (ai->ai_family, - &sock_addr->sin_addr, - buf, sizeof (buf) - 1)); - if (ai->ai_canonname) - dbgprintf ("\tFound %s...\n", ai->ai_canonname); - - { - char ipbuf[BUFSIZ]; - char portbuf[BUFSIZ]; - - res = getnameinfo (ai->ai_addr, ai->ai_addrlen, - ipbuf, sizeof (ipbuf) - 1, - portbuf, sizeof (portbuf) - 1, - NI_NUMERICHOST|NI_NUMERICSERV); - dbgprintf ("\t\tgetnameinfo %d: %s\n", res, gai_strerror (res)); - if (res == 0) - { - dbgprintf ("\t\tip %s\n", ipbuf); - dbgprintf ("\t\tport %s\n", portbuf); - } - } - - } - - freeaddrinfo (ai0); - - return 0; -} - -#define HOST1 "www.gnu.org" -#define SERV1 "http" -#define HOST2 "www.ibm.com" -#define SERV2 "https" -#define HOST3 "microsoft.com" -#define SERV3 "http" -#define HOST4 "google.org" -#define SERV4 "ldap" - -int main (void) -{ - return simple (HOST1, SERV1) - + simple (HOST2, SERV2) - + simple (HOST3, SERV3) - + simple (HOST4, SERV4); -} diff --git a/gl/tests/test-getcwd-lgpl.c b/gl/tests/test-getcwd-lgpl.c deleted file mode 100644 index 371c8df6ba..0000000000 --- a/gl/tests/test-getcwd-lgpl.c +++ /dev/null @@ -1,102 +0,0 @@ -/* Test of getcwd() function. - Copyright (C) 2009-2014 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 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> - -#include <unistd.h> - -#include "signature.h" -SIGNATURE_CHECK (getcwd, char *, (char *, size_t)); - -#include <errno.h> -#include <stdio.h> -#include <stdlib.h> -#include <string.h> - -#include "macros.h" - -int -main (int argc, char **argv) -{ - char *pwd1; - char *pwd2; - /* If the user provides an argument, attempt to chdir there first. */ - if (1 < argc) - { - if (chdir (argv[1]) == 0) - printf ("changed to directory %s\n", argv[1]); - } - - pwd1 = getcwd (NULL, 0); - ASSERT (pwd1 && *pwd1); - if (1 < argc) - printf ("cwd=%s\n", pwd1); - - /* Make sure the result is usable. */ - ASSERT (chdir (pwd1) == 0); - ASSERT (chdir (".//./.") == 0); - - /* Make sure that result is normalized. */ - pwd2 = getcwd (NULL, 0); - ASSERT (pwd2); - ASSERT (strcmp (pwd1, pwd2) == 0); - free (pwd2); - { - size_t len = strlen (pwd1); - ssize_t i = len - 10; - if (i < 1) - i = 1; - pwd2 = getcwd (NULL, len + 1); - ASSERT (pwd2); - free (pwd2); - pwd2 = malloc (len + 2); - for ( ; i <= len; i++) - { - char *tmp; - errno = 0; - ASSERT (getcwd (pwd2, i) == NULL); - ASSERT (errno == ERANGE); - /* Allow either glibc or BSD behavior, since POSIX allows both. */ - errno = 0; - tmp = getcwd (NULL, i); - if (tmp) - { - ASSERT (strcmp (pwd1, tmp) == 0); - free (tmp); - } - else - { - ASSERT (errno == ERANGE); - } - } - ASSERT (getcwd (pwd2, len + 1) == pwd2); - pwd2[len] = '/'; - pwd2[len + 1] = '\0'; - } - ASSERT (strstr (pwd2, "/./") == NULL); - ASSERT (strstr (pwd2, "/../") == NULL); - ASSERT (strstr (pwd2 + 1 + (pwd2[1] == '/'), "//") == NULL); - - /* Validate a POSIX requirement on size. */ - errno = 0; - ASSERT (getcwd(pwd2, 0) == NULL); - ASSERT (errno == EINVAL); - - free (pwd1); - free (pwd2); - - return 0; -} diff --git a/gl/tests/test-getdtablesize.c b/gl/tests/test-getdtablesize.c deleted file mode 100644 index 86a0b4f040..0000000000 --- a/gl/tests/test-getdtablesize.c +++ /dev/null @@ -1,36 +0,0 @@ -/* Test of getdtablesize() function. - Copyright (C) 2008-2014 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 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/>. */ - -/* Written by Bruno Haible <bruno@clisp.org>, 2008. */ - -#include <config.h> - -#include <unistd.h> - -#include "signature.h" -SIGNATURE_CHECK (getdtablesize, int, (void)); - -#include "macros.h" - -int -main (int argc, char *argv[]) -{ - ASSERT (getdtablesize () >= 3); - ASSERT (dup2 (0, getdtablesize() - 1) == getdtablesize () - 1); - ASSERT (dup2 (0, getdtablesize()) == -1); - - return 0; -} diff --git a/gl/tests/test-getpeername.c b/gl/tests/test-getpeername.c deleted file mode 100644 index 96e8fa6a76..0000000000 --- a/gl/tests/test-getpeername.c +++ /dev/null @@ -1,56 +0,0 @@ -/* Test getpeername() function. - Copyright (C) 2011-2014 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 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> - -#include <sys/socket.h> - -#include "signature.h" -SIGNATURE_CHECK (getpeername, int, (int, struct sockaddr *, socklen_t *)); - -#include <errno.h> -#include <netinet/in.h> -#include <unistd.h> - -#include "sockets.h" -#include "macros.h" - -int -main (void) -{ - (void) gl_sockets_startup (SOCKETS_1_1); - - /* Test behaviour for invalid file descriptors. */ - { - struct sockaddr_in addr; - socklen_t addrlen = sizeof (addr); - - errno = 0; - ASSERT (getpeername (-1, (struct sockaddr *) &addr, &addrlen) == -1); - ASSERT (errno == EBADF); - } - { - struct sockaddr_in addr; - socklen_t addrlen = sizeof (addr); - - close (99); - errno = 0; - ASSERT (getpeername (99, (struct sockaddr *) &addr, &addrlen) == -1); - ASSERT (errno == EBADF); - } - - return 0; -} diff --git a/gl/tests/test-ignore-value.c b/gl/tests/test-ignore-value.c deleted file mode 100644 index 3533d7ca9e..0000000000 --- a/gl/tests/test-ignore-value.c +++ /dev/null @@ -1,84 +0,0 @@ -/* Test the "ignore-value" module. - - Copyright (C) 2011-2014 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 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/>. */ - -/* Written by Eric Blake. */ - -#include <config.h> - -#include "ignore-value.h" - -#include <stdio.h> - -#ifndef _GL_ATTRIBUTE_RETURN_CHECK -# if __GNUC__ < 3 || (__GNUC__ == 3 && __GNUC_MINOR__ < 4) -# define _GL_ATTRIBUTE_RETURN_CHECK -# else -# define _GL_ATTRIBUTE_RETURN_CHECK __attribute__((__warn_unused_result__)) -# endif -#endif - -struct s { int i; }; -static char doChar (void) _GL_ATTRIBUTE_RETURN_CHECK; -static int doInt (void) _GL_ATTRIBUTE_RETURN_CHECK; -static off_t doOff (void) _GL_ATTRIBUTE_RETURN_CHECK; -static void *doPtr (void) _GL_ATTRIBUTE_RETURN_CHECK; -static struct s doStruct (void) _GL_ATTRIBUTE_RETURN_CHECK; - -static char -doChar (void) -{ - return 0; -} - -static int -doInt (void) -{ - return 0; -} - -static off_t -doOff (void) -{ - return 0; -} - -static void * -doPtr (void) -{ - return NULL; -} - -static struct s -doStruct (void) -{ - static struct s s1; - return s1; -} - -int -main (void) -{ - /* If this test can compile with -Werror and the same warnings as - the rest of the project, then we are properly silencing warnings - about ignored return values. */ - ignore_value (doChar ()); - ignore_value (doInt ()); - ignore_value (doOff ()); - ignore_value (doPtr ()); - ignore_value (doStruct ()); - return 0; -} diff --git a/gl/tests/test-inet_ntop.c b/gl/tests/test-inet_ntop.c deleted file mode 100644 index eca86e7240..0000000000 --- a/gl/tests/test-inet_ntop.c +++ /dev/null @@ -1,56 +0,0 @@ -/* Test of inet_ntop function. - Copyright (C) 2009-2014 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 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/>. */ - -/* Written by Bruno Haible <bruno@clisp.org>, 2009. */ - -#include <config.h> - -#include <arpa/inet.h> - -#include "signature.h" -SIGNATURE_CHECK (inet_ntop, char const *, (int, void const *, char *, - socklen_t)); - -#include <netinet/in.h> -#include <sys/socket.h> -#include <string.h> - -#include "macros.h" - -int -main (void) -{ -#if defined AF_INET /* HAVE_IPV4 */ - { - struct in_addr internal; - char printable[16]; - const char *result; - - /* This machine was for a long time known as - ma2s2.mathematik.uni-karlsruhe.de. */ -# ifdef WORDS_BIGENDIAN - internal.s_addr = 0x810D7302; -# else - internal.s_addr = 0x02730D81; -# endif - result = inet_ntop (AF_INET, &internal, printable, sizeof (printable)); - ASSERT (result != NULL); - ASSERT (strcmp (result, "129.13.115.2") == 0); - } -#endif - - return 0; -} diff --git a/gl/tests/test-ioctl.c b/gl/tests/test-ioctl.c deleted file mode 100644 index 8f31b68cc8..0000000000 --- a/gl/tests/test-ioctl.c +++ /dev/null @@ -1,51 +0,0 @@ -/* Test of ioctl() function. - Copyright (C) 2011-2014 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 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 <sys/ioctl.h> - -#include "signature.h" -SIGNATURE_CHECK (ioctl, int, (int, int, ...)); - -#include <errno.h> -#include <unistd.h> - -#include "macros.h" - -int -main (void) -{ -#ifdef FIONREAD - /* Test behaviour for invalid file descriptors. */ - { - int value; - errno = 0; - ASSERT (ioctl (-1, FIONREAD, &value) == -1); - ASSERT (errno == EBADF); - } - { - int value; - close (99); - errno = 0; - ASSERT (ioctl (99, FIONREAD, &value) == -1); - ASSERT (errno == EBADF); - } -#endif - - return 0; -} diff --git a/gl/tests/test-listen.c b/gl/tests/test-listen.c deleted file mode 100644 index f2e6c06a66..0000000000 --- a/gl/tests/test-listen.c +++ /dev/null @@ -1,49 +0,0 @@ -/* Test listen() function. - Copyright (C) 2011-2014 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 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> - -#include <sys/socket.h> - -#include "signature.h" -SIGNATURE_CHECK (listen, int, (int, int)); - -#include <errno.h> -#include <unistd.h> - -#include "sockets.h" -#include "macros.h" - -int -main (void) -{ - (void) gl_sockets_startup (SOCKETS_1_1); - - /* Test behaviour for invalid file descriptors. */ - { - errno = 0; - ASSERT (listen (-1, 1) == -1); - ASSERT (errno == EBADF); - } - { - close (99); - errno = 0; - ASSERT (listen (99 ,1) == -1); - ASSERT (errno == EBADF); - } - - return 0; -} diff --git a/gl/tests/test-lstat.c b/gl/tests/test-lstat.c deleted file mode 100644 index eab2ad4d75..0000000000 --- a/gl/tests/test-lstat.c +++ /dev/null @@ -1,60 +0,0 @@ -/* Test of lstat() function. - Copyright (C) 2008-2014 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 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/>. */ - -/* Written by Simon Josefsson, 2008; and Eric Blake, 2009. */ - -#include <config.h> - -#include <sys/stat.h> - -/* Caution: lstat may be a function-like macro. Although this - signature check must pass, it may be the signature of the real (and - broken) lstat rather than rpl_lstat. Most code should not use the - address of lstat. */ -#include "signature.h" -SIGNATURE_CHECK (lstat, int, (char const *, struct stat *)); - -#include <fcntl.h> -#include <errno.h> -#include <stdbool.h> -#include <stdio.h> -#include <stdlib.h> -#include <unistd.h> - -#include "same-inode.h" -#include "ignore-value.h" -#include "macros.h" - -#define BASE "test-lstat.t" - -#include "test-lstat.h" - -/* Wrapper around lstat, which works even if lstat is a function-like - macro, where test_lstat_func(lstat) would do the wrong thing. */ -static int -do_lstat (char const *name, struct stat *st) -{ - return lstat (name, st); -} - -int -main (void) -{ - /* Remove any leftovers from a previous partial run. */ - ignore_value (system ("rm -rf " BASE "*")); - - return test_lstat_func (do_lstat, true); -} diff --git a/gl/tests/test-lstat.h b/gl/tests/test-lstat.h deleted file mode 100644 index 45ca3bfa39..0000000000 --- a/gl/tests/test-lstat.h +++ /dev/null @@ -1,116 +0,0 @@ -/* Test of lstat() function. - Copyright (C) 2008-2014 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 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/>. */ - -/* Written by Simon Josefsson, 2008; and Eric Blake, 2009. */ - -/* This file is designed to test both lstat(n,buf) and - fstatat(AT_FDCWD,n,buf,AT_SYMLINK_NOFOLLOW). FUNC is the function - to test. Assumes that BASE and ASSERT are already defined, and - that appropriate headers are already included. If PRINT, warn - before skipping symlink tests with status 77. */ - -static int -test_lstat_func (int (*func) (char const *, struct stat *), bool print) -{ - struct stat st1; - struct stat st2; - - /* Test for common directories. */ - ASSERT (func (".", &st1) == 0); - ASSERT (func ("./", &st2) == 0); - ASSERT (SAME_INODE (st1, st2)); - ASSERT (S_ISDIR (st1.st_mode)); - ASSERT (S_ISDIR (st2.st_mode)); - ASSERT (func ("/", &st1) == 0); - ASSERT (func ("///", &st2) == 0); - ASSERT (SAME_INODE (st1, st2)); - ASSERT (S_ISDIR (st1.st_mode)); - ASSERT (S_ISDIR (st2.st_mode)); - ASSERT (func ("..", &st1) == 0); - ASSERT (S_ISDIR (st1.st_mode)); - - /* Test for error conditions. */ - errno = 0; - ASSERT (func ("", &st1) == -1); - ASSERT (errno == ENOENT); - errno = 0; - ASSERT (func ("nosuch", &st1) == -1); - ASSERT (errno == ENOENT); - errno = 0; - ASSERT (func ("nosuch/", &st1) == -1); - ASSERT (errno == ENOENT); - - ASSERT (close (creat (BASE "file", 0600)) == 0); - ASSERT (func (BASE "file", &st1) == 0); - ASSERT (S_ISREG (st1.st_mode)); - errno = 0; - ASSERT (func (BASE "file/", &st1) == -1); - ASSERT (errno == ENOTDIR); - - /* Now for some symlink tests, where supported. We set up: - link1 -> directory - link2 -> file - link3 -> dangling - link4 -> loop - then test behavior both with and without trailing slash. - */ - if (symlink (".", BASE "link1") != 0) - { - ASSERT (unlink (BASE "file") == 0); - if (print) - fputs ("skipping test: symlinks not supported on this file system\n", - stderr); - return 77; - } - ASSERT (symlink (BASE "file", BASE "link2") == 0); - ASSERT (symlink (BASE "nosuch", BASE "link3") == 0); - ASSERT (symlink (BASE "link4", BASE "link4") == 0); - - ASSERT (func (BASE "link1", &st1) == 0); - ASSERT (S_ISLNK (st1.st_mode)); - ASSERT (func (BASE "link1/", &st1) == 0); - ASSERT (stat (BASE "link1", &st2) == 0); - ASSERT (S_ISDIR (st1.st_mode)); - ASSERT (S_ISDIR (st2.st_mode)); - ASSERT (SAME_INODE (st1, st2)); - - ASSERT (func (BASE "link2", &st1) == 0); - ASSERT (S_ISLNK (st1.st_mode)); - errno = 0; - ASSERT (func (BASE "link2/", &st1) == -1); - ASSERT (errno == ENOTDIR); - - ASSERT (func (BASE "link3", &st1) == 0); - ASSERT (S_ISLNK (st1.st_mode)); - errno = 0; - ASSERT (func (BASE "link3/", &st1) == -1); - ASSERT (errno == ENOENT); - - ASSERT (func (BASE "link4", &st1) == 0); - ASSERT (S_ISLNK (st1.st_mode)); - errno = 0; - ASSERT (func (BASE "link4/", &st1) == -1); - ASSERT (errno == ELOOP); - - /* Cleanup. */ - ASSERT (unlink (BASE "file") == 0); - ASSERT (unlink (BASE "link1") == 0); - ASSERT (unlink (BASE "link2") == 0); - ASSERT (unlink (BASE "link3") == 0); - ASSERT (unlink (BASE "link4") == 0); - - return 0; -} diff --git a/gl/tests/test-open.c b/gl/tests/test-open.c deleted file mode 100644 index 985d9015c8..0000000000 --- a/gl/tests/test-open.c +++ /dev/null @@ -1,41 +0,0 @@ -/* Test of opening a file descriptor. - Copyright (C) 2007-2014 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 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/>. */ - -/* Written by Bruno Haible <bruno@clisp.org>, 2007. */ - -#include <config.h> - -#include <fcntl.h> - -#include "signature.h" -SIGNATURE_CHECK (open, int, (char const *, int, ...)); - -#include <errno.h> -#include <stdbool.h> -#include <stdio.h> -#include <unistd.h> - -#include "macros.h" - -#define BASE "test-open.t" - -#include "test-open.h" - -int -main (void) -{ - return test_open (open, true); -} diff --git a/gl/tests/test-open.h b/gl/tests/test-open.h deleted file mode 100644 index d7bd5afc49..0000000000 --- a/gl/tests/test-open.h +++ /dev/null @@ -1,102 +0,0 @@ -/* Test of opening a file descriptor. - Copyright (C) 2007-2014 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 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/>. */ - -/* Written by Bruno Haible <bruno@clisp.org>, 2007. */ - -/* Make test_open always inline if we're using Fortify, which defines - __always_inline to do that. Do nothing otherwise. This works - around a glibc bug whereby 'open' cannot be used as a function - pointer when _FORTIFY_SOURCE is positive. */ - -#ifndef __always_inline -#define __always_inline -#endif - -/* This file is designed to test both open(n,buf[,mode]) and - openat(AT_FDCWD,n,buf[,mode]). FUNC is the function to test. - Assumes that BASE and ASSERT are already defined, and that - appropriate headers are already included. If PRINT, warn before - skipping symlink tests with status 77. */ - -static __always_inline int -test_open (int (*func) (char const *, int, ...), bool print) -{ - int fd; - /* Remove anything from prior partial run. */ - unlink (BASE "file"); - - /* Cannot create directory. */ - errno = 0; - ASSERT (func ("nonexist.ent/", O_CREAT | O_RDONLY, 0600) == -1); - ASSERT (errno == ENOTDIR || errno == EISDIR || errno == ENOENT - || errno == EINVAL); - - /* Create a regular file. */ - fd = func (BASE "file", O_CREAT | O_RDONLY, 0600); - ASSERT (0 <= fd); - ASSERT (close (fd) == 0); - - /* Trailing slash handling. */ - errno = 0; - ASSERT (func (BASE "file/", O_RDONLY) == -1); - ASSERT (errno == ENOTDIR || errno == EISDIR || errno == EINVAL); - - /* Directories cannot be opened for writing. */ - errno = 0; - ASSERT (func (".", O_WRONLY) == -1); - ASSERT (errno == EISDIR || errno == EACCES); - - /* /dev/null must exist, and be writable. */ - fd = func ("/dev/null", O_RDONLY); - ASSERT (0 <= fd); - { - char c; - ASSERT (read (fd, &c, 1) == 0); - } - ASSERT (close (fd) == 0); - fd = func ("/dev/null", O_WRONLY); - ASSERT (0 <= fd); - ASSERT (write (fd, "c", 1) == 1); - ASSERT (close (fd) == 0); - - /* Although O_NONBLOCK on regular files can be ignored, it must not - cause a failure. */ - fd = func (BASE "file", O_NONBLOCK | O_RDONLY); - ASSERT (0 <= fd); - ASSERT (close (fd) == 0); - - /* Symlink handling, where supported. */ - if (symlink (BASE "file", BASE "link") != 0) - { - ASSERT (unlink (BASE "file") == 0); - if (print) - fputs ("skipping test: symlinks not supported on this file system\n", - stderr); - return 77; - } - errno = 0; - ASSERT (func (BASE "link/", O_RDONLY) == -1); - ASSERT (errno == ENOTDIR); - fd = func (BASE "link", O_RDONLY); - ASSERT (0 <= fd); - ASSERT (close (fd) == 0); - - /* Cleanup. */ - ASSERT (unlink (BASE "file") == 0); - ASSERT (unlink (BASE "link") == 0); - - return 0; -} diff --git a/gl/tests/test-pathmax.c b/gl/tests/test-pathmax.c deleted file mode 100644 index 8bc7dbcca5..0000000000 --- a/gl/tests/test-pathmax.c +++ /dev/null @@ -1,32 +0,0 @@ -/* Test of "pathmax.h". - Copyright (C) 2011-2014 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 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/>. */ - -/* Written by Bruno Haible <bruno@clisp.org>, 2011. */ - -#include <config.h> - -#include "pathmax.h" - -/* Check that PATH_MAX is a constant if it is defined. */ -#ifdef PATH_MAX -int a = PATH_MAX; -#endif - -int -main (void) -{ - return 0; -} diff --git a/gl/tests/test-perror.c b/gl/tests/test-perror.c deleted file mode 100644 index c003faad58..0000000000 --- a/gl/tests/test-perror.c +++ /dev/null @@ -1,36 +0,0 @@ -/* Test of perror() function. - Copyright (C) 2008-2014 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, 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 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> - -#include <stdio.h> - -#include "signature.h" -SIGNATURE_CHECK (perror, void, (char const *)); - -#include <errno.h> - -int -main (int argc, char **argv) -{ - const char *prefix = (argc > 1 ? argv[1] : NULL); - - errno = EACCES; perror (prefix); - errno = ETIMEDOUT; perror (prefix); - errno = EOVERFLOW; perror (prefix); - - return 0; -} diff --git a/gl/tests/test-perror.sh b/gl/tests/test-perror.sh deleted file mode 100755 index 7274d3223f..0000000000 --- a/gl/tests/test-perror.sh +++ /dev/null @@ -1,24 +0,0 @@ -#!/bin/sh -: ${srcdir=.} -. "$srcdir/init.sh"; path_prepend_ . - -# Test NULL prefix. Result should not contain a number. -test-perror 2>&1 >/dev/null | LC_ALL=C tr -d '\r' > t-perror.tmp -grep '[0-9]' t-perror.tmp > /dev/null \ - && fail_ "result should not contain a number" - -# Test empty prefix. Result should be the same. -test-perror '' 2>&1 >/dev/null | LC_ALL=C tr -d '\r' > t-perror1.tmp -diff t-perror.tmp t-perror1.tmp \ - || fail_ "empty prefix should behave like NULL argument" - -# Test non-empty prefix. -test-perror foo 2>&1 >/dev/null | LC_ALL=C tr -d '\r' > t-perror3.tmp -sed -e 's/^/foo: /' < t-perror.tmp > t-perror2.tmp -diff t-perror2.tmp t-perror3.tmp || fail_ "prefix applied incorrectly" - -# Test exit status. -test-perror >out 2>/dev/null || fail_ "unexpected exit status" -test -s out && fail_ "unexpected output" - -Exit 0 diff --git a/gl/tests/test-perror2.c b/gl/tests/test-perror2.c deleted file mode 100644 index 7e98126481..0000000000 --- a/gl/tests/test-perror2.c +++ /dev/null @@ -1,136 +0,0 @@ -/* Test of perror() function. - Copyright (C) 2011-2014 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, 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 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> - -#include <stdio.h> - -#include <errno.h> -#include <string.h> -#include <unistd.h> - -/* This test intentionally parses stderr. So, we arrange to have fd 10 - (outside the range of interesting fd's during the test) set up to - duplicate the original stderr. */ -#define BACKUP_STDERR_FILENO 10 -#define ASSERT_STREAM myerr -#include "macros.h" - -static FILE *myerr; - -#define BASE "test-perror2" - -int -main (void) -{ - /* We change fd 2 later, so save it in fd 10. */ - if (dup2 (STDERR_FILENO, BACKUP_STDERR_FILENO) != BACKUP_STDERR_FILENO - || (myerr = fdopen (BACKUP_STDERR_FILENO, "w")) == NULL) - return 2; - - ASSERT (freopen (BASE ".tmp", "w+", stderr) == stderr); - - /* Test that perror does not clobber strerror buffer. */ - { - const char *msg1; - const char *msg2; - const char *msg3; - const char *msg4; - char *str1; - char *str2; - char *str3; - char *str4; - - msg1 = strerror (ENOENT); - ASSERT (msg1); - str1 = strdup (msg1); - ASSERT (str1); - - msg2 = strerror (ERANGE); - ASSERT (msg2); - str2 = strdup (msg2); - ASSERT (str2); - - msg3 = strerror (-4); - ASSERT (msg3); - str3 = strdup (msg3); - ASSERT (str3); - - msg4 = strerror (1729576); - ASSERT (msg4); - str4 = strdup (msg4); - ASSERT (str4); - - errno = EACCES; - perror (""); - errno = -5; - perror (""); - ASSERT (!ferror (stderr)); - ASSERT (msg1 == msg2 || msg1 == msg4 || STREQ (msg1, str1)); - ASSERT (msg2 == msg4 || STREQ (msg2, str2)); - ASSERT (msg3 == msg4 || STREQ (msg3, str3)); - ASSERT (STREQ (msg4, str4)); - - free (str1); - free (str2); - free (str3); - free (str4); - } - - /* Test that perror uses the same message as strerror. */ - { - int errs[] = { EACCES, 0, -3, }; - int i; - for (i = 0; i < SIZEOF (errs); i++) - { - char buf[256]; - char *err = strerror (errs[i]); - - ASSERT (err); - ASSERT (strlen (err) < sizeof buf); - rewind (stderr); - ASSERT (ftruncate (fileno (stderr), 0) == 0); - errno = errs[i]; - perror (NULL); - ASSERT (!ferror (stderr)); - rewind (stderr); - ASSERT (fgets (buf, sizeof buf, stderr) == buf); - ASSERT (strstr (buf, err)); - } - } - - /* Test that perror reports write failure. */ - { - ASSERT (freopen (BASE ".tmp", "r", stderr) == stderr); - ASSERT (setvbuf (stderr, NULL, _IONBF, BUFSIZ) == 0); - errno = -1; - ASSERT (!ferror (stderr)); - perror (NULL); -#if 0 - /* Commented out until cygwin behaves: - http://sourceware.org/ml/newlib/2011/msg00228.html */ - ASSERT (errno > 0); - /* Commented out until glibc behaves: - http://sourceware.org/bugzilla/show_bug.cgi?id=12792 */ - ASSERT (ferror (stderr)); -#endif - } - - ASSERT (fclose (stderr) == 0); - ASSERT (remove (BASE ".tmp") == 0); - - return 0; -} diff --git a/gl/tests/test-pipe.c b/gl/tests/test-pipe.c deleted file mode 100644 index c951d1d063..0000000000 --- a/gl/tests/test-pipe.c +++ /dev/null @@ -1,104 +0,0 @@ -/* Test of pipe. - Copyright (C) 2009-2014 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, 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 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> - -#include <unistd.h> - -#include "signature.h" -SIGNATURE_CHECK (pipe, int, (int[2])); - -#include <fcntl.h> -#include <stdbool.h> - -#if (defined _WIN32 || defined __WIN32__) && ! defined __CYGWIN__ -/* Get declarations of the native Windows API functions. */ -# define WIN32_LEAN_AND_MEAN -# include <windows.h> -/* Get _get_osfhandle. */ -# include "msvc-nothrow.h" -#endif - -#include "binary-io.h" -#include "macros.h" - -/* Return true if FD is open. */ -static bool -is_open (int fd) -{ -#if (defined _WIN32 || defined __WIN32__) && ! defined __CYGWIN__ - /* On native Windows, the initial state of unassigned standard file - descriptors is that they are open but point to an - INVALID_HANDLE_VALUE, and there is no fcntl. */ - return (HANDLE) _get_osfhandle (fd) != INVALID_HANDLE_VALUE; -#else -# ifndef F_GETFL -# error Please port fcntl to your platform -# endif - return 0 <= fcntl (fd, F_GETFL); -#endif -} - -/* Return true if FD is not inherited to child processes. */ -static bool -is_cloexec (int fd) -{ -#if (defined _WIN32 || defined __WIN32__) && ! defined __CYGWIN__ - HANDLE h = (HANDLE) _get_osfhandle (fd); - DWORD flags; - ASSERT (GetHandleInformation (h, &flags)); - return (flags & HANDLE_FLAG_INHERIT) == 0; -#else - int flags; - ASSERT ((flags = fcntl (fd, F_GETFD)) >= 0); - return (flags & FD_CLOEXEC) != 0; -#endif -} - -/* Return true if FD is in non-blocking mode. */ -static bool -is_nonblocking (int fd) -{ -#if (defined _WIN32 || defined __WIN32__) && ! defined __CYGWIN__ - /* We don't use the non-blocking mode for sockets here. */ - return 0; -#else - int flags; - ASSERT ((flags = fcntl (fd, F_GETFL)) >= 0); - return (flags & O_NONBLOCK) != 0; -#endif -} - -int -main () -{ - int fd[2]; - - fd[0] = -1; - fd[1] = -1; - ASSERT (pipe (fd) >= 0); - ASSERT (fd[0] >= 0); - ASSERT (fd[1] >= 0); - ASSERT (fd[0] != fd[1]); - ASSERT (is_open (fd[0])); - ASSERT (is_open (fd[1])); - ASSERT (!is_cloexec (fd[0])); - ASSERT (!is_cloexec (fd[1])); - ASSERT (!is_nonblocking (fd[0])); - ASSERT (!is_nonblocking (fd[1])); - - return 0; -} diff --git a/gl/tests/test-recv.c b/gl/tests/test-recv.c deleted file mode 100644 index 114e332046..0000000000 --- a/gl/tests/test-recv.c +++ /dev/null @@ -1,51 +0,0 @@ -/* Test the recv() function. - Copyright (C) 2011-2014 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 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> - -#include <sys/socket.h> - -#include "signature.h" -SIGNATURE_CHECK (recv, ssize_t, (int, void *, size_t, int)); - -#include <errno.h> -#include <unistd.h> - -#include "sockets.h" -#include "macros.h" - -int -main (void) -{ - (void) gl_sockets_startup (SOCKETS_1_1); - - /* Test behaviour for invalid file descriptors. */ - { - char byte; - errno = 0; - ASSERT (recv (-1, &byte, 1, 0) == -1); - ASSERT (errno == EBADF); - } - { - char byte; - close (99); - errno = 0; - ASSERT (recv (99, &byte, 1, 0) == -1); - ASSERT (errno == EBADF); - } - - return 0; -} diff --git a/gl/tests/test-recvfrom.c b/gl/tests/test-recvfrom.c deleted file mode 100644 index d0b8c61847..0000000000 --- a/gl/tests/test-recvfrom.c +++ /dev/null @@ -1,62 +0,0 @@ -/* Test the recvfrom() function. - Copyright (C) 2011-2014 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 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> - -#include <sys/socket.h> - -#include "signature.h" -SIGNATURE_CHECK (recvfrom, ssize_t, - (int, void *, size_t, int, - struct sockaddr *, socklen_t *)); - -#include <errno.h> -#include <netinet/in.h> -#include <unistd.h> - -#include "sockets.h" -#include "macros.h" - -int -main (void) -{ - (void) gl_sockets_startup (SOCKETS_1_1); - - /* Test behaviour for invalid file descriptors. */ - { - char byte; - struct sockaddr_in addr; - socklen_t addrlen = sizeof (addr); - - errno = 0; - ASSERT (recvfrom (-1, &byte, 1, 0, (struct sockaddr *) &addr, &addrlen) - == -1); - ASSERT (errno == EBADF); - } - { - char byte; - struct sockaddr_in addr; - socklen_t addrlen = sizeof (addr); - - close (99); - errno = 0; - ASSERT (recvfrom (99, &byte, 1, 0, (struct sockaddr *) &addr, &addrlen) - == -1); - ASSERT (errno == EBADF); - } - - return 0; -} diff --git a/gl/tests/test-select-fd.c b/gl/tests/test-select-fd.c deleted file mode 100644 index ae9e83cc83..0000000000 --- a/gl/tests/test-select-fd.c +++ /dev/null @@ -1,72 +0,0 @@ -/* Test of select() substitute, reading or writing from a given file descriptor. - Copyright (C) 2008-2014 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 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/>. */ - -/* Written by Bruno Haible <bruno@clisp.org>, 2008. */ - -#include <config.h> - -#include <stdio.h> -#include <stdlib.h> -#include <sys/select.h> - -int -main (int argc, char *argv[]) -{ - if (argc == 4) - { - char mode = argv[1][0]; - - if (mode == 'r' || mode == 'w') - { - int fd = atoi (argv[2]); - - if (fd >= 0) - { - const char *result_file_name = argv[3]; - FILE *result_file = fopen (result_file_name, "wb"); - - if (result_file != NULL) - { - fd_set fds; - struct timeval timeout; - int ret; - - FD_ZERO (&fds); - FD_SET (fd, &fds); - timeout.tv_sec = 0; - timeout.tv_usec = 10000; - ret = (mode == 'r' - ? select (fd + 1, &fds, NULL, NULL, &timeout) - : select (fd + 1, NULL, &fds, NULL, &timeout)); - if (ret < 0) - { - perror ("select failed"); - exit (1); - } - if ((ret == 0) != ! FD_ISSET (fd, &fds)) - { - fprintf (stderr, "incorrect return value\n"); - exit (1); - } - fprintf (result_file, "%d\n", ret); - exit (0); - } - } - } - } - fprintf (stderr, "Usage: test-select-fd mode fd result-file-name\n"); - exit (1); -} diff --git a/gl/tests/test-select-in.sh b/gl/tests/test-select-in.sh deleted file mode 100755 index 2a8b742268..0000000000 --- a/gl/tests/test-select-in.sh +++ /dev/null @@ -1,39 +0,0 @@ -#!/bin/sh -# Test select() on file descriptors opened for reading. - -# This test is known to fail on Solaris 2.6 and older, due to its handling -# of /dev/null. - -tmpfiles="" -trap 'rm -fr $tmpfiles' 1 2 3 15 - -tmpfiles="$tmpfiles t-select-in.tmp" - -# Regular files. - -rm -f t-select-in.tmp -./test-select-fd${EXEEXT} r 0 t-select-in.tmp < ./test-select-fd${EXEEXT} -test `cat t-select-in.tmp` = "1" || exit 1 - -# Pipes. - -rm -f t-select-in.tmp -{ sleep 1; echo abc; } | \ - { ./test-select-fd${EXEEXT} r 0 t-select-in.tmp; cat > /dev/null; } -test `cat t-select-in.tmp` = "0" || exit 1 - -rm -f t-select-in.tmp -echo abc | { sleep 1; ./test-select-fd${EXEEXT} r 0 t-select-in.tmp; } -test `cat t-select-in.tmp` = "1" || exit 1 - -# Special files. -# This part of the test is known to fail on Solaris 2.6 and older. - -# Doesn't work under mingw -- simon@josefsson.org -#rm -f t-select-in.tmp -#./test-select-fd${EXEEXT} r 0 t-select-in.tmp < /dev/null -#test `cat t-select-in.tmp` = "1" || exit 1 - -rm -fr $tmpfiles - -exit 0 diff --git a/gl/tests/test-select-out.sh b/gl/tests/test-select-out.sh deleted file mode 100755 index c5fd8619f6..0000000000 --- a/gl/tests/test-select-out.sh +++ /dev/null @@ -1,35 +0,0 @@ -#!/bin/sh -# Test select() on file descriptors opened for writing. - -tmpfiles="" -trap 'rm -fr $tmpfiles' 1 2 3 15 - -tmpfiles="$tmpfiles t-select-out.out t-select-out.tmp" - -# Regular files. - -rm -f t-select-out.tmp -./test-select-fd${EXEEXT} w 1 t-select-out.tmp > t-select-out.out -test `cat t-select-out.tmp` = "1" || exit 1 - -# Pipes. - -if false; then # This test fails on some platforms. - rm -f t-select-out.tmp - ( { echo abc; ./test-select-fd${EXEEXT} w 1 t-select-out.tmp; } | { sleep 1; cat; } ) > /dev/null - test `cat t-select-out.tmp` = "0" || exit 1 -fi - -rm -f t-select-out.tmp -( { sleep 1; echo abc; ./test-select-fd${EXEEXT} w 1 t-select-out.tmp; } | cat) > /dev/null -test `cat t-select-out.tmp` = "1" || exit 1 - -# Special files. - -rm -f t-select-out.tmp -./test-select-fd${EXEEXT} w 1 t-select-out.tmp > /dev/null -test `cat t-select-out.tmp` = "1" || exit 1 - -rm -fr $tmpfiles - -exit 0 diff --git a/gl/tests/test-select-stdin.c b/gl/tests/test-select-stdin.c deleted file mode 100644 index 8b242a2130..0000000000 --- a/gl/tests/test-select-stdin.c +++ /dev/null @@ -1,83 +0,0 @@ -/* Test of select() substitute, reading from stdin. - Copyright (C) 2008-2014 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 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/>. */ - -/* Written by Bruno Haible <bruno@clisp.org>, 2008. */ - -#include <config.h> - -#include <stdio.h> -#include <stdlib.h> -#include <sys/select.h> -#include <sys/time.h> -#include <unistd.h> - -#include "macros.h" - -int -main (void) -{ - printf ("Applying select() from standard input. Press Ctrl-C to abort.\n"); - for (;;) - { - struct timeval before; - struct timeval after; - unsigned long spent_usec; - fd_set readfds; - struct timeval timeout; - int ret; - - gettimeofday (&before, NULL); - - FD_ZERO (&readfds); - FD_SET (0, &readfds); - timeout.tv_sec = 0; - timeout.tv_usec = 500000; - ret = select (1, &readfds, NULL, NULL, &timeout); - - gettimeofday (&after, NULL); - spent_usec = (after.tv_sec - before.tv_sec) * 1000000 - + after.tv_usec - before.tv_usec; - - if (ret < 0) - { - perror ("select failed"); - exit (1); - } - if ((ret == 0) != ! FD_ISSET (0, &readfds)) - { - fprintf (stderr, "incorrect return value\n"); - exit (1); - } - if (ret == 0) - { - if (spent_usec < 250000) - { - fprintf (stderr, "returned too early\n"); - exit (1); - } - /* Timeout */ - printf ("."); - ASSERT (fflush (stdout) == 0); - } - else - { - char c; - - printf ("Input available! Trying to read 1 byte...\n"); - ASSERT (read (0, &c, 1) == 1); - } - } -} diff --git a/gl/tests/test-select.c b/gl/tests/test-select.c deleted file mode 100644 index ef7389a850..0000000000 --- a/gl/tests/test-select.c +++ /dev/null @@ -1,34 +0,0 @@ -/* Test of select() substitute. - Copyright (C) 2008-2014 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 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/>. */ - -/* Written by Paolo Bonzini, 2008. */ - -#include <config.h> - -#include <sys/select.h> - -#include "signature.h" - -SIGNATURE_CHECK (select, int, (int, fd_set *, fd_set *, fd_set *, - struct timeval *)); - -#include "test-select.h" - -int -main (void) -{ - return test_function (select); -} diff --git a/gl/tests/test-select.h b/gl/tests/test-select.h deleted file mode 100644 index adf1dd4eef..0000000000 --- a/gl/tests/test-select.h +++ /dev/null @@ -1,462 +0,0 @@ -/* Test of select() substitute. - Copyright (C) 2008-2014 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 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/>. */ - -/* Written by Paolo Bonzini, 2008. */ - -#include <stdio.h> -#include <string.h> -#include <netinet/in.h> -#include <arpa/inet.h> -#include <unistd.h> -#include <fcntl.h> -#include <stdlib.h> -#include <stdbool.h> -#include <sys/ioctl.h> -#include <errno.h> - -#include "macros.h" - -#if (defined _WIN32 || defined __WIN32__) && ! defined __CYGWIN__ -# define WINDOWS_NATIVE -#endif - -#ifdef HAVE_SYS_WAIT_H -# include <sys/wait.h> -#endif - -#ifndef SO_REUSEPORT -# define SO_REUSEPORT SO_REUSEADDR -#endif - -#define TEST_PORT 12345 - - -typedef int (*select_fn) (int, fd_set *, fd_set *, fd_set *, struct timeval *); - - -/* Minimal testing infrastructure. */ - -static int failures; - -static void -failed (const char *reason) -{ - if (++failures > 1) - printf (" "); - printf ("failed (%s)\n", reason); -} - -static int -test (void (*fn) (select_fn), select_fn my_select, const char *msg) -{ - failures = 0; - printf ("%s... ", msg); - fflush (stdout); - fn (my_select); - - if (!failures) - printf ("passed\n"); - - return failures; -} - - -/* Funny socket code. */ - -static int -open_server_socket (void) -{ - int s, x; - struct sockaddr_in ia; - - s = socket (AF_INET, SOCK_STREAM, 0); - - x = 1; - setsockopt (s, SOL_SOCKET, SO_REUSEPORT, &x, sizeof (x)); - - memset (&ia, 0, sizeof (ia)); - ia.sin_family = AF_INET; - inet_pton (AF_INET, "127.0.0.1", &ia.sin_addr); - ia.sin_port = htons (TEST_PORT); - if (bind (s, (struct sockaddr *) &ia, sizeof (ia)) < 0) - { - perror ("bind"); - exit (77); - } - - if (listen (s, 1) < 0) - { - perror ("listen"); - exit (77); - } - - return s; -} - -static int -connect_to_socket (bool blocking) -{ - int s; - struct sockaddr_in ia; - - s = socket (AF_INET, SOCK_STREAM, 0); - - memset (&ia, 0, sizeof (ia)); - ia.sin_family = AF_INET; - inet_pton (AF_INET, "127.0.0.1", &ia.sin_addr); - ia.sin_port = htons (TEST_PORT); - - if (!blocking) - { -#ifdef WINDOWS_NATIVE - unsigned long iMode = 1; - ioctl (s, FIONBIO, (char *) &iMode); - -#elif defined F_GETFL - int oldflags = fcntl (s, F_GETFL, NULL); - - if (!(oldflags & O_NONBLOCK)) - fcntl (s, F_SETFL, oldflags | O_NONBLOCK); -#endif - } - - if (connect (s, (struct sockaddr *) &ia, sizeof (ia)) < 0 - && (blocking || errno != EINPROGRESS)) - { - perror ("connect"); - exit (77); - } - - return s; -} - - -/* A slightly more convenient interface to select(2). - Waits until a specific event occurs on a file descriptor FD. - EV is a bit mask of events to look for: - SEL_IN - input can be polled without blocking, - SEL_OUT - output can be provided without blocking, - SEL_EXC - an exception occurred, - A maximum wait time is specified by TIMEOUT. - *TIMEOUT = { 0, 0 } means to return immediately, - TIMEOUT = NULL means to wait indefinitely. */ - -enum { SEL_IN = 1, SEL_OUT = 2, SEL_EXC = 4 }; - -static int -do_select (int fd, int ev, struct timeval *timeout, select_fn my_select) -{ - fd_set rfds, wfds, xfds; - int r, rev; - - FD_ZERO (&rfds); - FD_ZERO (&wfds); - FD_ZERO (&xfds); - if (ev & SEL_IN) - FD_SET (fd, &rfds); - if (ev & SEL_OUT) - FD_SET (fd, &wfds); - if (ev & SEL_EXC) - FD_SET (fd, &xfds); - r = my_select (fd + 1, &rfds, &wfds, &xfds, timeout); - if (r < 0) - return r; - - rev = 0; - if (FD_ISSET (fd, &rfds)) - rev |= SEL_IN; - if (FD_ISSET (fd, &wfds)) - rev |= SEL_OUT; - if (FD_ISSET (fd, &xfds)) - rev |= SEL_EXC; - if (rev && r == 0) - failed ("select returned 0"); - if (rev & ~ev) - failed ("select returned unrequested events"); - - return rev; -} - -static int -do_select_nowait (int fd, int ev, select_fn my_select) -{ - struct timeval tv0; - tv0.tv_sec = 0; - tv0.tv_usec = 0; - return do_select (fd, ev, &tv0, my_select); -} - -static int -do_select_wait (int fd, int ev, select_fn my_select) -{ - return do_select (fd, ev, NULL, my_select); -} - - -/* Test select(2) for TTYs. */ - -#ifdef INTERACTIVE -static void -test_tty (select_fn my_select) -{ - if (do_select_nowait (0, SEL_IN, my_select) != 0) - failed ("can read"); - if (do_select_nowait (0, SEL_OUT, my_select) == 0) - failed ("cannot write"); - - if (do_select_wait (0, SEL_IN, my_select) == 0) - failed ("return with infinite timeout"); - - getchar (); - if (do_select_nowait (0, SEL_IN, my_select) != 0) - failed ("can read after getc"); -} -#endif - - -static int -do_select_bad_nfd_nowait (int nfd, select_fn my_select) -{ - struct timeval tv0; - tv0.tv_sec = 0; - tv0.tv_usec = 0; - errno = 0; - return my_select (nfd, NULL, NULL, NULL, &tv0); -} - -static void -test_bad_nfd (select_fn my_select) -{ - if (do_select_bad_nfd_nowait (-1, my_select) != -1 || errno != EINVAL) - failed ("invalid errno after negative nfds"); - /* Can't test FD_SETSIZE + 1 for EINVAL, since some systems allow - dynamically larger set size by redefining FD_SETSIZE anywhere up - to the actual maximum fd. */ - /* if (do_select_bad_nfd_nowait (FD_SETSIZE + 1, my_select) != -1 */ - /* || errno != EINVAL) */ - /* failed ("invalid errno after bogus nfds"); */ -} - -/* Test select(2) on invalid file descriptors. */ - -static int -do_select_bad_fd (int fd, int ev, struct timeval *timeout, select_fn my_select) -{ - fd_set rfds, wfds, xfds; - - FD_ZERO (&rfds); - FD_ZERO (&wfds); - FD_ZERO (&xfds); - if (ev & SEL_IN) - FD_SET (fd, &rfds); - if (ev & SEL_OUT) - FD_SET (fd, &wfds); - if (ev & SEL_EXC) - FD_SET (fd, &xfds); - errno = 0; - return my_select (fd + 1, &rfds, &wfds, &xfds, timeout); - /* In this case, when fd is invalid, on some platforms, the bit for fd - is left alone in the fd_set, whereas on other platforms it is cleared. - So, don't check the bit for fd here. */ -} - -static int -do_select_bad_fd_nowait (int fd, int ev, select_fn my_select) -{ - struct timeval tv0; - tv0.tv_sec = 0; - tv0.tv_usec = 0; - return do_select_bad_fd (fd, ev, &tv0, my_select); -} - -static void -test_bad_fd (select_fn my_select) -{ - /* This tests fails on OSF/1 and native Windows, even with fd = 16. */ -#if !(defined __osf__ || defined WINDOWS_NATIVE) - int fd; - - /* On Linux, Mac OS X, *BSD, values of fd like 99 or 399 are discarded - by the kernel early and therefore do *not* lead to EBADF, as required - by POSIX. */ -# if defined __linux__ || (defined __APPLE__ && defined __MACH__) || defined __FreeBSD__ || defined __OpenBSD__ || defined __NetBSD__ - fd = 16; -# else - fd = 99; -# endif - close (fd); - - if (do_select_bad_fd_nowait (fd, SEL_IN, my_select) == 0 || errno != EBADF) - failed ("invalid fd among rfds"); - if (do_select_bad_fd_nowait (fd, SEL_OUT, my_select) == 0 || errno != EBADF) - failed ("invalid fd among wfds"); - if (do_select_bad_fd_nowait (fd, SEL_EXC, my_select) == 0 || errno != EBADF) - failed ("invalid fd among xfds"); -#endif -} - - -/* Test select(2) for unconnected nonblocking sockets. */ - -static void -test_connect_first (select_fn my_select) -{ - int s = open_server_socket (); - struct sockaddr_in ia; - socklen_t addrlen; - - int c1, c2; - - if (do_select_nowait (s, SEL_IN | SEL_EXC, my_select) != 0) - failed ("can read, socket not connected"); - - c1 = connect_to_socket (false); - - if (do_select_wait (s, SEL_IN | SEL_EXC, my_select) != SEL_IN) - failed ("expecting readability on passive socket"); - if (do_select_nowait (s, SEL_IN | SEL_EXC, my_select) != SEL_IN) - failed ("expecting readability on passive socket"); - - addrlen = sizeof (ia); - c2 = accept (s, (struct sockaddr *) &ia, &addrlen); - ASSERT (close (s) == 0); - ASSERT (close (c1) == 0); - ASSERT (close (c2) == 0); -} - - -/* Test select(2) for unconnected blocking sockets. */ - -static void -test_accept_first (select_fn my_select) -{ -#ifndef WINDOWS_NATIVE - int s = open_server_socket (); - struct sockaddr_in ia; - socklen_t addrlen; - char buf[3]; - int c, pid; - - pid = fork (); - if (pid < 0) - return; - - if (pid == 0) - { - addrlen = sizeof (ia); - c = accept (s, (struct sockaddr *) &ia, &addrlen); - ASSERT (close (s) == 0); - ASSERT (write (c, "foo", 3) == 3); - ASSERT (read (c, buf, 3) == 3); - shutdown (c, SHUT_RD); - ASSERT (close (c) == 0); - exit (0); - } - else - { - ASSERT (close (s) == 0); - c = connect_to_socket (true); - if (do_select_nowait (c, SEL_OUT, my_select) != SEL_OUT) - failed ("cannot write after blocking connect"); - ASSERT (write (c, "foo", 3) == 3); - wait (&pid); - if (do_select_wait (c, SEL_IN, my_select) != SEL_IN) - failed ("cannot read data left in the socket by closed process"); - ASSERT (read (c, buf, 3) == 3); - ASSERT (write (c, "foo", 3) == 3); - (void) close (c); /* may fail with errno = ECONNRESET */ - } -#endif -} - - -/* Common code for pipes and connected sockets. */ - -static void -test_pair (int rd, int wd, select_fn my_select) -{ - char buf[3]; - if (do_select_wait (wd, SEL_IN | SEL_OUT | SEL_EXC, my_select) != SEL_OUT) - failed ("expecting writability before writing"); - if (do_select_nowait (wd, SEL_IN | SEL_OUT | SEL_EXC, my_select) != SEL_OUT) - failed ("expecting writability before writing"); - - ASSERT (write (wd, "foo", 3) == 3); - if (do_select_wait (rd, SEL_IN, my_select) != SEL_IN) - failed ("expecting readability after writing"); - if (do_select_nowait (rd, SEL_IN, my_select) != SEL_IN) - failed ("expecting readability after writing"); - - ASSERT (read (rd, buf, 3) == 3); -} - - -/* Test select(2) on connected sockets. */ - -static void -test_socket_pair (select_fn my_select) -{ - struct sockaddr_in ia; - - socklen_t addrlen = sizeof (ia); - int s = open_server_socket (); - int c1 = connect_to_socket (false); - int c2 = accept (s, (struct sockaddr *) &ia, &addrlen); - - ASSERT (close (s) == 0); - - test_pair (c1, c2, my_select); - ASSERT (close (c1) == 0); - ASSERT (write (c2, "foo", 3) == 3); - (void) close (c2); /* may fail with errno = ECONNRESET */ -} - - -/* Test select(2) on pipes. */ - -static void -test_pipe (select_fn my_select) -{ - int fd[2]; - - ASSERT (pipe (fd) == 0); - test_pair (fd[0], fd[1], my_select); - ASSERT (close (fd[0]) == 0); - ASSERT (close (fd[1]) == 0); -} - - -/* Do them all. */ - -static int -test_function (select_fn my_select) -{ - int result = 0; - -#ifdef INTERACTIVE - printf ("Please press Enter\n"); - test (test_tty, "TTY", my_select); -#endif - - result += test (test_bad_nfd, my_select, "Invalid nfd test"); - result += test (test_bad_fd, my_select, "Invalid fd test"); - result += test (test_connect_first, my_select, "Unconnected socket test"); - result += test (test_socket_pair, my_select, "Connected sockets test"); - result += test (test_accept_first, my_select, "General socket test with fork"); - result += test (test_pipe, my_select, "Pipe test"); - - return result; -} diff --git a/gl/tests/test-send.c b/gl/tests/test-send.c deleted file mode 100644 index beb46382b1..0000000000 --- a/gl/tests/test-send.c +++ /dev/null @@ -1,51 +0,0 @@ -/* Test the send() function. - Copyright (C) 2011-2014 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 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> - -#include <sys/socket.h> - -#include "signature.h" -SIGNATURE_CHECK (send, ssize_t, (int, const void *, size_t, int)); - -#include <errno.h> -#include <unistd.h> - -#include "sockets.h" -#include "macros.h" - -int -main (void) -{ - (void) gl_sockets_startup (SOCKETS_1_1); - - /* Test behaviour for invalid file descriptors. */ - { - char byte = 'x'; - errno = 0; - ASSERT (send (-1, &byte, 1, 0) == -1); - ASSERT (errno == EBADF); - } - { - char byte = 'x'; - close (99); - errno = 0; - ASSERT (send (99, &byte, 1, 0) == -1); - ASSERT (errno == EBADF); - } - - return 0; -} diff --git a/gl/tests/test-sendto.c b/gl/tests/test-sendto.c deleted file mode 100644 index 8df5d64b6f..0000000000 --- a/gl/tests/test-sendto.c +++ /dev/null @@ -1,66 +0,0 @@ -/* Test the sendto() function. - Copyright (C) 2011-2014 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 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> - -#include <sys/socket.h> - -#include "signature.h" -SIGNATURE_CHECK (sendto, ssize_t, - (int, const void *, size_t, int, - const struct sockaddr *, socklen_t)); - -#include <errno.h> -#include <netinet/in.h> -#include <arpa/inet.h> -#include <unistd.h> - -#include "sockets.h" -#include "macros.h" - -int -main (void) -{ - (void) gl_sockets_startup (SOCKETS_1_1); - - /* Test behaviour for invalid file descriptors. */ - { - struct sockaddr_in addr; - - addr.sin_family = AF_INET; - inet_pton (AF_INET, "127.0.0.1", &addr.sin_addr); - addr.sin_port = htons (80); - { - char byte = 'x'; - errno = 0; - ASSERT (sendto (-1, &byte, 1, 0, - (const struct sockaddr *) &addr, sizeof (addr)) - == -1); - ASSERT (errno == EBADF); - } - { - char byte = 'x'; - close (99); - errno = 0; - ASSERT (sendto (99, &byte, 1, 0, - (const struct sockaddr *) &addr, sizeof (addr)) - == -1); - ASSERT (errno == EBADF); - } - } - - return 0; -} diff --git a/gl/tests/test-setsockopt.c b/gl/tests/test-setsockopt.c deleted file mode 100644 index ebf50a5081..0000000000 --- a/gl/tests/test-setsockopt.c +++ /dev/null @@ -1,55 +0,0 @@ -/* Test setsockopt() function. - Copyright (C) 2011-2014 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 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> - -#include <sys/socket.h> - -#include "signature.h" -SIGNATURE_CHECK (setsockopt, int, (int, int, int, const void *, socklen_t)); - -#include <errno.h> -#include <unistd.h> - -#include "sockets.h" -#include "macros.h" - -int -main (void) -{ - (void) gl_sockets_startup (SOCKETS_1_1); - - /* Test behaviour for invalid file descriptors. */ - { - int value = 1; - - errno = 0; - ASSERT (setsockopt (-1, SOL_SOCKET, SO_REUSEADDR, &value, sizeof (value)) - == -1); - ASSERT (errno == EBADF); - } - { - int value = 1; - - close (99); - errno = 0; - ASSERT (setsockopt (99, SOL_SOCKET, SO_REUSEADDR, &value, sizeof (value)) - == -1); - ASSERT (errno == EBADF); - } - - return 0; -} diff --git a/gl/tests/test-shutdown.c b/gl/tests/test-shutdown.c deleted file mode 100644 index d49460965d..0000000000 --- a/gl/tests/test-shutdown.c +++ /dev/null @@ -1,49 +0,0 @@ -/* Test the shutdown() function. - Copyright (C) 2011-2014 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 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> - -#include <sys/socket.h> - -#include "signature.h" -SIGNATURE_CHECK (shutdown, int, (int, int)); - -#include <errno.h> -#include <unistd.h> - -#include "sockets.h" -#include "macros.h" - -int -main (void) -{ - (void) gl_sockets_startup (SOCKETS_1_1); - - /* Test behaviour for invalid file descriptors. */ - { - errno = 0; - ASSERT (shutdown (-1, SHUT_RD) == -1); - ASSERT (errno == EBADF); - } - { - close (99); - errno = 0; - ASSERT (shutdown (99, SHUT_RD) == -1); - ASSERT (errno == EBADF); - } - - return 0; -} diff --git a/gl/tests/test-signal-h.c b/gl/tests/test-signal-h.c deleted file mode 100644 index 3bc948219b..0000000000 --- a/gl/tests/test-signal-h.c +++ /dev/null @@ -1,129 +0,0 @@ -/* Test of <signal.h> substitute. - Copyright (C) 2009-2014 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 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/>. */ - -/* Written by Eric Blake <ebb9@byu.net>, 2009. */ - -#include <config.h> - -#include <signal.h> - -/* Check for required types. */ -struct -{ - size_t a; - uid_t b; - volatile sig_atomic_t c; - sigset_t d; - pid_t e; -#if 0 - /* Not guaranteed by gnulib. */ - pthread_t f; - struct timespec g; -#endif -} s; - -/* Check that NSIG is defined. */ -int nsig = NSIG; - -int -main (void) -{ - switch (0) - { - /* The following are guaranteed by C. */ - case 0: - case SIGABRT: - case SIGFPE: - case SIGILL: - case SIGINT: - case SIGSEGV: - case SIGTERM: - /* The following is guaranteed by gnulib. */ -#if GNULIB_SIGPIPE || defined SIGPIPE - case SIGPIPE: -#endif - /* Ensure no conflict with other standardized names. */ -#ifdef SIGALRM - case SIGALRM: -#endif - /* On Haiku, SIGBUS is mistakenly equal to SIGSEGV. */ -#if defined SIGBUS && SIGBUS != SIGSEGV - case SIGBUS: -#endif -#ifdef SIGCHLD - case SIGCHLD: -#endif -#ifdef SIGCONT - case SIGCONT: -#endif -#ifdef SIGHUP - case SIGHUP: -#endif -#ifdef SIGKILL - case SIGKILL: -#endif -#ifdef SIGQUIT - case SIGQUIT: -#endif -#ifdef SIGSTOP - case SIGSTOP: -#endif -#ifdef SIGTSTP - case SIGTSTP: -#endif -#ifdef SIGTTIN - case SIGTTIN: -#endif -#ifdef SIGTTOU - case SIGTTOU: -#endif -#ifdef SIGUSR1 - case SIGUSR1: -#endif -#ifdef SIGUSR2 - case SIGUSR2: -#endif -#ifdef SIGSYS - case SIGSYS: -#endif -#ifdef SIGTRAP - case SIGTRAP: -#endif -#ifdef SIGURG - case SIGURG: -#endif -#ifdef SIGVTALRM - case SIGVTALRM: -#endif -#ifdef SIGXCPU - case SIGXCPU: -#endif -#ifdef SIGXFSZ - case SIGXFSZ: -#endif - /* SIGRTMIN and SIGRTMAX need not be compile-time constants. */ -#if 0 -# ifdef SIGRTMIN - case SIGRTMIN: -# endif -# ifdef SIGRTMAX - case SIGRTMAX: -# endif -#endif - ; - } - return s.a + s.b + s.c + s.e; -} diff --git a/gl/tests/test-stat.c b/gl/tests/test-stat.c deleted file mode 100644 index 9ed462a32a..0000000000 --- a/gl/tests/test-stat.c +++ /dev/null @@ -1,55 +0,0 @@ -/* Tests of stat. - Copyright (C) 2009-2014 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 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/>. */ - -/* Written by Eric Blake <ebb9@byu.net>, 2009. */ - -#include <config.h> - -#include <sys/stat.h> - -/* Caution: stat may be a function-like macro. Although this - signature check must pass, it may be the signature of the real (and - broken) stat rather than rpl_stat. Most code should not use the - address of stat. */ -#include "signature.h" -SIGNATURE_CHECK (stat, int, (char const *, struct stat *)); - -#include <fcntl.h> -#include <errno.h> -#include <stdbool.h> -#include <stdio.h> -#include <unistd.h> - -#include "same-inode.h" -#include "macros.h" - -#define BASE "test-stat.t" - -#include "test-stat.h" - -/* Wrapper around stat, which works even if stat is a function-like - macro, where test_stat_func(stat) would do the wrong thing. */ -static int -do_stat (char const *name, struct stat *st) -{ - return stat (name, st); -} - -int -main (void) -{ - return test_stat_func (do_stat, true); -} diff --git a/gl/tests/test-stat.h b/gl/tests/test-stat.h deleted file mode 100644 index 6cfc958d4a..0000000000 --- a/gl/tests/test-stat.h +++ /dev/null @@ -1,100 +0,0 @@ -/* Tests of stat. - Copyright (C) 2009-2014 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 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/>. */ - -/* Written by Eric Blake <ebb9@byu.net>, 2009. */ - -/* This file is designed to test both stat(n,buf) and - fstatat(AT_FDCWD,n,buf,0). FUNC is the function to test. Assumes - that BASE and ASSERT are already defined, and that appropriate - headers are already included. If PRINT, warn before skipping - symlink tests with status 77. */ - -static int -test_stat_func (int (*func) (char const *, struct stat *), bool print) -{ - struct stat st1; - struct stat st2; - char *cwd = getcwd (NULL, 0); - - ASSERT (cwd); - ASSERT (func (".", &st1) == 0); - ASSERT (func ("./", &st2) == 0); - ASSERT (SAME_INODE (st1, st2)); - ASSERT (func (cwd, &st2) == 0); - ASSERT (SAME_INODE (st1, st2)); - ASSERT (func ("/", &st1) == 0); - ASSERT (func ("///", &st2) == 0); - ASSERT (SAME_INODE (st1, st2)); - - errno = 0; - ASSERT (func ("", &st1) == -1); - ASSERT (errno == ENOENT); - errno = 0; - ASSERT (func ("nosuch", &st1) == -1); - ASSERT (errno == ENOENT); - errno = 0; - ASSERT (func ("nosuch/", &st1) == -1); - ASSERT (errno == ENOENT); - - ASSERT (close (creat (BASE "file", 0600)) == 0); - ASSERT (func (BASE "file", &st1) == 0); - errno = 0; - ASSERT (func (BASE "file/", &st1) == -1); - ASSERT (errno == ENOTDIR); - - /* Now for some symlink tests, where supported. We set up: - link1 -> directory - link2 -> file - link3 -> dangling - link4 -> loop - then test behavior with trailing slash. - */ - if (symlink (".", BASE "link1") != 0) - { - ASSERT (unlink (BASE "file") == 0); - if (print) - fputs ("skipping test: symlinks not supported on this file system\n", - stderr); - return 77; - } - ASSERT (symlink (BASE "file", BASE "link2") == 0); - ASSERT (symlink (BASE "nosuch", BASE "link3") == 0); - ASSERT (symlink (BASE "link4", BASE "link4") == 0); - - ASSERT (func (BASE "link1/", &st1) == 0); - ASSERT (S_ISDIR (st1.st_mode)); - - errno = 0; - ASSERT (func (BASE "link2/", &st1) == -1); - ASSERT (errno == ENOTDIR); - - errno = 0; - ASSERT (func (BASE "link3/", &st1) == -1); - ASSERT (errno == ENOENT); - - errno = 0; - ASSERT (func (BASE "link4/", &st1) == -1); - ASSERT (errno == ELOOP); - - /* Cleanup. */ - ASSERT (unlink (BASE "file") == 0); - ASSERT (unlink (BASE "link1") == 0); - ASSERT (unlink (BASE "link2") == 0); - ASSERT (unlink (BASE "link3") == 0); - ASSERT (unlink (BASE "link4") == 0); - - return 0; -} diff --git a/gl/tests/test-strerror.c b/gl/tests/test-strerror.c deleted file mode 100644 index 8e2ed7c272..0000000000 --- a/gl/tests/test-strerror.c +++ /dev/null @@ -1,75 +0,0 @@ -/* Test of strerror() function. - Copyright (C) 2007-2014 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, 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 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/>. */ - -/* Written by Eric Blake <ebb9@byu.net>, 2007. */ - -#include <config.h> - -#include <string.h> - -#include "signature.h" -SIGNATURE_CHECK (strerror, char *, (int)); - -#include <errno.h> - -#include "macros.h" - -int -main (void) -{ - char *str; - - errno = 0; - str = strerror (EACCES); - ASSERT (str); - ASSERT (*str); - ASSERT (errno == 0); - - errno = 0; - str = strerror (ETIMEDOUT); - ASSERT (str); - ASSERT (*str); - ASSERT (errno == 0); - - errno = 0; - str = strerror (EOVERFLOW); - ASSERT (str); - ASSERT (*str); - ASSERT (errno == 0); - - /* POSIX requires strerror (0) to succeed. Reject use of "Unknown - error", but allow "Success", "No error", or even Solaris' "Error - 0" which are distinct patterns from true out-of-range strings. - http://austingroupbugs.net/view.php?id=382 */ - errno = 0; - str = strerror (0); - ASSERT (str); - ASSERT (*str); - ASSERT (errno == 0); - ASSERT (strstr (str, "nknown") == NULL); - ASSERT (strstr (str, "ndefined") == NULL); - - /* POSIX requires strerror to produce a non-NULL result for all - inputs; as an extension, we also guarantee a non-empty result. - Reporting EINVAL is optional. */ - errno = 0; - str = strerror (-3); - ASSERT (str); - ASSERT (*str); - ASSERT (errno == 0 || errno == EINVAL); - - return 0; -} diff --git a/gl/tests/test-strerror_r.c b/gl/tests/test-strerror_r.c deleted file mode 100644 index 9e1f0bef51..0000000000 --- a/gl/tests/test-strerror_r.c +++ /dev/null @@ -1,181 +0,0 @@ -/* Test of strerror_r() function. - Copyright (C) 2007-2014 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, 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 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> - -#include <string.h> - -#include "signature.h" -SIGNATURE_CHECK (strerror_r, int, (int, char *, size_t)); - -#include <errno.h> - -#include "macros.h" - -int -main (void) -{ - char buf[100]; - int ret; - - /* Test results with valid errnum and enough room. */ - - errno = 0; - buf[0] = '\0'; - ASSERT (strerror_r (EACCES, buf, sizeof buf) == 0); - ASSERT (buf[0] != '\0'); - ASSERT (errno == 0); - ASSERT (strlen (buf) < sizeof buf); - - errno = 0; - buf[0] = '\0'; - ASSERT (strerror_r (ETIMEDOUT, buf, sizeof buf) == 0); - ASSERT (buf[0] != '\0'); - ASSERT (errno == 0); - ASSERT (strlen (buf) < sizeof buf); - - errno = 0; - buf[0] = '\0'; - ASSERT (strerror_r (EOVERFLOW, buf, sizeof buf) == 0); - ASSERT (buf[0] != '\0'); - ASSERT (errno == 0); - ASSERT (strlen (buf) < sizeof buf); - - /* POSIX requires strerror (0) to succeed. Reject use of "Unknown - error", but allow "Success", "No error", or even Solaris' "Error - 0" which are distinct patterns from true out-of-range strings. - http://austingroupbugs.net/view.php?id=382 */ - errno = 0; - buf[0] = '\0'; - ret = strerror_r (0, buf, sizeof buf); - ASSERT (ret == 0); - ASSERT (buf[0]); - ASSERT (errno == 0); - ASSERT (strstr (buf, "nknown") == NULL); - ASSERT (strstr (buf, "ndefined") == NULL); - - /* Test results with out-of-range errnum and enough room. POSIX - allows an empty string on success, and allows an unchanged buf on - error, but these are not useful, so we guarantee contents. */ - errno = 0; - buf[0] = '^'; - ret = strerror_r (-3, buf, sizeof buf); - ASSERT (ret == 0 || ret == EINVAL); - ASSERT (buf[0] != '^'); - ASSERT (*buf); - ASSERT (errno == 0); - ASSERT (strlen (buf) < sizeof buf); - - /* Test results with a too small buffer. POSIX requires an error; - only ERANGE for 0 and valid errors, and a choice of ERANGE or - EINVAL for out-of-range values. On error, POSIX permits buf to - be empty, unchanged, or unterminated, but these are not useful, - so we guarantee NUL-terminated truncated contents for all but - size 0. http://austingroupbugs.net/view.php?id=398. Also ensure - that no out-of-bounds writes occur. */ - { - int errs[] = { EACCES, 0, -3, }; - int j; - - buf[sizeof buf - 1] = '\0'; - for (j = 0; j < SIZEOF (errs); j++) - { - int err = errs[j]; - char buf2[sizeof buf] = ""; - size_t len; - size_t i; - - strerror_r (err, buf2, sizeof buf2); - len = strlen (buf2); - ASSERT (len < sizeof buf); - - for (i = 0; i <= len; i++) - { - memset (buf, '^', sizeof buf - 1); - errno = 0; - ret = strerror_r (err, buf, i); - ASSERT (errno == 0); - if (err < 0) - ASSERT (ret == ERANGE || ret == EINVAL); - else - ASSERT (ret == ERANGE); - if (i) - { - ASSERT (strncmp (buf, buf2, i - 1) == 0); - ASSERT (buf[i - 1] == '\0'); - } - ASSERT (strspn (buf + i, "^") == sizeof buf - 1 - i); - } - - strcpy (buf, "BADFACE"); - errno = 0; - ret = strerror_r (err, buf, len + 1); - ASSERT (ret != ERANGE); - ASSERT (errno == 0); - ASSERT (strcmp (buf, buf2) == 0); - } - } - -#if GNULIB_STRERROR - /* Test that strerror_r does not clobber strerror buffer. On some - platforms, this test can only succeed if gnulib also replaces - strerror. */ - { - const char *msg1; - const char *msg2; - const char *msg3; - const char *msg4; - char *str1; - char *str2; - char *str3; - char *str4; - - msg1 = strerror (ENOENT); - ASSERT (msg1); - str1 = strdup (msg1); - ASSERT (str1); - - msg2 = strerror (ERANGE); - ASSERT (msg2); - str2 = strdup (msg2); - ASSERT (str2); - - msg3 = strerror (-4); - ASSERT (msg3); - str3 = strdup (msg3); - ASSERT (str3); - - msg4 = strerror (1729576); - ASSERT (msg4); - str4 = strdup (msg4); - ASSERT (str4); - - strerror_r (EACCES, buf, sizeof buf); - strerror_r (-5, buf, sizeof buf); - ASSERT (msg1 == msg2 || msg1 == msg4 || STREQ (msg1, str1)); - ASSERT (msg2 == msg4 || STREQ (msg2, str2)); - ASSERT (msg3 == msg4 || STREQ (msg3, str3)); - ASSERT (STREQ (msg4, str4)); - - free (str1); - free (str2); - free (str3); - free (str4); - } -#endif - - return 0; -} diff --git a/gl/tests/test-symlink.c b/gl/tests/test-symlink.c deleted file mode 100644 index 78d46c23b6..0000000000 --- a/gl/tests/test-symlink.c +++ /dev/null @@ -1,47 +0,0 @@ -/* Tests of symlink. - Copyright (C) 2009-2014 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 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/>. */ - -/* Written by Eric Blake <ebb9@byu.net>, 2009. */ - -#include <config.h> - -#include <unistd.h> - -#include "signature.h" -SIGNATURE_CHECK (symlink, int, (char const *, char const *)); - -#include <fcntl.h> -#include <errno.h> -#include <stdbool.h> -#include <stdio.h> -#include <stdlib.h> -#include <sys/stat.h> - -#include "ignore-value.h" -#include "macros.h" - -#define BASE "test-symlink.t" - -#include "test-symlink.h" - -int -main (void) -{ - /* Remove any leftovers from a previous partial run. */ - ignore_value (system ("rm -rf " BASE "*")); - - return test_symlink (symlink, true); -} diff --git a/gl/tests/test-symlink.h b/gl/tests/test-symlink.h deleted file mode 100644 index eb11cf69b8..0000000000 --- a/gl/tests/test-symlink.h +++ /dev/null @@ -1,95 +0,0 @@ -/* Tests of symlink. - Copyright (C) 2009-2014 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 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/>. */ - -/* Written by Eric Blake <ebb9@byu.net>, 2009. */ - -/* This file is designed to test both symlink(a,b) and - symlinkat(a,AT_FDCWD,b). FUNC is the function to test. Assumes - that BASE and ASSERT are already defined, and that appropriate - headers are already included. If PRINT, warn before skipping - symlink tests with status 77. */ - -static int -test_symlink (int (*func) (char const *, char const *), bool print) -{ - if (func ("nowhere", BASE "link1")) - { - if (print) - fputs ("skipping test: symlinks not supported on this file system\n", - stderr); - return 77; - } - - /* Some systems allow the creation of 0-length symlinks as a synonym - for "."; but most reject it. */ - { - int status; - errno = 0; - status = func ("", BASE "link2"); - if (status == -1) - ASSERT (errno == ENOENT || errno == EINVAL); - else - { - ASSERT (status == 0); - ASSERT (unlink (BASE "link2") == 0); - } - } - - /* Sanity checks of failures. */ - errno = 0; - ASSERT (func ("nowhere", "") == -1); - ASSERT (errno == ENOENT); - errno = 0; - ASSERT (func ("nowhere", ".") == -1); - ASSERT (errno == EEXIST || errno == EINVAL); - errno = 0; - ASSERT (func ("somewhere", BASE "link1") == -1); - ASSERT (errno == EEXIST); - errno = 0; - ASSERT (func ("nowhere", BASE "link2/") == -1); - ASSERT (errno == ENOTDIR || errno == ENOENT); - ASSERT (mkdir (BASE "dir", 0700) == 0); - errno = 0; - ASSERT (func ("nowhere", BASE "dir") == -1); - ASSERT (errno == EEXIST); - errno = 0; - ASSERT (func ("nowhere", BASE "dir/") == -1); - ASSERT (errno == EEXIST || errno == EINVAL); - ASSERT (close (creat (BASE "file", 0600)) == 0); - errno = 0; - ASSERT (func ("nowhere", BASE "file") == -1); - ASSERT (errno == EEXIST); - errno = 0; - ASSERT (func ("nowhere", BASE "file/") == -1); - ASSERT (errno == EEXIST || errno == ENOTDIR || errno == ENOENT); - - /* Trailing slash must always be rejected. */ - ASSERT (unlink (BASE "link1") == 0); - ASSERT (func (BASE "link2", BASE "link1") == 0); - errno = 0; - ASSERT (func (BASE "nowhere", BASE "link1/") == -1); - ASSERT (errno == EEXIST || errno == ENOTDIR || errno == ENOENT); - errno = 0; - ASSERT (unlink (BASE "link2") == -1); - ASSERT (errno == ENOENT); - - /* Cleanup. */ - ASSERT (rmdir (BASE "dir") == 0); - ASSERT (unlink (BASE "file") == 0); - ASSERT (unlink (BASE "link1") == 0); - - return 0; -} diff --git a/gl/tests/test-sys_ioctl.c b/gl/tests/test-sys_ioctl.c deleted file mode 100644 index bd2a5af34a..0000000000 --- a/gl/tests/test-sys_ioctl.c +++ /dev/null @@ -1,27 +0,0 @@ -/* Test of <sys/ioctl.h> substitute. - Copyright (C) 2009-2014 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 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/>. */ - -/* Written by Eric Blake <ebb9@byu.net>, 2009. */ - -#include <config.h> - -#include <sys/ioctl.h> - -int -main (void) -{ - return 0; -} diff --git a/gl/tests/test-sys_select.c b/gl/tests/test-sys_select.c deleted file mode 100644 index 2e4f7c10b2..0000000000 --- a/gl/tests/test-sys_select.c +++ /dev/null @@ -1,59 +0,0 @@ -/* Test of <sys/select.h> substitute. - Copyright (C) 2007-2014 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 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/>. */ - -/* Written by Bruno Haible <bruno@clisp.org>, 2007. */ - -#include <config.h> - -#include <sys/select.h> - -#include "signature.h" - -/* The following may be macros without underlying functions, so only - check signature if they are not macros. */ -#ifndef FD_CLR -SIGNATURE_CHECK (FD_CLR, void, (int, fd_set *)); -#endif -#ifndef FD_ISSET -SIGNATURE_CHECK (FD_ISSET, void, (int, fd_set *)); -#endif -#ifndef FD_SET -SIGNATURE_CHECK (FD_SET, int, (int, fd_set *)); -#endif -#ifndef FD_ZERO -SIGNATURE_CHECK (FD_ZERO, void, (fd_set *)); -#endif - -/* Check that the 'struct timeval' type is defined. */ -struct timeval a; - -/* Check that a.tv_sec is wide enough to hold a time_t, ignoring - signedness issues. */ -typedef int verify_tv_sec_type[sizeof (time_t) <= sizeof (a.tv_sec) ? 1 : -1]; - -/* Check that sigset_t is defined. */ -sigset_t t2; - -int -main (void) -{ - /* Check that FD_ZERO can be used. This should not yield a warning - such as "warning: implicit declaration of function 'memset'". */ - fd_set fds; - FD_ZERO (&fds); - - return 0; -} |