Fossil SCM
unicode support for file_getcwd, file_access and fossil_stat as well
Commit
d95039cc5aa76a06f8102e7b92b87bf3b5903518
Parent
0fdb1f4f8f02319…
1 file changed
+16
-8
+16
-8
| --- src/file.c | ||
| +++ src/file.c | ||
| @@ -27,10 +27,14 @@ | ||
| 27 | 27 | #include <sys/stat.h> |
| 28 | 28 | #include <unistd.h> |
| 29 | 29 | #include <string.h> |
| 30 | 30 | #include <errno.h> |
| 31 | 31 | #include "file.h" |
| 32 | +#if defined(_WIN32) | |
| 33 | +#include <direct.h> | |
| 34 | +#endif | |
| 35 | + | |
| 32 | 36 | |
| 33 | 37 | /* |
| 34 | 38 | ** On Windows, include the Platform SDK header file. |
| 35 | 39 | */ |
| 36 | 40 | #ifdef _WIN32 |
| @@ -68,12 +72,12 @@ | ||
| 68 | 72 | }else{ |
| 69 | 73 | return stat(zFilename, buf); |
| 70 | 74 | } |
| 71 | 75 | #else |
| 72 | 76 | int rc = 0; |
| 73 | - char *zMbcs = fossil_utf8_to_mbcs(zFilename); | |
| 74 | - rc = stat(zMbcs, buf); | |
| 77 | + wchar_t *zMbcs = fossil_utf8_to_unicode(zFilename); | |
| 78 | + rc = _wstati64(zMbcs, buf); | |
| 75 | 79 | fossil_mbcs_free(zMbcs); |
| 76 | 80 | return rc; |
| 77 | 81 | #endif |
| 78 | 82 | } |
| 79 | 83 | |
| @@ -298,13 +302,17 @@ | ||
| 298 | 302 | |
| 299 | 303 | /* |
| 300 | 304 | ** Wrapper around the access() system call. |
| 301 | 305 | */ |
| 302 | 306 | int file_access(const char *zFilename, int flags){ |
| 303 | - char *zMbcs = fossil_utf8_to_mbcs(zFilename); | |
| 304 | - int rc = access(zMbcs, flags); | |
| 307 | +#ifdef _WIN32 | |
| 308 | + wchar_t *zMbcs = fossil_utf8_to_unicode(zFilename); | |
| 309 | + int rc = _waccess(zMbcs, flags); | |
| 305 | 310 | fossil_mbcs_free(zMbcs); |
| 311 | +#else | |
| 312 | + int rc = access(zFilename, flags); | |
| 313 | +#endif | |
| 306 | 314 | return rc; |
| 307 | 315 | } |
| 308 | 316 | |
| 309 | 317 | /* |
| 310 | 318 | ** Find an unused filename similar to zBase with zSuffix appended. |
| @@ -565,24 +573,24 @@ | ||
| 565 | 573 | } |
| 566 | 574 | |
| 567 | 575 | /* |
| 568 | 576 | ** Get the current working directory. |
| 569 | 577 | ** |
| 570 | -** On windows, the name is converted from MBCS to UTF8 and all '\\' | |
| 578 | +** On windows, the name is converted from unicode to UTF8 and all '\\' | |
| 571 | 579 | ** characters are converted to '/'. No conversions are needed on |
| 572 | 580 | ** unix. |
| 573 | 581 | */ |
| 574 | 582 | void file_getcwd(char *zBuf, int nBuf){ |
| 575 | 583 | #ifdef _WIN32 |
| 576 | 584 | char *zPwdUtf8; |
| 577 | 585 | int nPwd; |
| 578 | 586 | int i; |
| 579 | - char zPwd[2000]; | |
| 580 | - if( getcwd(zPwd, sizeof(zPwd)-1)==0 ){ | |
| 587 | + wchar_t zPwd[2000]; | |
| 588 | + if( _wgetcwd(zPwd, sizeof(zPwd)-1)==0 ){ | |
| 581 | 589 | fossil_fatal("cannot find the current working directory."); |
| 582 | 590 | } |
| 583 | - zPwdUtf8 = fossil_mbcs_to_utf8(zPwd); | |
| 591 | + zPwdUtf8 = fossil_unicode_to_utf8(zPwd); | |
| 584 | 592 | nPwd = strlen(zPwdUtf8); |
| 585 | 593 | if( nPwd > nBuf-1 ){ |
| 586 | 594 | fossil_fatal("pwd too big: max %d\n", nBuf-1); |
| 587 | 595 | } |
| 588 | 596 | for(i=0; zPwdUtf8[i]; i++) if( zPwdUtf8[i]=='\\' ) zPwdUtf8[i] = '/'; |
| 589 | 597 |
| --- src/file.c | |
| +++ src/file.c | |
| @@ -27,10 +27,14 @@ | |
| 27 | #include <sys/stat.h> |
| 28 | #include <unistd.h> |
| 29 | #include <string.h> |
| 30 | #include <errno.h> |
| 31 | #include "file.h" |
| 32 | |
| 33 | /* |
| 34 | ** On Windows, include the Platform SDK header file. |
| 35 | */ |
| 36 | #ifdef _WIN32 |
| @@ -68,12 +72,12 @@ | |
| 68 | }else{ |
| 69 | return stat(zFilename, buf); |
| 70 | } |
| 71 | #else |
| 72 | int rc = 0; |
| 73 | char *zMbcs = fossil_utf8_to_mbcs(zFilename); |
| 74 | rc = stat(zMbcs, buf); |
| 75 | fossil_mbcs_free(zMbcs); |
| 76 | return rc; |
| 77 | #endif |
| 78 | } |
| 79 | |
| @@ -298,13 +302,17 @@ | |
| 298 | |
| 299 | /* |
| 300 | ** Wrapper around the access() system call. |
| 301 | */ |
| 302 | int file_access(const char *zFilename, int flags){ |
| 303 | char *zMbcs = fossil_utf8_to_mbcs(zFilename); |
| 304 | int rc = access(zMbcs, flags); |
| 305 | fossil_mbcs_free(zMbcs); |
| 306 | return rc; |
| 307 | } |
| 308 | |
| 309 | /* |
| 310 | ** Find an unused filename similar to zBase with zSuffix appended. |
| @@ -565,24 +573,24 @@ | |
| 565 | } |
| 566 | |
| 567 | /* |
| 568 | ** Get the current working directory. |
| 569 | ** |
| 570 | ** On windows, the name is converted from MBCS to UTF8 and all '\\' |
| 571 | ** characters are converted to '/'. No conversions are needed on |
| 572 | ** unix. |
| 573 | */ |
| 574 | void file_getcwd(char *zBuf, int nBuf){ |
| 575 | #ifdef _WIN32 |
| 576 | char *zPwdUtf8; |
| 577 | int nPwd; |
| 578 | int i; |
| 579 | char zPwd[2000]; |
| 580 | if( getcwd(zPwd, sizeof(zPwd)-1)==0 ){ |
| 581 | fossil_fatal("cannot find the current working directory."); |
| 582 | } |
| 583 | zPwdUtf8 = fossil_mbcs_to_utf8(zPwd); |
| 584 | nPwd = strlen(zPwdUtf8); |
| 585 | if( nPwd > nBuf-1 ){ |
| 586 | fossil_fatal("pwd too big: max %d\n", nBuf-1); |
| 587 | } |
| 588 | for(i=0; zPwdUtf8[i]; i++) if( zPwdUtf8[i]=='\\' ) zPwdUtf8[i] = '/'; |
| 589 |
| --- src/file.c | |
| +++ src/file.c | |
| @@ -27,10 +27,14 @@ | |
| 27 | #include <sys/stat.h> |
| 28 | #include <unistd.h> |
| 29 | #include <string.h> |
| 30 | #include <errno.h> |
| 31 | #include "file.h" |
| 32 | #if defined(_WIN32) |
| 33 | #include <direct.h> |
| 34 | #endif |
| 35 | |
| 36 | |
| 37 | /* |
| 38 | ** On Windows, include the Platform SDK header file. |
| 39 | */ |
| 40 | #ifdef _WIN32 |
| @@ -68,12 +72,12 @@ | |
| 72 | }else{ |
| 73 | return stat(zFilename, buf); |
| 74 | } |
| 75 | #else |
| 76 | int rc = 0; |
| 77 | wchar_t *zMbcs = fossil_utf8_to_unicode(zFilename); |
| 78 | rc = _wstati64(zMbcs, buf); |
| 79 | fossil_mbcs_free(zMbcs); |
| 80 | return rc; |
| 81 | #endif |
| 82 | } |
| 83 | |
| @@ -298,13 +302,17 @@ | |
| 302 | |
| 303 | /* |
| 304 | ** Wrapper around the access() system call. |
| 305 | */ |
| 306 | int file_access(const char *zFilename, int flags){ |
| 307 | #ifdef _WIN32 |
| 308 | wchar_t *zMbcs = fossil_utf8_to_unicode(zFilename); |
| 309 | int rc = _waccess(zMbcs, flags); |
| 310 | fossil_mbcs_free(zMbcs); |
| 311 | #else |
| 312 | int rc = access(zFilename, flags); |
| 313 | #endif |
| 314 | return rc; |
| 315 | } |
| 316 | |
| 317 | /* |
| 318 | ** Find an unused filename similar to zBase with zSuffix appended. |
| @@ -565,24 +573,24 @@ | |
| 573 | } |
| 574 | |
| 575 | /* |
| 576 | ** Get the current working directory. |
| 577 | ** |
| 578 | ** On windows, the name is converted from unicode to UTF8 and all '\\' |
| 579 | ** characters are converted to '/'. No conversions are needed on |
| 580 | ** unix. |
| 581 | */ |
| 582 | void file_getcwd(char *zBuf, int nBuf){ |
| 583 | #ifdef _WIN32 |
| 584 | char *zPwdUtf8; |
| 585 | int nPwd; |
| 586 | int i; |
| 587 | wchar_t zPwd[2000]; |
| 588 | if( _wgetcwd(zPwd, sizeof(zPwd)-1)==0 ){ |
| 589 | fossil_fatal("cannot find the current working directory."); |
| 590 | } |
| 591 | zPwdUtf8 = fossil_unicode_to_utf8(zPwd); |
| 592 | nPwd = strlen(zPwdUtf8); |
| 593 | if( nPwd > nBuf-1 ){ |
| 594 | fossil_fatal("pwd too big: max %d\n", nBuf-1); |
| 595 | } |
| 596 | for(i=0; zPwdUtf8[i]; i++) if( zPwdUtf8[i]=='\\' ) zPwdUtf8[i] = '/'; |
| 597 |