Mercurial > hg > octave-nkf > gnulib-hg
changeset 15739:9f82d16d3139
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.
author | Bruno Haible <bruno@clisp.org> |
---|---|
date | Thu, 22 Sep 2011 14:16:31 +0200 |
parents | 8c84ffc4d210 |
children | f94acfaf527e |
files | ChangeLog doc/posix-functions/ftruncate.texi lib/ftruncate.c m4/ftruncate.m4 modules/ftruncate modules/perror-tests |
diffstat | 6 files changed, 29 insertions(+), 111 deletions(-) [+] |
line wrap: on
line diff
--- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,16 @@ +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.
--- 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
--- 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> - -#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 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 <io.h> 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 <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
--- 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 ])
--- 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