summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--ChangeLog13
-rw-r--r--doc/posix-functions/ftruncate.texi13
-rw-r--r--lib/ftruncate.c79
-rw-r--r--m4/ftruncate.m427
-rw-r--r--modules/ftruncate7
-rw-r--r--modules/perror-tests1
6 files changed, 29 insertions, 111 deletions
diff --git a/ChangeLog b/ChangeLog
index 8f3da40c09..f6f275093f 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,18 @@
2011-09-21 Bruno Haible <bruno@clisp.org>
+ ftruncate: Un-deprecate, concentrate on Win32 support.
+ * modules/ftruncate (Status, Notice): Remove sections.
+ (Depends-on): Add largefile.
+ * m4/ftruncate.m4 (gl_FUNC_FTRUNCATE): Drop failure message on
+ non-mingw platforms.
+ * lib/ftruncate.c: Remove code for the older platforms. For Win32,
+ include <io.h>.
+ * modules/perror-tests (Depends-on): Add ftruncate.
+ * doc/posix-functions/ftruncate.texi: Mention the MSVC problem and the
+ 'ftruncate' module.
+
+2011-09-21 Bruno Haible <bruno@clisp.org>
+
Add dependencies to new dirent related modules.
* modules/opendir (Depends-on): Add closedir.
* modules/getcwd (Depends-on): Add opendir, closedir.
diff --git a/doc/posix-functions/ftruncate.texi b/doc/posix-functions/ftruncate.texi
index 60d31882b5..16713e7d5b 100644
--- a/doc/posix-functions/ftruncate.texi
+++ b/doc/posix-functions/ftruncate.texi
@@ -4,16 +4,19 @@
POSIX specification:@* @url{http://www.opengroup.org/onlinepubs/9699919799/functions/ftruncate.html}
-Gnulib module: ---
+Gnulib module: ftruncate
Portability problems fixed by Gnulib:
@itemize
-@end itemize
-
-Portability problems not fixed by Gnulib:
-@itemize
+@item
+This function is missing on some platforms:
+MSVC 9.
@item
On platforms where @code{off_t} is a 32-bit type, this function is not
applicable to arbitrary lengths for files larger than 2 GB. The fix is to
use the @code{AC_SYS_LARGEFILE} macro.
@end itemize
+
+Portability problems not fixed by Gnulib:
+@itemize
+@end itemize
diff --git a/lib/ftruncate.c b/lib/ftruncate.c
index 33b69d8107..d5a3be144c 100644
--- a/lib/ftruncate.c
+++ b/lib/ftruncate.c
@@ -1,4 +1,4 @@
-/* ftruncate emulations that work on some System V's.
+/* ftruncate emulations for native Windows.
This file is in the public domain. */
#include <config.h>
@@ -6,67 +6,9 @@
/* Specification. */
#include <unistd.h>
-#include <sys/types.h>
-#include <fcntl.h>
+#if HAVE_CHSIZE
-#ifdef F_CHSIZE
-
-int
-ftruncate (int fd, off_t length)
-{
- return fcntl (fd, F_CHSIZE, length);
-}
-
-#else /* not F_CHSIZE */
-# ifdef F_FREESP
-
-/* By William Kucharski <kucharsk@netcom.com>. */
-
-# include <sys/stat.h>
-# include <errno.h>
-
-int
-ftruncate (int fd, off_t length)
-{
- struct flock fl;
- struct stat filebuf;
-
- if (fstat (fd, &filebuf) < 0)
- return -1;
-
- if (filebuf.st_size < length)
- {
- /* Extend file length. */
- if (lseek (fd, (length - 1), SEEK_SET) < 0)
- return -1;
-
- /* Write a "0" byte. */
- if (write (fd, "", 1) != 1)
- return -1;
- }
- else
- {
-
- /* Truncate length. */
-
- fl.l_whence = 0;
- fl.l_len = 0;
- fl.l_start = length;
- fl.l_type = F_WRLCK; /* write lock on file space */
-
- /* This relies on the *undocumented* F_FREESP argument to fcntl,
- which truncates the file so that it ends at the position
- indicated by fl.l_start. Will minor miracles never cease? */
-
- if (fcntl (fd, F_FREESP, &fl) < 0)
- return -1;
- }
-
- return 0;
-}
-
-# else /* not F_CHSIZE nor F_FREESP */
-# if HAVE_CHSIZE /* native Windows, e.g. mingw */
+# include <io.h>
int
ftruncate (int fd, off_t length)
@@ -74,17 +16,4 @@ ftruncate (int fd, off_t length)
return chsize (fd, length);
}
-# else /* not F_CHSIZE nor F_FREESP nor HAVE_CHSIZE */
-
-# include <errno.h>
-
-int
-ftruncate (int fd, off_t length)
-{
- errno = EIO;
- return -1;
-}
-
-# endif /* not HAVE_CHSIZE */
-# endif /* not F_FREESP */
-#endif /* not F_CHSIZE */
+#endif
diff --git a/m4/ftruncate.m4 b/m4/ftruncate.m4
index c3c3342652..42730907a6 100644
--- a/m4/ftruncate.m4
+++ b/m4/ftruncate.m4
@@ -1,41 +1,18 @@
-# serial 16
+# serial 17
-# See if we need to emulate a missing ftruncate function using fcntl or chsize.
+# See if we need to emulate a missing ftruncate function using chsize.
# Copyright (C) 2000-2001, 2003-2007, 2009-2011 Free Software Foundation, Inc.
# This file is free software; the Free Software Foundation
# gives unlimited permission to copy and/or distribute it,
# with or without modifications, as long as this notice is preserved.
-# FIXME: remove this macro, along with all uses of HAVE_FTRUNCATE in 2012,
-# if the check below provokes no more reports. So far, the only report
-# arose from a test build of this gnulib module, cross-compiling to mingw:
-# <http://thread.gmane.org/gmane.comp.lib.gnulib.bugs/9203>
-# Now (in 2010), MSVC has been raised as a possible target:
-# <http://thread.gmane.org/gmane.comp.lib.gnulib.bugs/21394/focus=21396>
-
AC_DEFUN([gl_FUNC_FTRUNCATE],
[
AC_REQUIRE([gl_UNISTD_H_DEFAULTS])
- AC_REQUIRE([AC_CANONICAL_HOST])
AC_CHECK_FUNCS_ONCE([ftruncate])
if test $ac_cv_func_ftruncate = no; then
HAVE_FTRUNCATE=0
- case "$host_os" in
- mingw*)
- # Yes, we know mingw lacks ftruncate.
- ;;
- *)
- # If someone lacks ftruncate, make configure fail, and request
- # a bug report to inform us about it.
- if test x"$SKIP_FTRUNCATE_CHECK" != xyes; then
- AC_MSG_FAILURE([Your system lacks the ftruncate function.
- Please report this, along with the output of "uname -a", to the
- bug-coreutils@gnu.org mailing list. To continue past this point,
- rerun configure with SKIP_FTRUNCATE_CHECK=yes.
- E.g., ./configure SKIP_FTRUNCATE_CHECK=yes])
- fi
- esac
fi
])
diff --git a/modules/ftruncate b/modules/ftruncate
index 6be248c842..3bea20be3b 100644
--- a/modules/ftruncate
+++ b/modules/ftruncate
@@ -1,18 +1,13 @@
Description:
ftruncate() function: truncate an open file to a specified length.
-Status:
-obsolete
-
-Notice:
-This module is obsolete.
-
Files:
lib/ftruncate.c
m4/ftruncate.m4
Depends-on:
unistd
+largefile
configure.ac:
gl_FUNC_FTRUNCATE
diff --git a/modules/perror-tests b/modules/perror-tests
index 04adee2e22..5e41800283 100644
--- a/modules/perror-tests
+++ b/modules/perror-tests
@@ -8,6 +8,7 @@ tests/test-perror.sh
Depends-on:
dup2
+ftruncate
strerror
configure.ac: