lua-users home
lua-l archive

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


Dimiter 'malkia' Stanev <malkia@gmail.com> wrote:

> > Would be acceptable to include a workaround so that one could enable
> > support for such large files (someone mentioned fseek64) just using an
> > option in luaconf.h, say #define USE_FSEEK64?
> 
> LuaJIT has support for 64-bit seeks.
> 
> #if LJ_TARGET_POSIX
>    res = fseeko(fp, ofs, opt);
> #elif _MSC_VER >= 1400
>    res = _fseeki64(fp, ofs, opt);
> #elif defined(__MINGW32__)
>    res = fseeko64(fp, ofs, opt);
> #else
>    res = fseek(fp, (long)ofs, opt);
> #endif
>    if (res)
>      return io_pushresult(L, 0, NULL);
> #if LJ_TARGET_POSIX
>    ofs = ftello(fp);
> #elif _MSC_VER >= 1400
>    ofs = _ftelli64(fp);
> #elif defined(__MINGW32__)
>    ofs = ftello64(fp);
> #else
>    ofs = (int64_t)ftell(fp);
> #endif
> 
> Actually I had to disable that for my library builds for Windows as I 
> want to link with MSVCRT.DLL and XP's MSVCRT.DLL (not MSVCR80, MSVCR90, 
> etc.) does not have _ftelli64 (or was it _fseeki64), and although there 
> is _telli64 (or _seeki64) it cannot be reused for file-handles through 
> the means of fileno() because it would differ and it's just not safe.

I was trying to do the same (ie linking LuaJIT2 with MSVCRT.DLL) and I
solved this specific problem via the CRT functions fgetpos() and
fsetpos(). Have a look at these; as far as I can tell they do work with
streams, so it should be possible to implement a local variant of
fseek() with them.

-- 
cheers  thomasl