local ffi = require("ffi")
ffi.cdef[[
typedef struct stat {
int st_dev;
int st_ino;
int st_mode;
int st_nlink;
int st_uid;
int st_gid;
int st_rdev;
long st_size;
long st_atime;
long st_mtime;
long st_ctime;
}stat;
int stat(const char *path, stat *buf);
]]
function get_file_size(path)
local stat_buf = ffi.new("stat")
local res = ffi.C.stat(path, stat_buf)
if res == 0 then
return tonumber(stat_buf.st_size)
else
return nil, "error: " .. ffi.errno()
end
end