[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
fseek and ftell with large files on Windows
From: |
Markus Mützel |
Subject: |
fseek and ftell with large files on Windows |
Date: |
Mon, 11 Nov 2024 15:31:56 +0000 |
Octave is using gnulib's "fseek" and "ftell" functions. A user reported that
they have issues when using these functions with large files on Windows:
https://savannah.gnu.org/bugs/index.php?66399
If I understand the code paths for Windows correctly, the issue might be caused
by the fact that the "fseek" and "ftell" functions are forwarding to
"_fseeki64" or "_ftelli64", respectively, if the size of the "off_t" type is
smaller than 64-bit. They are forwarding to "fseek" and "ftell" otherwise.
However, even if the "off_t" type is 64-bit (or larger), "fseek" and "ftell"
still return "long" on Windows which is only 32-bit wide:
https://learn.microsoft.com/en-us/cpp/c-runtime-library/reference/ftell-ftelli64?view=msvc-170
The following change avoids the issue described in the above bug report for me.
I don't know whether that change is correct though.
Thank you,
Markus
diff --git a/lib/fseeko.c b/lib/fseeko.c
index 2c3b053a3b..30f8f70afe 100644
--- a/lib/fseeko.c
+++ b/lib/fseeko.c
@@ -31,7 +31,7 @@ fseeko (FILE *fp, off_t offset, int whence)
# undef fseek
# define fseeko fseek
#endif
-#if _GL_WINDOWS_64_BIT_OFF_T
+#if _WIN32
# undef fseeko
# if HAVE__FSEEKI64 && HAVE_DECL__FSEEKI64 /* msvc, mingw since
msvcrt8.0, mingw64 */
# define fseeko _fseeki64
diff --git a/lib/ftello.c b/lib/ftello.c
index 88247bca8e..2f83c61c0e 100644
--- a/lib/ftello.c
+++ b/lib/ftello.c
@@ -34,7 +34,7 @@ ftello (FILE *fp)
# undef ftell
# define ftello ftell
#endif
-#if _GL_WINDOWS_64_BIT_OFF_T
+#if _WIN32
# undef ftello
# if HAVE__FTELLI64 /* msvc, mingw64 */
# define ftello _ftelli64
- fseek and ftell with large files on Windows,
Markus Mützel <=
- Re: fseek and ftell with large files on Windows, Bruno Haible, 2024/11/11
- Re: fseek and ftell with large files on Windows, Markus Mützel, 2024/11/12
- Re: fseek and ftell with large files on Windows, Bruno Haible, 2024/11/12
- Re: fseek and ftell with large files on Windows, Markus Mützel, 2024/11/13
- Re: fseek and ftell with large files on Windows, Bruno Haible, 2024/11/13
- Re: fseek and ftell with large files on Windows, Bruno Haible, 2024/11/13
- Re: fseek and ftell with large files on Windows, Markus Mützel, 2024/11/14
- Re: fseek and ftell with large files on Windows, Bruno Haible, 2024/11/14
- Re: fseek and ftell with large files on Windows, Markus Mützel, 2024/11/14
- Re: fseek and ftell with large files on Windows, Bruno Haible, 2024/11/14