static int filefind_index_size_helper(lua_State* L, struct FileFindInfo* info) { #if defined(_WIN32) unsigned __int64 fileSize = 0; if (info->fd.dwFileAttributes & FILE_ATTRIBUTE_REPARSE_POINT) { HANDLE handle; DWORD fileSizeLow; DWORD fileSizeHigh; char* filename = malloc(strlen(info->path) + strlen(info->fd.cFileName) + 1); strcpy(filename, info->path); strcat(filename, info->fd.cFileName); handle = CreateFile(filename, GENERIC_READ, FILE_SHARE_READ | FILE_SHARE_WRITE, NULL, OPEN_EXISTING, 0, NULL); if (handle != INVALID_HANDLE_VALUE) { fileSizeLow = GetFileSize(handle, &fileSizeHigh); fileSize = (unsigned __int64)fileSizeLow + ((unsigned __int64)fileSizeHigh << 32); CloseHandle(handle); } free(filename); } else { fileSize = (unsigned __int64)info->fd.nFileSizeLow + ((unsigned __int64)info->fd.nFileSizeHigh << 32); } lua_pushnumber(L, (lua_Number)ui64ToDouble(fileSize)); #else lua_pushnumber(L, info->attr.st_size); #endif return 1; }
static int _glob_push_FILETIME(lua_State* L, fileglob_uint64 filetime) { lua_newtable(L); lua_pushnumber(L, (lua_Number)ui64ToDouble(filetime & 0xffffffff)); lua_rawseti(L, -2, 1); lua_pushnumber(L, (lua_Number)ui64ToDouble(filetime >> 32)); lua_rawseti(L, -2, 2); return 1; }
static int filefind_index_size_helper(lua_State* L, struct FileFindInfo* info) { #if defined(WIN32) lua_pushnumber(L, (lua_Number)ui64ToDouble((unsigned __int64)info->fd.nFileSizeLow + ((unsigned __int64)info->fd.nFileSizeHigh << 32))); #else lua_pushnumber(L, info->attr.st_size); #endif return 1; }
static int glob_index_size_helper(lua_State* L, struct _fileglob* glob) { lua_pushnumber(L, (lua_Number)ui64ToDouble(fileglob_FileSize(glob))); return 1; }
static int glob_index_write_time_helper(lua_State* L, struct _fileglob* glob) { lua_pushnumber(L, (lua_Number)ui64ToDouble(fileglob_WriteTime(glob))); return 1; }
static int glob_index_number_of_links_helper(lua_State* L, struct _fileglob* glob) { lua_pushnumber(L, (lua_Number)ui64ToDouble(fileglob_NumberOfLinks(glob))); return 1; }
/* * Returns millisecond timing (in seconds) for the current time. * * Note: This function should be called once in single-threaded mode in Win32, * to get it initialized. */ time_d now_secs(void) { #if (defined PLATFORM_WIN32) || (defined PLATFORM_POCKETPC) /* * Windows FILETIME values are "100-nanosecond intervals since * January 1, 1601 (UTC)" (MSDN). Well, we'd want Unix Epoch as * the offset and it seems, so would they: * * <http://msdn.microsoft.com/en-us/library/ms724928(VS.85).aspx> */ SYSTEMTIME st; FILETIME ft; ULARGE_INTEGER uli; static ULARGE_INTEGER uli_epoch; // Jan 1st 1970 0:0:0 if (uli_epoch.HighPart==0) { st.wYear= 1970; st.wMonth= 1; // Jan st.wDay= 1; st.wHour= st.wMinute= st.wSecond= st.wMilliseconds= 0; if (!SystemTimeToFileTime( &st, &ft )) FAIL( "SystemTimeToFileTime", GetLastError() ); uli_epoch.LowPart= ft.dwLowDateTime; uli_epoch.HighPart= ft.dwHighDateTime; } GetSystemTime( &st ); // current system date/time in UTC if (!SystemTimeToFileTime( &st, &ft )) FAIL( "SystemTimeToFileTime", GetLastError() ); uli.LowPart= ft.dwLowDateTime; uli.HighPart= ft.dwHighDateTime; /* 'double' has less accuracy than 64-bit int, but if it were to degrade, * it would do so gracefully. In practise, the integer accuracy is not * of the 100ns class but just 1ms (Windows XP). */ # if 1 #if _MSC_VER && _MSC_VER <= 1300 return (double) (ui64ToDouble(uli.QuadPart - uli_epoch.QuadPart)/10000) / 1000.0; #else // >= 2.0.3 code return (double) ((uli.QuadPart - uli_epoch.QuadPart)/10000) / 1000.0; #endif # elif 0 // fix from Kriss Daniels, see: // <http://luaforge.net/forum/forum.php?thread_id=22704&forum_id=1781> // // "seem to be getting negative numbers from the old version, probably number // conversion clipping, this fixes it and maintains ms resolution" // // This was a bad fix, and caused timer test 5 sec timers to disappear. // --AKa 25-Jan-2009 // return ((double)((signed)((uli.QuadPart/10000) - (uli_epoch.QuadPart/10000)))) / 1000.0; # else // <= 2.0.2 code return (double)(uli.QuadPart - uli_epoch.QuadPart) / 10000000.0; # endif #else struct timeval tv; // { // time_t tv_sec; /* seconds since Jan. 1, 1970 */ // suseconds_t tv_usec; /* and microseconds */ // }; int rc= gettimeofday( &tv, NULL /*time zone not used any more (in Linux)*/ ); assert( rc==0 ); return ((double)tv.tv_sec) + ((tv.tv_usec)/1000) / 1000.0; #endif }