# HG changeset patch # User Bruno Haible # Date 1316693791 -7200 # Node ID 9f82d16d3139112abcfbbb9dd85102a39a24404e # Parent 8c84ffc4d210d5ddfe4204fe1f867e59a7900d99 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 . * modules/perror-tests (Depends-on): Add ftruncate. * doc/posix-functions/ftruncate.texi: Mention the MSVC problem and the 'ftruncate' module. diff --git a/ChangeLog b/ChangeLog --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,16 @@ +2011-09-21 Bruno Haible + + 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 . + * 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 Add dependencies to new dirent related modules. diff --git a/doc/posix-functions/ftruncate.texi b/doc/posix-functions/ftruncate.texi --- 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 --- 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 @@ -6,67 +6,9 @@ /* Specification. */ #include -#include -#include - -#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 . */ - -# include -# include - -int -ftruncate (int fd, off_t length) -{ - struct flock fl; - struct stat filebuf; - - if (fstat (fd, &filebuf) < 0) - return -1; +#if HAVE_CHSIZE - 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 int ftruncate (int fd, off_t length) @@ -74,17 +16,4 @@ return chsize (fd, length); } -# else /* not F_CHSIZE nor F_FREESP nor HAVE_CHSIZE */ - -# include - -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 --- 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: -# -# Now (in 2010), MSVC has been raised as a possible target: -# - 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 --- 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 --- a/modules/perror-tests +++ b/modules/perror-tests @@ -8,6 +8,7 @@ Depends-on: dup2 +ftruncate strerror configure.ac: