| 29 | #endif // _WIN32 |
| 30 | |
| 31 | size_t getFileSize(const std::string& path) |
| 32 | { |
| 33 | #ifdef _WIN32 |
| 34 | CW2T pszT(CA2W(path.c_str(), CP_UTF8)); |
| 35 | HANDLE hFile = CreateFile((LPCTSTR)pszT, GENERIC_READ, |
| 36 | FILE_SHARE_READ | FILE_SHARE_WRITE, NULL, OPEN_EXISTING, |
| 37 | FILE_ATTRIBUTE_NORMAL, NULL); |
| 38 | if (hFile == INVALID_HANDLE_VALUE) |
| 39 | return -1; // error condition, could call GetLastError to find out more |
| 40 | |
| 41 | LARGE_INTEGER size; |
| 42 | if (!GetFileSizeEx(hFile, &size)) |
| 43 | { |
| 44 | CloseHandle(hFile); |
| 45 | return -1; // error condition, could call GetLastError to find out more |
| 46 | } |
| 47 | |
| 48 | CloseHandle(hFile); |
| 49 | return (size_t)size.QuadPart; |
| 50 | #else |
| 51 | struct stat sb; |
| 52 | int rc = stat(path.c_str(), &sb); |
| 53 | return rc == 0 ? sb.st_size : -1; |
| 54 | #endif |
| 55 | } |
| 56 | |
| 57 | bool existsDirectory(const std::string& path) |
| 58 | { |