static int filefind_tostring(lua_State *L) { struct FileFindInfo* info = filefind_checkmetatable(L, 1); char buffer[100]; int top; #if defined(_WIN32) if (info->handle == INVALID_HANDLE_VALUE) { lua_pushstring(L, "[filefind object]: empty"); return 1; } top = lua_gettop(L); lua_pushstring(L, "[filefind object]: filename = \""); lua_pushstring(L, info->fd.cFileName); lua_pushstring(L, "\""); sprintf(buffer, ", creation_time = %u", fileglob_ConvertToTime_t(&info->fd.ftCreationTime)); lua_pushstring(L, buffer); sprintf(buffer, ", access_time = %u", fileglob_ConvertToTime_t(&info->fd.ftLastAccessTime)); lua_pushstring(L, buffer); sprintf(buffer, ", write_time = %u", fileglob_ConvertToTime_t(&info->fd.ftLastWriteTime)); lua_pushstring(L, buffer); sprintf(buffer, ", creation_FILETIME = { %u, %u }", info->fd.ftCreationTime.dwLowDateTime, info->fd.ftCreationTime.dwHighDateTime); lua_pushstring(L, buffer); sprintf(buffer, ", access_FILETIME = { %u, %u }", info->fd.ftLastAccessTime.dwLowDateTime, info->fd.ftLastAccessTime.dwHighDateTime); lua_pushstring(L, buffer); sprintf(buffer, ", write_FILETIME = { %u, %u }", info->fd.ftLastWriteTime.dwLowDateTime, info->fd.ftLastWriteTime.dwHighDateTime); lua_pushstring(L, buffer); sprintf(buffer, ", size = %I64d", ((unsigned __int64)info->fd.nFileSizeLow + ((unsigned __int64)info->fd.nFileSizeHigh << 32))); lua_pushstring(L, buffer); sprintf(buffer, ", is_directory = %s", (info->fd.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) != 0 ? "true" : "false"); lua_pushstring(L, buffer); sprintf(buffer, ", is_link = %s", (info->fd.dwFileAttributes & FILE_ATTRIBUTE_REPARSE_POINT) != 0 ? "true" : "false"); lua_pushstring(L, buffer); sprintf(buffer, ", is_readonly = %s", (info->fd.dwFileAttributes & FILE_ATTRIBUTE_READONLY) ? "true" : "false"); lua_pushstring(L, buffer); filefind_index_number_of_links_helper(L, info); sprintf(buffer, ", number_of_links = %d", lua_tointeger(L, -1)); lua_pop(L, 1); lua_pushstring(L, buffer); lua_concat(L, lua_gettop(L) - top); return 1; #else return 0; #endif }
static int filefind_index_write_time_helper(lua_State* L, struct FileFindInfo* info) { #if defined(WIN32) lua_pushnumber(L, (lua_Number)fileglob_ConvertToTime_t(&info->fd.ftLastWriteTime)); #else lua_pushnumber(L, info->attr.st_mtime); #endif return 1; }
fileglob_uint64 fileglob_WriteTime(fileglob* self) { #if defined(WIN32) if (self->context->handle != INVALID_HANDLE_VALUE) { return fileglob_ConvertToTime_t(&self->context->fd.ftLastWriteTime); } #else if (self->context->dirp) { if (!self->context->hasattr) { stat(fileglob_FileName(self), &self->context->attr); self->context->hasattr = 1; } return self->context->attr.st_mtime; } #endif return 0; }