I haven't checked for the time of last access, etc. but as for st_mode and st_size I'm sure there is a problem.
st_mode cannot be exploited to determine whether it's a directory or not with the usual macro S_ISDIR (it always returns 0); however I managed to find the method "elem->d_type == DT_DIR", where elem is the dirent struct, which is working properly.
st_size doesn't give the actual size; in the root (accessed using "/") the size of every item (directories and files) is 34049932, and on some others it comes to 0.
As said above, when I stat in the current working directory, S_ISDIR works fine and the given size is correct.
Here is my code if it can help:
Code: Select all
struct dirent *elem;
struct stat st;
const char *dirName = luaL_checkstring(L, 1); // luaL_checkstring() just gives the name of the folder to be listed
DIR *dir = opendir(dirName);
while ((elem = readdir(dir))) {
lua_pushstring(L, elem->d_name);
lua_pushboolean(L, elem->d_type == DT_DIR);
stat(elem->d_name, &st);
lua_pushnumber(L, st.st_size);
}
I gladly thank you for any help about this as it is a major bug in my project.