Am Montag, 11. November 2024 um 19:50 schrieb "Bruno Haible":
> Hi,
> 
> Markus Mützel wrote:
> > 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
> 
> This is explained in the Gnulib documentation:
> https://www.gnu.org/software/gnulib/manual/html_node/fseek.html
> https://www.gnu.org/software/gnulib/manual/html_node/ftell.html
> 

Thank you for the clarification. And sorry for being slightly confused when I 
wrote the initial email:
The Octave functions that are being called in the reproducer are named "fseek" 
and "ftell". But the gnulib functions that are called internally are "fseeko" 
and "ftello". If I understood Paul Eggert in that bug report correctly, he 
found at least one place where Octave is using "fseek" instead of "fseeko".
But stepping through with a debugger, - at least in the code paths that 
reproduce the issue - "fseeko" and "ftello" are used as far as I can tell.

> > If I understand the code paths for Windows correctly
> 
> It's not specific to Windows. You get the same effects on all 32-bit 
platforms
> as well.
> 
> > 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
> 
> This patch cannot help, since the problem is with using a 'long' as 
offset. Gnulib
> can't change that, since the prototype of fseek and ftell is specified by 
ISO C.

Octave is using 'off_t' as offset when calling "fseeko". Checking the content 
of the generated "sys/types.h" header, I see the following:

/* Override off_t if Large File Support is requested on native Windows.  */
#if 0
/* Same as int64_t in <stdint.h>.  */
# if defined _MSC_VER
#  define off_t __int64
# else
#  define off_t long long int
# endif
/* Indicator, for gnulib internal purposes.  */
# define _GL_WINDOWS_64_BIT_OFF_T 1
#endif

If I understand correctly, the fact that this section is skipped means that 
'off_t' has a 64-bit size here (on mingw-w64) and doesn't need to be redefined.

Looping back to the previously proposed changes for "fseeko.c" and "fseeko.c": 
In the current version 'fseeko' is defined to 'fseek' for the function body. 
But 'fseek' uses an offset that is of type 'long' on Windows. So, it won't work 
with large files.
With the proposed changes, 'fseeko' would be defined to '_fseeki64' for the 
function body. (And similar changes for "ftello.c".) Isn't that needed for 
large files on Windows?

Markus
</stdint.h>

Reply via email to