bug-gnulib
[Top][All Lists]
Advanced

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

ftruncate: Accept lengths > 2 GiB on 32-bit mingw


From: Bruno Haible
Subject: ftruncate: Accept lengths > 2 GiB on 32-bit mingw
Date: Thu, 14 Nov 2024 04:39:12 +0100

ftruncate() takes an off_t argument. On mingw-w64, this is 64-bits wide;
the module 'largefile' does not need to override off_t. Still, in this
situation, it is wrong to use _chsize() since that takes only a 32-bit
argument.

This patch fixes it.


2024-11-14  Bruno Haible  <bruno@clisp.org>

        ftruncate: Accept lengths > 2 GiB on 32-bit mingw.
        * lib/ftruncate.c: Test whether module 'largefile' is in use, not
        whether it had to override 'off_t'.

diff --git a/lib/ftruncate.c b/lib/ftruncate.c
index 6394725781..0566c32d0e 100644
--- a/lib/ftruncate.c
+++ b/lib/ftruncate.c
@@ -24,10 +24,12 @@
 
 # include <errno.h>
 
-# if _GL_WINDOWS_64_BIT_OFF_T
+# if _FILE_OFFSET_BITS == 64 /* set by module 'largefile' on all platforms */
 
 /* Large File Support: off_t is 64-bit, but _chsize() takes only a 32-bit
-   argument.  So, define a 64-bit safe SetFileSize function ourselves.  */
+   argument.  Some newer versions of the Windows CRT have a _chsize_s function
+   that takes a 64-bit argument, but we cannot rely on that.
+   So, define a 64-bit safe SetFileSize function ourselves.  */
 
 /* Ensure that <windows.h> declares GetFileSizeEx.  */
 #  if !defined _WIN32_WINNT || (_WIN32_WINNT < _WIN32_WINNT_WIN2K)






reply via email to

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