this repo has no description
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

Fix the error 'folder <folder> doesn't exist' under Windows XP (#2558)

authored by

Alice and committed by
GitHub
49111447 deae9c68

+51 -1
+51 -1
src/studio/fs.c
··· 158 158 return str; 159 159 } 160 160 161 + time_t FileTimeToTimeT(FILETIME* ft) { 162 + ULARGE_INTEGER ull; 163 + ull.LowPart = ft->dwLowDateTime; 164 + ull.HighPart = ft->dwHighDateTime; 165 + return (time_t)((ull.QuadPart / 10000000ULL) - 11644473600ULL); 166 + } 167 + 168 + // There is a bug in the toolchain when compiling with v141_xp 169 + // This shim is a workaround for that, using GetFileAttributesEx 170 + // see https://stackoverflow.com/questions/32452777/visual-c-2015-express-stat-not-working-on-windows-xp 171 + static int _wstat_win32_shim(const wchar_t* path, struct _stat* buffer) 172 + { 173 + WIN32_FILE_ATTRIBUTE_DATA fileInfo; 174 + if (!GetFileAttributesExW(path, GetFileExInfoStandard, &fileInfo)) 175 + { 176 + return -1; 177 + } 178 + 179 + memset(buffer, 0, sizeof(struct _stat)); 180 + 181 + buffer->st_mode = _S_IREAD; 182 + if (!(fileInfo.dwFileAttributes & FILE_ATTRIBUTE_READONLY)) 183 + { 184 + buffer->st_mode |= _S_IWRITE; 185 + } 186 + if (fileInfo.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) 187 + { 188 + buffer->st_mode |= _S_IFDIR; 189 + } 190 + else 191 + { 192 + buffer->st_mode |= _S_IFREG; 193 + } 194 + 195 + // Set the file size 196 + buffer->st_size = ((_off_t)fileInfo.nFileSizeHigh << 32) | fileInfo.nFileSizeLow; 197 + 198 + // Set the file times 199 + buffer->st_mtime = FileTimeToTimeT(&fileInfo.ftLastWriteTime); 200 + buffer->st_atime = FileTimeToTimeT(&fileInfo.ftLastAccessTime); 201 + buffer->st_ctime = FileTimeToTimeT(&fileInfo.ftCreationTime); 202 + return 0; 203 + } 204 + 161 205 #define freeString(S) free((void*)S) 162 206 163 207 ··· 169 213 #define tic_readdir _wreaddir 170 214 #define tic_closedir _wclosedir 171 215 #define tic_rmdir _wrmdir 172 - #define tic_stat _wstat 216 + 217 + // use the shim (see above) if we're targeting Windows XP 218 + #if defined(_MSC_VER) && defined(_USING_V110_SDK71_) 219 + #define tic_stat _wstat_win32_shim 220 + #else 221 + #define tic_stat _wstat 222 + #endif 173 223 #define tic_remove _wremove 174 224 #define tic_fopen _wfopen 175 225 #define tic_mkdir(name) _wmkdir(name)