summaryrefslogtreecommitdiff
path: root/gl/tests
diff options
context:
space:
mode:
authorNikos Mavrogiannopoulos <nmav@gnutls.org>2012-06-05 19:10:04 +0200
committerNikos Mavrogiannopoulos <nmav@gnutls.org>2012-06-05 19:10:04 +0200
commit75ed5f82a8b6a5f697c06feb1254152bb8b1f0ff (patch)
tree545a22b12ecce630acc5fa48d877b5898340f93e /gl/tests
parenta8f5d585a2b482b3d33ce7f5e8ff2785b6ac4f8e (diff)
downloadgnutls-75ed5f82a8b6a5f697c06feb1254152bb8b1f0ff.tar.gz
updated gnulib
Diffstat (limited to 'gl/tests')
-rw-r--r--gl/tests/binary-io.h41
-rw-r--r--gl/tests/fcntl.in.h4
-rw-r--r--gl/tests/ftruncate.c157
-rw-r--r--gl/tests/ignore-value.h10
-rw-r--r--gl/tests/init.sh8
-rw-r--r--gl/tests/stat.c14
-rw-r--r--gl/tests/test-binary-io.c26
-rwxr-xr-xgl/tests/test-binary-io.sh8
-rw-r--r--gl/tests/test-errno.c2
9 files changed, 231 insertions, 39 deletions
diff --git a/gl/tests/binary-io.h b/gl/tests/binary-io.h
index 824ad5b78a..a33e32aee2 100644
--- a/gl/tests/binary-io.h
+++ b/gl/tests/binary-io.h
@@ -25,28 +25,41 @@
so we include it here first. */
#include <stdio.h>
-/* SET_BINARY (fd);
- changes the file descriptor fd to perform binary I/O. */
+/* set_binary_mode (fd, mode)
+ sets the binary/text I/O mode of file descriptor fd to the given mode
+ (must be O_BINARY or O_TEXT) and returns the previous mode. */
#if O_BINARY
# if defined __EMX__ || defined __DJGPP__ || defined __CYGWIN__
# include <io.h> /* declares setmode() */
+# define set_binary_mode setmode
# else
-# define setmode _setmode
+# define set_binary_mode _setmode
# undef fileno
# define fileno _fileno
# endif
-# ifdef __DJGPP__
-# include <unistd.h> /* declares isatty() */
- /* Avoid putting stdin/stdout in binary mode if it is connected to
- the console, because that would make it impossible for the user
- to interrupt the program through Ctrl-C or Ctrl-Break. */
-# define SET_BINARY(fd) ((void) (!isatty (fd) ? (setmode (fd, O_BINARY), 0) : 0))
-# else
-# define SET_BINARY(fd) ((void) setmode (fd, O_BINARY))
-# endif
#else
- /* On reasonable systems, binary I/O is the default. */
-# define SET_BINARY(fd) /* do nothing */ ((void) 0)
+ /* On reasonable systems, binary I/O is the only choice. */
+ /* Use an inline function rather than a macro, to avoid gcc warnings
+ "warning: statement with no effect". */
+static inline int
+set_binary_mode (int fd, int mode)
+{
+ (void) fd;
+ (void) mode;
+ return O_BINARY;
+}
+#endif
+
+/* SET_BINARY (fd);
+ changes the file descriptor fd to perform binary I/O. */
+#ifdef __DJGPP__
+# include <unistd.h> /* declares isatty() */
+ /* Avoid putting stdin/stdout in binary mode if it is connected to
+ the console, because that would make it impossible for the user
+ to interrupt the program through Ctrl-C or Ctrl-Break. */
+# define SET_BINARY(fd) ((void) (!isatty (fd) ? (set_binary_mode (fd, O_BINARY), 0) : 0))
+#else
+# define SET_BINARY(fd) ((void) set_binary_mode (fd, O_BINARY))
#endif
#endif /* _BINARY_H */
diff --git a/gl/tests/fcntl.in.h b/gl/tests/fcntl.in.h
index 344bbe4d3d..76e12f78a6 100644
--- a/gl/tests/fcntl.in.h
+++ b/gl/tests/fcntl.in.h
@@ -25,6 +25,8 @@
#if defined __need_system_fcntl_h
/* Special invocation convention. */
+/* Needed before <sys/stat.h>.
+ May also define off_t to a 64-bit type on native Windows. */
#include <sys/types.h>
/* On some systems other than glibc, <sys/stat.h> is a prerequisite of
<fcntl.h>. On glibc systems, we would like to avoid namespace pollution.
@@ -42,6 +44,8 @@
#ifndef _@GUARD_PREFIX@_FCNTL_H
+/* Needed before <sys/stat.h>.
+ May also define off_t to a 64-bit type on native Windows. */
#include <sys/types.h>
/* On some systems other than glibc, <sys/stat.h> is a prerequisite of
<fcntl.h>. On glibc systems, we would like to avoid namespace pollution.
diff --git a/gl/tests/ftruncate.c b/gl/tests/ftruncate.c
index ae1e85890c..e243adda60 100644
--- a/gl/tests/ftruncate.c
+++ b/gl/tests/ftruncate.c
@@ -1,5 +1,18 @@
/* ftruncate emulations for native Windows.
- This file is in the public domain. */
+ Copyright (C) 1992-2012 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>
@@ -7,12 +20,143 @@
#include <unistd.h>
#if HAVE_CHSIZE
+/* A native Windows platform. */
# include <errno.h>
-# include <io.h>
-# if HAVE_MSVC_INVALID_PARAMETER_HANDLER
-# include "msvc-inval.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 inline int
chsize_nothrow (int fd, long length)
{
@@ -31,8 +175,8 @@ chsize_nothrow (int fd, long length)
return result;
}
-# define chsize chsize_nothrow
-# endif
+# define chsize chsize_nothrow
+# endif
int
ftruncate (int fd, off_t length)
@@ -40,4 +184,5 @@ ftruncate (int fd, off_t length)
return chsize (fd, length);
}
+# endif
#endif
diff --git a/gl/tests/ignore-value.h b/gl/tests/ignore-value.h
index 52919de8f1..2e34435094 100644
--- a/gl/tests/ignore-value.h
+++ b/gl/tests/ignore-value.h
@@ -35,16 +35,6 @@
#ifndef _GL_IGNORE_VALUE_H
# define _GL_IGNORE_VALUE_H
-# ifndef _GL_ATTRIBUTE_DEPRECATED
-/* The __attribute__((__deprecated__)) feature
- is available in gcc versions 3.1 and newer. */
-# if __GNUC__ < 3 || (__GNUC__ == 3 && __GNUC_MINOR__ < 1)
-# define _GL_ATTRIBUTE_DEPRECATED /* empty */
-# else
-# define _GL_ATTRIBUTE_DEPRECATED __attribute__ ((__deprecated__))
-# endif
-# endif
-
/* The __attribute__((__warn_unused_result__)) feature
is available in gcc versions 3.4 and newer,
while the typeof feature has been available since 2.7 at least. */
diff --git a/gl/tests/init.sh b/gl/tests/init.sh
index ae867144d0..f525a7cab4 100644
--- a/gl/tests/init.sh
+++ b/gl/tests/init.sh
@@ -207,6 +207,14 @@ else
fi
fi
+# If this is bash, turn off all aliases.
+test -n "$BASH_VERSION" && unalias -a
+
+# Note that when supporting $EXEEXT (transparently mapping from PROG_NAME to
+# PROG_NAME.exe), we want to support hyphen-containing names like test-acos.
+# That is part of the shell-selection test above. Why use aliases rather
+# than functions? Because support for hyphen-containing aliases is more
+# widespread than that for hyphen-containing function names.
test -n "$EXEEXT" && shopt -s expand_aliases
# Enable glibc's malloc-perturbing option.
diff --git a/gl/tests/stat.c b/gl/tests/stat.c
index 9ea53c1c0c..1fc633eeef 100644
--- a/gl/tests/stat.c
+++ b/gl/tests/stat.c
@@ -27,6 +27,20 @@
#include <sys/stat.h>
#undef __need_system_sys_stat_h
+#if (defined _WIN32 || defined __WIN32__) && ! defined __CYGWIN__
+# if _GL_WINDOWS_64_BIT_ST_SIZE
+# 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 inline int
orig_stat (const char *filename, struct stat *buf)
{
diff --git a/gl/tests/test-binary-io.c b/gl/tests/test-binary-io.c
index c695454ecd..4f284e7015 100644
--- a/gl/tests/test-binary-io.c
+++ b/gl/tests/test-binary-io.c
@@ -30,26 +30,40 @@
#include "macros.h"
int
-main ()
+main (int argc, char *argv[])
{
/* Test the O_BINARY macro. */
{
int fd =
- open ("t-bin-out2.tmp", O_CREAT | O_TRUNC | O_RDWR | O_BINARY, 0600);
+ open ("t-bin-out0.tmp", O_CREAT | O_TRUNC | O_RDWR | O_BINARY, 0600);
if (write (fd, "Hello\n", 6) < 0)
exit (1);
close (fd);
}
{
struct stat statbuf;
- if (stat ("t-bin-out2.tmp", &statbuf) < 0)
+ if (stat ("t-bin-out0.tmp", &statbuf) < 0)
exit (1);
ASSERT (statbuf.st_size == 6);
}
- /* Test the SET_BINARY macro. */
- SET_BINARY (1);
- fputs ("Hello\n", stdout);
+ switch (argv[1][0])
+ {
+ case '1':
+ /* Test the set_binary_mode() function. */
+ set_binary_mode (1, O_BINARY);
+ fputs ("Hello\n", stdout);
+ break;
+
+ case '2':
+ /* Test the SET_BINARY macro. */
+ SET_BINARY (1);
+ fputs ("Hello\n", stdout);
+ break;
+
+ default:
+ break;
+ }
return 0;
}
diff --git a/gl/tests/test-binary-io.sh b/gl/tests/test-binary-io.sh
index 272edef179..c4dd6e9295 100755
--- a/gl/tests/test-binary-io.sh
+++ b/gl/tests/test-binary-io.sh
@@ -3,9 +3,11 @@
tmpfiles=""
trap 'rm -fr $tmpfiles' 1 2 3 15
-tmpfiles="$tmpfiles t-bin-out1.tmp t-bin-out2.tmp"
-./test-binary-io${EXEEXT} > t-bin-out1.tmp || exit 1
-cmp t-bin-out1.tmp t-bin-out2.tmp > /dev/null || exit 1
+tmpfiles="$tmpfiles t-bin-out0.tmp t-bin-out1.tmp t-bin-out2.tmp"
+./test-binary-io${EXEEXT} 1 > t-bin-out1.tmp || exit 1
+cmp t-bin-out0.tmp t-bin-out1.tmp > /dev/null || exit 1
+./test-binary-io${EXEEXT} 2 > t-bin-out2.tmp || exit 1
+cmp t-bin-out0.tmp t-bin-out2.tmp > /dev/null || exit 1
rm -fr $tmpfiles
diff --git a/gl/tests/test-errno.c b/gl/tests/test-errno.c
index d9a030f448..8d0071741f 100644
--- a/gl/tests/test-errno.c
+++ b/gl/tests/test-errno.c
@@ -98,6 +98,8 @@ int e115 = EINPROGRESS;
int e116 = ESTALE;
int e122 = EDQUOT;
int e125 = ECANCELED;
+int e130 = EOWNERDEAD;
+int e131 = ENOTRECOVERABLE;
/* Don't verify that these errno values are all different, except for possibly
EWOULDBLOCK == EAGAIN. Even Linux/x86 does not pass this check: it has