changeset 15782:402bb52d5f11

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.
author Bruno Haible <bruno@clisp.org>
date Sun, 25 Sep 2011 14:10:58 +0200
parents 16f47458947e
children 4b59b93e3c12
files ChangeLog lib/ftruncate.c m4/ftruncate.m4 modules/ftruncate
diffstat 4 files changed, 36 insertions(+), 1 deletions(-) [+]
line wrap: on
line diff
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,12 @@
+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'.
--- 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)
 {
--- 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 @@
 # Prerequisites of lib/ftruncate.c.
 AC_DEFUN([gl_PREREQ_FTRUNCATE],
 [
+  AC_REQUIRE([AC_C_INLINE])
   AC_CHECK_FUNCS([chsize])
 ])
--- a/modules/ftruncate
+++ b/modules/ftruncate
@@ -8,6 +8,7 @@
 Depends-on:
 unistd
 largefile
+msvc-inval      [test $HAVE_FTRUNCATE = 0]
 
 configure.ac:
 gl_FUNC_FTRUNCATE