summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBruno Haible <bruno@clisp.org>2011-09-25 14:10:58 +0200
committerBruno Haible <bruno@clisp.org>2011-09-25 14:10:58 +0200
commit5d91e956e6cca4176be51f9591ac00a189b7df00 (patch)
tree0ee049770af20ee605888e9c8808e63e39d618c4
parentcd76a061a80d91823660fc999727c6ec5f4a067b (diff)
downloadgnulib-5d91e956e6cca4176be51f9591ac00a189b7df00.tar.gz
ftruncate: Support for MSVC 9.
* lib/ftruncate.c: Include errno.h, msvc-inval.h. (chsize_nothrow): New function. (chsize): Redefine as a macro. * m4/ftruncate.m4 (gl_PREREQ_FTRUNCATE): Require AC_C_INLINE. * modules/ftruncate (Depends-on): Add msvc-inval.
-rw-r--r--ChangeLog9
-rw-r--r--lib/ftruncate.c24
-rw-r--r--m4/ftruncate.m43
-rw-r--r--modules/ftruncate1
4 files changed, 36 insertions, 1 deletions
diff --git a/ChangeLog b/ChangeLog
index c7bc060ee7..12ef00a68b 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,14 @@
2011-09-25 Bruno Haible <bruno@clisp.org>
+ ftruncate: Support for MSVC 9.
+ * lib/ftruncate.c: Include errno.h, msvc-inval.h.
+ (chsize_nothrow): New function.
+ (chsize): Redefine as a macro.
+ * m4/ftruncate.m4 (gl_PREREQ_FTRUNCATE): Require AC_C_INLINE.
+ * modules/ftruncate (Depends-on): Add msvc-inval.
+
+2011-09-25 Bruno Haible <bruno@clisp.org>
+
New module 'fstat'.
* lib/sys_stat.in.h (fstat): Declare only if GNULIB_FSTAT is set.
* lib/fstat.c: New file, based on a piece of lib/fchdir.c.
diff --git a/lib/ftruncate.c b/lib/ftruncate.c
index d5a3be144c..ae1e85890c 100644
--- a/lib/ftruncate.c
+++ b/lib/ftruncate.c
@@ -8,8 +8,32 @@
#if HAVE_CHSIZE
+# include <errno.h>
# include <io.h>
+# if HAVE_MSVC_INVALID_PARAMETER_HANDLER
+# include "msvc-inval.h"
+static inline 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)
{
diff --git a/m4/ftruncate.m4 b/m4/ftruncate.m4
index 42730907a6..4a47ba4297 100644
--- a/m4/ftruncate.m4
+++ b/m4/ftruncate.m4
@@ -1,4 +1,4 @@
-# serial 17
+# serial 18
# See if we need to emulate a missing ftruncate function using chsize.
@@ -19,5 +19,6 @@ AC_DEFUN([gl_FUNC_FTRUNCATE],
# Prerequisites of lib/ftruncate.c.
AC_DEFUN([gl_PREREQ_FTRUNCATE],
[
+ AC_REQUIRE([AC_C_INLINE])
AC_CHECK_FUNCS([chsize])
])
diff --git a/modules/ftruncate b/modules/ftruncate
index 3bea20be3b..097ed9c770 100644
--- a/modules/ftruncate
+++ b/modules/ftruncate
@@ -8,6 +8,7 @@ m4/ftruncate.m4
Depends-on:
unistd
largefile
+msvc-inval [test $HAVE_FTRUNCATE = 0]
configure.ac:
gl_FUNC_FTRUNCATE