lua-users home
lua-l archive

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

Forgive me if this is a FAQ.

Can "regular" FILE* objects (e.g. the sort built on Linux when you do _not_ #define _FILE_OFFSET_BITS 64) be passed into fseeko64 (_fseeki64 on Windows) and ftello64 (_ftelli64 on Windows)?

In other words, is it enough to "bigfileify" the io library by changing _only_ the f_seek() function in libiolib.c like this:

---diff -U 5---
 static int f_seek (lua_State *L) {
   static const int mode[] = {SEEK_SET, SEEK_CUR, SEEK_END};
   static const char *const modenames[] = {"set", "cur", "end", NULL};
   FILE *f = tofile(L);
   int op = luaL_checkoption(L, 2, "cur", modenames);
-  long offset = luaL_optlong(L, 3, 0);
-  op = fseek(f, offset, mode[op]);
+  long long offset = (long long)luaL_optnumber(L, 3, 0);
+  op = fseeko64(f, offset, mode[op]);
   if (op)
     return pushresult(L, 0, NULL);  /* error */
   else {
-    lua_pushinteger(L, ftell(f));
+    lua_pushnumber(L, (lua_Number)ftello64(f));
     return 1;
---diff -U 5---

Or do you need to compile everything with _FILE_OFFSET_BITS = 64 in order to get FILE* objects to tolerate being operated upon with 64-bit offsets?