return size of file; also returns zero if no file exists
| 2695 | |
| 2696 | // return size of file; also returns zero if no file exists |
| 2697 | unsigned long SystemTools::FileLength(std::string const& filename) |
| 2698 | { |
| 2699 | unsigned long length = 0; |
| 2700 | #ifdef _WIN32 |
| 2701 | WIN32_FILE_ATTRIBUTE_DATA fs; |
| 2702 | if (GetFileAttributesExW(Encoding::ToWindowsExtendedPath(filename).c_str(), |
| 2703 | GetFileExInfoStandard, &fs) != 0) { |
| 2704 | /* To support the full 64-bit file size, use fs.nFileSizeHigh |
| 2705 | * and fs.nFileSizeLow to construct the 64 bit size |
| 2706 | |
| 2707 | length = ((__int64)fs.nFileSizeHigh << 32) + fs.nFileSizeLow; |
| 2708 | */ |
| 2709 | length = static_cast<unsigned long>(fs.nFileSizeLow); |
| 2710 | } |
| 2711 | #else |
| 2712 | struct stat fs; |
| 2713 | if (stat(filename.c_str(), &fs) == 0) { |
| 2714 | length = static_cast<unsigned long>(fs.st_size); |
| 2715 | } |
| 2716 | #endif |
| 2717 | return length; |
| 2718 | } |
| 2719 | |
| 2720 | int SystemTools::Strucmp(char const* l, char const* r) |
| 2721 | { |