file:seek("end") returns -1 on big files

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
5 messages Options
Reply | Threaded
Open this post in threaded view
|

file:seek("end") returns -1 on big files

Shmuel Zeigerman
Hello,

When I call file:seek("end") on a file which size is 4000 megabytes it
returns -1.

This occurs with all versions of Lua 5.1-5.4 compiled with MinGW on
Windows 10.

LuaJIT 2.1.0-beta3 (also compiled with MinGW) returns the correct value
4194304000.

--
Shmuel
Reply | Threaded
Open this post in threaded view
|

Re: file:seek("end") returns -1 on big files

Paul K-2
Hi Shmuel,

I have this patch in my Lua makefile:

    # need to patch Lua io to support large (>2GB) files on Windows:
    # http://lua-users.org/lists/lua-l/2015-05/msg00370.html
    cat <<EOF >>src/luaconf.h
#if defined(liolib_c) && defined(__MINGW32__)
#include <sys/types.h>
#define l_fseek(f,o,w) fseeko64(f,o,w)
#define l_ftell(f) ftello64(f)
#define l_seeknum off64_t
#endif
EOF

See the earlier discussion on this topic:
http://lua-users.org/lists/lua-l/2015-05/msg00315.html

Paul.

On Sun, Feb 28, 2021 at 11:36 AM Shmuel Zeigerman <[hidden email]> wrote:

>
> Hello,
>
> When I call file:seek("end") on a file which size is 4000 megabytes it
> returns -1.
>
> This occurs with all versions of Lua 5.1-5.4 compiled with MinGW on
> Windows 10.
>
> LuaJIT 2.1.0-beta3 (also compiled with MinGW) returns the correct value
> 4194304000.
>
> --
> Shmuel
Reply | Threaded
Open this post in threaded view
|

Re: file:seek("end") returns -1 on big files

Shmuel Zeigerman
On 28/02/2021 21:44, Paul K wrote:
> See the earlier discussion on this topic:
> http://lua-users.org/lists/lua-l/2015-05/msg00315.html
>

Thanks Paul.
It is sad it doesn't work out-of-the-box.

--
Shmuel
Reply | Threaded
Open this post in threaded view
|

Re: file:seek("end") returns -1 on big files

Roberto Ierusalimschy
In reply to this post by Paul K-2
> I have this patch in my Lua makefile:
>
>     # need to patch Lua io to support large (>2GB) files on Windows:
>     # http://lua-users.org/lists/lua-l/2015-05/msg00370.html
>     cat <<EOF >>src/luaconf.h
> #if defined(liolib_c) && defined(__MINGW32__)
> #include <sys/types.h>
> #define l_fseek(f,o,w) fseeko64(f,o,w)
> #define l_ftell(f) ftello64(f)
> #define l_seeknum off64_t
> #endif
> EOF
>
> See the earlier discussion on this topic:
> http://lua-users.org/lists/lua-l/2015-05/msg00315.html

At the end of that discussion, we suggested using functions POSIX-named
(fseeko, ftello, off_t), while here you are using fseeko64, ftello64,
off64_t. What are the pros/cons of each of these choices?

-- Roberto
Reply | Threaded
Open this post in threaded view
|

Re: file:seek("end") returns -1 on big files

Paul K-2
Hi Roberto,

> At the end of that discussion, we suggested using functions POSIX-named
> (fseeko, ftello, off_t), while here you are using fseeko64, ftello64,
> off64_t. What are the pros/cons of each of these choices?

My vague recollection is that when the patch was made, I started with
your suggested change, but had a problem with the compiler not finding
*o functions, while *o64 functions were available (similar to the
symptoms discussed in this thread:
https://sourceforge.net/p/mingw/mailman/mingw-users/thread/49CB69BE.9040909%40laposte.net/#msg21936228).
I can't reproduce it with either mingw/gcc 9.2.0 or tdm/gcc 4.8.1 I
have access to, so it was probably related to some old version of
mingw/gcc I had at that time.

Paul.

On Mon, Mar 1, 2021 at 6:19 AM Roberto Ierusalimschy
<[hidden email]> wrote:

>
> > I have this patch in my Lua makefile:
> >
> >     # need to patch Lua io to support large (>2GB) files on Windows:
> >     # http://lua-users.org/lists/lua-l/2015-05/msg00370.html
> >     cat <<EOF >>src/luaconf.h
> > #if defined(liolib_c) && defined(__MINGW32__)
> > #include <sys/types.h>
> > #define l_fseek(f,o,w) fseeko64(f,o,w)
> > #define l_ftell(f) ftello64(f)
> > #define l_seeknum off64_t
> > #endif
> > EOF
> >
> > See the earlier discussion on this topic:
> > http://lua-users.org/lists/lua-l/2015-05/msg00315.html
>
> At the end of that discussion, we suggested using functions POSIX-named
> (fseeko, ftello, off_t), while here you are using fseeko64, ftello64,
> off64_t. What are the pros/cons of each of these choices?
>
> -- Roberto