Fossil SCM
Use SetCurrentDirectoryW/GetFileAttributesExW in stead of _wchdir/_wstati64 (which cannot handle long pathnames)
Commit
3714782631607e930dff33f7c544c857ec606e3a
Parent
cf9293ad53b2717…
1 file changed
+18
-3
+18
-3
| --- src/file.c | ||
| +++ src/file.c | ||
| @@ -47,11 +47,16 @@ | ||
| 47 | 47 | ** Use _stati64 rather than stat on windows, in order to handle files |
| 48 | 48 | ** larger than 2GB. |
| 49 | 49 | */ |
| 50 | 50 | #if defined(_WIN32) && (defined(__MSVCRT__) || defined(_MSC_VER)) |
| 51 | 51 | # undef stat |
| 52 | -# define stat _stati64 | |
| 52 | +# define stat _fossil_stati64 | |
| 53 | +struct stat { | |
| 54 | + i64 st_size; | |
| 55 | + i64 st_mtime; | |
| 56 | + int st_mode; | |
| 57 | +}; | |
| 53 | 58 | #endif |
| 54 | 59 | /* |
| 55 | 60 | ** On Windows S_ISLNK always returns FALSE. |
| 56 | 61 | */ |
| 57 | 62 | #if !defined(S_ISLNK) |
| @@ -73,12 +78,22 @@ | ||
| 73 | 78 | rc = lstat(zMbcs, buf); |
| 74 | 79 | }else{ |
| 75 | 80 | rc = stat(zMbcs, buf); |
| 76 | 81 | } |
| 77 | 82 | #else |
| 83 | + WIN32_FILE_ATTRIBUTE_DATA attr; | |
| 78 | 84 | wchar_t *zMbcs = fossil_utf8_to_filename(zFilename); |
| 79 | - rc = _wstati64(zMbcs, buf); | |
| 85 | + rc = !GetFileAttributesExW(zMbcs, GetFileExInfoStandard, &attr); | |
| 86 | + if( !rc ){ | |
| 87 | + ULARGE_INTEGER ull; | |
| 88 | + ull.LowPart = attr.ftLastWriteTime.dwLowDateTime; | |
| 89 | + ull.HighPart = attr.ftLastWriteTime.dwHighDateTime; | |
| 90 | + buf->st_mode = (attr.dwFileAttributes&FILE_ATTRIBUTE_DIRECTORY)? | |
| 91 | + S_IFDIR:S_IFREG; | |
| 92 | + buf->st_size = (((i64)attr.nFileSizeHigh)<<32) | attr.nFileSizeLow; | |
| 93 | + buf->st_mtime = ull.QuadPart / 10000000ULL - 11644473600ULL; | |
| 94 | + } | |
| 80 | 95 | #endif |
| 81 | 96 | fossil_filename_free(zMbcs); |
| 82 | 97 | return rc; |
| 83 | 98 | } |
| 84 | 99 | |
| @@ -321,11 +336,11 @@ | ||
| 321 | 336 | ** (UNIX only) |
| 322 | 337 | */ |
| 323 | 338 | int file_chdir(const char *zChDir, int bChroot){ |
| 324 | 339 | #ifdef _WIN32 |
| 325 | 340 | wchar_t *zPath = fossil_utf8_to_filename(zChDir); |
| 326 | - int rc = _wchdir(zPath); | |
| 341 | + int rc = SetCurrentDirectoryW(zPath)==0; | |
| 327 | 342 | #else |
| 328 | 343 | char *zPath = fossil_utf8_to_filename(zChDir); |
| 329 | 344 | int rc = chdir(zPath); |
| 330 | 345 | if( !rc && bChroot ){ |
| 331 | 346 | rc = chroot(zPath); |
| 332 | 347 |
| --- src/file.c | |
| +++ src/file.c | |
| @@ -47,11 +47,16 @@ | |
| 47 | ** Use _stati64 rather than stat on windows, in order to handle files |
| 48 | ** larger than 2GB. |
| 49 | */ |
| 50 | #if defined(_WIN32) && (defined(__MSVCRT__) || defined(_MSC_VER)) |
| 51 | # undef stat |
| 52 | # define stat _stati64 |
| 53 | #endif |
| 54 | /* |
| 55 | ** On Windows S_ISLNK always returns FALSE. |
| 56 | */ |
| 57 | #if !defined(S_ISLNK) |
| @@ -73,12 +78,22 @@ | |
| 73 | rc = lstat(zMbcs, buf); |
| 74 | }else{ |
| 75 | rc = stat(zMbcs, buf); |
| 76 | } |
| 77 | #else |
| 78 | wchar_t *zMbcs = fossil_utf8_to_filename(zFilename); |
| 79 | rc = _wstati64(zMbcs, buf); |
| 80 | #endif |
| 81 | fossil_filename_free(zMbcs); |
| 82 | return rc; |
| 83 | } |
| 84 | |
| @@ -321,11 +336,11 @@ | |
| 321 | ** (UNIX only) |
| 322 | */ |
| 323 | int file_chdir(const char *zChDir, int bChroot){ |
| 324 | #ifdef _WIN32 |
| 325 | wchar_t *zPath = fossil_utf8_to_filename(zChDir); |
| 326 | int rc = _wchdir(zPath); |
| 327 | #else |
| 328 | char *zPath = fossil_utf8_to_filename(zChDir); |
| 329 | int rc = chdir(zPath); |
| 330 | if( !rc && bChroot ){ |
| 331 | rc = chroot(zPath); |
| 332 |
| --- src/file.c | |
| +++ src/file.c | |
| @@ -47,11 +47,16 @@ | |
| 47 | ** Use _stati64 rather than stat on windows, in order to handle files |
| 48 | ** larger than 2GB. |
| 49 | */ |
| 50 | #if defined(_WIN32) && (defined(__MSVCRT__) || defined(_MSC_VER)) |
| 51 | # undef stat |
| 52 | # define stat _fossil_stati64 |
| 53 | struct stat { |
| 54 | i64 st_size; |
| 55 | i64 st_mtime; |
| 56 | int st_mode; |
| 57 | }; |
| 58 | #endif |
| 59 | /* |
| 60 | ** On Windows S_ISLNK always returns FALSE. |
| 61 | */ |
| 62 | #if !defined(S_ISLNK) |
| @@ -73,12 +78,22 @@ | |
| 78 | rc = lstat(zMbcs, buf); |
| 79 | }else{ |
| 80 | rc = stat(zMbcs, buf); |
| 81 | } |
| 82 | #else |
| 83 | WIN32_FILE_ATTRIBUTE_DATA attr; |
| 84 | wchar_t *zMbcs = fossil_utf8_to_filename(zFilename); |
| 85 | rc = !GetFileAttributesExW(zMbcs, GetFileExInfoStandard, &attr); |
| 86 | if( !rc ){ |
| 87 | ULARGE_INTEGER ull; |
| 88 | ull.LowPart = attr.ftLastWriteTime.dwLowDateTime; |
| 89 | ull.HighPart = attr.ftLastWriteTime.dwHighDateTime; |
| 90 | buf->st_mode = (attr.dwFileAttributes&FILE_ATTRIBUTE_DIRECTORY)? |
| 91 | S_IFDIR:S_IFREG; |
| 92 | buf->st_size = (((i64)attr.nFileSizeHigh)<<32) | attr.nFileSizeLow; |
| 93 | buf->st_mtime = ull.QuadPart / 10000000ULL - 11644473600ULL; |
| 94 | } |
| 95 | #endif |
| 96 | fossil_filename_free(zMbcs); |
| 97 | return rc; |
| 98 | } |
| 99 | |
| @@ -321,11 +336,11 @@ | |
| 336 | ** (UNIX only) |
| 337 | */ |
| 338 | int file_chdir(const char *zChDir, int bChroot){ |
| 339 | #ifdef _WIN32 |
| 340 | wchar_t *zPath = fossil_utf8_to_filename(zChDir); |
| 341 | int rc = SetCurrentDirectoryW(zPath)==0; |
| 342 | #else |
| 343 | char *zPath = fossil_utf8_to_filename(zChDir); |
| 344 | int rc = chdir(zPath); |
| 345 | if( !rc && bChroot ){ |
| 346 | rc = chroot(zPath); |
| 347 |