Fossil SCM

Use SetCurrentDirectoryW/GetFileAttributesExW in stead of _wchdir/_wstati64 (which cannot handle long pathnames)

jan.nijtmans 2013-12-13 09:40 trunk
Commit 3714782631607e930dff33f7c544c857ec606e3a
1 file changed +18 -3
+18 -3
--- src/file.c
+++ src/file.c
@@ -47,11 +47,16 @@
4747
** Use _stati64 rather than stat on windows, in order to handle files
4848
** larger than 2GB.
4949
*/
5050
#if defined(_WIN32) && (defined(__MSVCRT__) || defined(_MSC_VER))
5151
# 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
+};
5358
#endif
5459
/*
5560
** On Windows S_ISLNK always returns FALSE.
5661
*/
5762
#if !defined(S_ISLNK)
@@ -73,12 +78,22 @@
7378
rc = lstat(zMbcs, buf);
7479
}else{
7580
rc = stat(zMbcs, buf);
7681
}
7782
#else
83
+ WIN32_FILE_ATTRIBUTE_DATA attr;
7884
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
+ }
8095
#endif
8196
fossil_filename_free(zMbcs);
8297
return rc;
8398
}
8499
@@ -321,11 +336,11 @@
321336
** (UNIX only)
322337
*/
323338
int file_chdir(const char *zChDir, int bChroot){
324339
#ifdef _WIN32
325340
wchar_t *zPath = fossil_utf8_to_filename(zChDir);
326
- int rc = _wchdir(zPath);
341
+ int rc = SetCurrentDirectoryW(zPath)==0;
327342
#else
328343
char *zPath = fossil_utf8_to_filename(zChDir);
329344
int rc = chdir(zPath);
330345
if( !rc && bChroot ){
331346
rc = chroot(zPath);
332347
--- 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

Keyboard Shortcuts

Open search /
Next entry (timeline) j
Previous entry (timeline) k
Open focused entry Enter
Show this help ?
Toggle theme Top nav button