| 42 | using std::string; |
| 43 | |
| 44 | bool GetDateModifiedString(const char *file_name, char *buffer, int buffer_size) { |
| 45 | #ifdef _WIN32 |
| 46 | struct _stat buf; |
| 47 | int result; |
| 48 | char timebuf[26]; |
| 49 | errno_t err; |
| 50 | |
| 51 | // Get data associated with "crt_stat.c": |
| 52 | const int buf_size = 2048; |
| 53 | WCHAR path_utf16[buf_size]; |
| 54 | if (!MultiByteToWideChar(CP_UTF8, 0, file_name, -1, path_utf16, buf_size)) { |
| 55 | #ifndef NO_ERR |
| 56 | FatalError("Error", "Error converting utf8 string to utf16: %s", file_name); |
| 57 | #endif |
| 58 | } |
| 59 | result = _wstat(path_utf16, &buf); |
| 60 | |
| 61 | // Check if statistics are valid: |
| 62 | while (result != 0) { |
| 63 | #ifndef NO_ERR |
| 64 | string error = "Could not find: " + string(file_name); |
| 65 | ErrorResponse response = DisplayError("Error", error.c_str(), _ok_cancel_retry); |
| 66 | if (response == _retry) { |
| 67 | result = _wstat(path_utf16, &buf); |
| 68 | } else if (response == _continue) { |
| 69 | return false; |
| 70 | } |
| 71 | #else |
| 72 | return false; |
| 73 | #endif |
| 74 | } |
| 75 | |
| 76 | err = ctime_s(timebuf, 26, &buf.st_mtime); |
| 77 | if (err) { |
| 78 | #ifndef NO_ERR |
| 79 | DisplayError("Error", "Problem getting date modified string."); |
| 80 | #endif |
| 81 | return false; |
| 82 | } |
| 83 | strncpy(buffer, timebuf, buffer_size); |
| 84 | return true; |
| 85 | |
| 86 | #else // standard unix implementation |
| 87 | struct stat buf; |
| 88 | int result; |
| 89 | char timebuf[26]; |
| 90 | |
| 91 | // Get data associated with "crt_stat.c": |
| 92 | const char *path = file_name; |
| 93 | result = stat(path, &buf); |
| 94 | |
| 95 | // Check if statistics are valid: |
| 96 | if (result != 0) { |
| 97 | const int BUF_SIZE = 512; |
| 98 | char err_buf[BUF_SIZE]; |
| 99 | #ifndef NO_ERR |
| 100 | if (errno == ENOENT) { |
| 101 | snprintf(err_buf, BUF_SIZE, "The file doesn't exist: %s", file_name); |
nothing calls this directly
no test coverage detected