Fossil SCM

unicode support for file_getcwd, file_access and fossil_stat as well

jan.nijtmans 2012-08-23 08:53 eclipse-project
Commit d95039cc5aa76a06f8102e7b92b87bf3b5903518
1 file changed +16 -8
+16 -8
--- src/file.c
+++ src/file.c
@@ -27,10 +27,14 @@
2727
#include <sys/stat.h>
2828
#include <unistd.h>
2929
#include <string.h>
3030
#include <errno.h>
3131
#include "file.h"
32
+#if defined(_WIN32)
33
+#include <direct.h>
34
+#endif
35
+
3236
3337
/*
3438
** On Windows, include the Platform SDK header file.
3539
*/
3640
#ifdef _WIN32
@@ -68,12 +72,12 @@
6872
}else{
6973
return stat(zFilename, buf);
7074
}
7175
#else
7276
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);
7579
fossil_mbcs_free(zMbcs);
7680
return rc;
7781
#endif
7882
}
7983
@@ -298,13 +302,17 @@
298302
299303
/*
300304
** Wrapper around the access() system call.
301305
*/
302306
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);
305310
fossil_mbcs_free(zMbcs);
311
+#else
312
+ int rc = access(zFilename, flags);
313
+#endif
306314
return rc;
307315
}
308316
309317
/*
310318
** Find an unused filename similar to zBase with zSuffix appended.
@@ -565,24 +573,24 @@
565573
}
566574
567575
/*
568576
** Get the current working directory.
569577
**
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 '\\'
571579
** characters are converted to '/'. No conversions are needed on
572580
** unix.
573581
*/
574582
void file_getcwd(char *zBuf, int nBuf){
575583
#ifdef _WIN32
576584
char *zPwdUtf8;
577585
int nPwd;
578586
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 ){
581589
fossil_fatal("cannot find the current working directory.");
582590
}
583
- zPwdUtf8 = fossil_mbcs_to_utf8(zPwd);
591
+ zPwdUtf8 = fossil_unicode_to_utf8(zPwd);
584592
nPwd = strlen(zPwdUtf8);
585593
if( nPwd > nBuf-1 ){
586594
fossil_fatal("pwd too big: max %d\n", nBuf-1);
587595
}
588596
for(i=0; zPwdUtf8[i]; i++) if( zPwdUtf8[i]=='\\' ) zPwdUtf8[i] = '/';
589597
--- 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

Keyboard Shortcuts

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