bug-gnulib
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

ftruncate on MSVC


From: Bruno Haible
Subject: ftruncate on MSVC
Date: Sun, 25 Sep 2011 14:13:47 +0200
User-agent: KMail/1.13.6 (Linux/2.6.37.6-0.5-desktop; KDE/4.6.0; x86_64; ; )

The chsize() function also crashes for invalid fd on MSVC 9. This works around
it.

We don't need to make the fixed chsize() function public, since the POSIX API
for this functionality is ftruncate().


2011-09-25  Bruno Haible  <address@hidden>

        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.

--- lib/ftruncate.c.orig        Sun Sep 25 14:08:52 2011
+++ lib/ftruncate.c     Sun Sep 25 14:05:37 2011
@@ -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)
 {
--- m4/ftruncate.m4.orig        Sun Sep 25 14:08:52 2011
+++ m4/ftruncate.m4     Sun Sep 25 14:02:34 2011
@@ -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])
 ])
--- modules/ftruncate.orig      Sun Sep 25 14:08:52 2011
+++ modules/ftruncate   Sun Sep 25 13:58:22 2011
@@ -8,6 +8,7 @@
 Depends-on:
 unistd
 largefile
+msvc-inval      [test $HAVE_FTRUNCATE = 0]
 
 configure.ac:
 gl_FUNC_FTRUNCATE
-- 
In memoriam Safia Ahmed-jan <http://en.wikipedia.org/wiki/Safia_Ahmed-jan>



reply via email to

[Prev in Thread] Current Thread [Next in Thread]