Fossil SCM

working part of [01a2f3a346]

jan.nijtmans 2012-08-29 22:34 trunk merge
Commit 14733d1519d8e157cf65439fbad90de07647d217
4 files changed +3 -3 +79 -23 +79 -23 +2 -2
+3 -3
--- src/export.c
+++ src/export.c
@@ -1,7 +1,7 @@
11
/*
2
-** Copyright (c) 2010 D. Richard Hipp
2
+** Copyright © 2010 D. Richard Hipp
33
**
44
** This program is free software; you can redistribute it and/or
55
** modify it under the terms of the Simplified BSD License (also
66
** known as the "2-Clause License" or "FreeBSD License".)
77
@@ -136,11 +136,11 @@
136136
if( markfile_in!=0 ){
137137
Stmt qb,qc;
138138
char line[100];
139139
FILE *f;
140140
141
- f = fopen(markfile_in, "r");
141
+ f = fossil_fopen(markfile_in, "r");
142142
if( f==0 ){
143143
fossil_panic("cannot open %s for reading", markfile_in);
144144
}
145145
db_prepare(&qb, "INSERT OR IGNORE INTO oldblob VALUES (:rid)");
146146
db_prepare(&qc, "INSERT OR IGNORE INTO oldcommit VALUES (:rid)");
@@ -325,11 +325,11 @@
325325
db_finalize(&q);
326326
bag_clear(&vers);
327327
328328
if( markfile_out!=0 ){
329329
FILE *f;
330
- f = fopen(markfile_out, "w");
330
+ f = fossil_fopen(markfile_out, "w");
331331
if( f == 0 ){
332332
fossil_panic("cannot open %s for writing", markfile_out);
333333
}
334334
db_prepare(&q, "SELECT rid FROM oldblob");
335335
while( db_step(&q)==SQLITE_ROW ){
336336
--- src/export.c
+++ src/export.c
@@ -1,7 +1,7 @@
1 /*
2 ** Copyright (c) 2010 D. Richard Hipp
3 **
4 ** This program is free software; you can redistribute it and/or
5 ** modify it under the terms of the Simplified BSD License (also
6 ** known as the "2-Clause License" or "FreeBSD License".)
7
@@ -136,11 +136,11 @@
136 if( markfile_in!=0 ){
137 Stmt qb,qc;
138 char line[100];
139 FILE *f;
140
141 f = fopen(markfile_in, "r");
142 if( f==0 ){
143 fossil_panic("cannot open %s for reading", markfile_in);
144 }
145 db_prepare(&qb, "INSERT OR IGNORE INTO oldblob VALUES (:rid)");
146 db_prepare(&qc, "INSERT OR IGNORE INTO oldcommit VALUES (:rid)");
@@ -325,11 +325,11 @@
325 db_finalize(&q);
326 bag_clear(&vers);
327
328 if( markfile_out!=0 ){
329 FILE *f;
330 f = fopen(markfile_out, "w");
331 if( f == 0 ){
332 fossil_panic("cannot open %s for writing", markfile_out);
333 }
334 db_prepare(&q, "SELECT rid FROM oldblob");
335 while( db_step(&q)==SQLITE_ROW ){
336
--- src/export.c
+++ src/export.c
@@ -1,7 +1,7 @@
1 /*
2 ** Copyright © 2010 D. Richard Hipp
3 **
4 ** This program is free software; you can redistribute it and/or
5 ** modify it under the terms of the Simplified BSD License (also
6 ** known as the "2-Clause License" or "FreeBSD License".)
7
@@ -136,11 +136,11 @@
136 if( markfile_in!=0 ){
137 Stmt qb,qc;
138 char line[100];
139 FILE *f;
140
141 f = fossil_fopen(markfile_in, "r");
142 if( f==0 ){
143 fossil_panic("cannot open %s for reading", markfile_in);
144 }
145 db_prepare(&qb, "INSERT OR IGNORE INTO oldblob VALUES (:rid)");
146 db_prepare(&qc, "INSERT OR IGNORE INTO oldcommit VALUES (:rid)");
@@ -325,11 +325,11 @@
325 db_finalize(&q);
326 bag_clear(&vers);
327
328 if( markfile_out!=0 ){
329 FILE *f;
330 f = fossil_fopen(markfile_out, "w");
331 if( f == 0 ){
332 fossil_panic("cannot open %s for writing", markfile_out);
333 }
334 db_prepare(&q, "SELECT rid FROM oldblob");
335 while( db_step(&q)==SQLITE_ROW ){
336
+79 -23
--- src/file.c
+++ src/file.c
@@ -1,7 +1,7 @@
11
/*
2
-** Copyright (c) 2006 D. Richard Hipp
2
+** Copyright © 2006 D. Richard Hipp
33
**
44
** This program is free software; you can redistribute it and/or
55
** modify it under the terms of the Simplified BSD License (also
66
** known as the "2-Clause License" or "FreeBSD License".)
77
@@ -32,10 +32,11 @@
3232
3333
/*
3434
** On Windows, include the Platform SDK header file.
3535
*/
3636
#ifdef _WIN32
37
+# include <direct.h>
3738
# include <windows.h>
3839
#endif
3940
4041
/*
4142
** The file status information from the most recent stat() call.
@@ -68,12 +69,12 @@
6869
}else{
6970
return stat(zFilename, buf);
7071
}
7172
#else
7273
int rc = 0;
73
- char *zMbcs = fossil_utf8_to_mbcs(zFilename);
74
- rc = stat(zMbcs, buf);
74
+ wchar_t *zMbcs = fossil_utf8_to_unicode(zFilename);
75
+ rc = _wstati64(zMbcs, buf);
7576
fossil_mbcs_free(zMbcs);
7677
return rc;
7778
#endif
7879
}
7980
@@ -298,13 +299,17 @@
298299
299300
/*
300301
** Wrapper around the access() system call.
301302
*/
302303
int file_access(const char *zFilename, int flags){
303
- char *zMbcs = fossil_utf8_to_mbcs(zFilename);
304
- int rc = access(zMbcs, flags);
304
+#ifdef _WIN32
305
+ wchar_t *zMbcs = fossil_utf8_to_unicode(zFilename);
306
+ int rc = _waccess(zMbcs, flags);
305307
fossil_mbcs_free(zMbcs);
308
+#else
309
+ int rc = access(zFilename, flags);
310
+#endif
306311
return rc;
307312
}
308313
309314
/*
310315
** Find an unused filename similar to zBase with zSuffix appended.
@@ -389,13 +394,17 @@
389394
390395
/*
391396
** Delete a file.
392397
*/
393398
void file_delete(const char *zFilename){
394
- char *z = fossil_utf8_to_mbcs(zFilename);
395
- unlink(z);
399
+#ifdef _WIN32
400
+ wchar_t *z = fossil_utf8_to_unicode(zFilename);
401
+ _wunlink(z);
396402
fossil_mbcs_free(z);
403
+#else
404
+ unlink(zFilename);
405
+#endif
397406
}
398407
399408
/*
400409
** Create the directory named in the argument, if it does not already
401410
** exist. If forceFlag is 1, delete any prior non-directory object
@@ -410,12 +419,12 @@
410419
file_delete(zName);
411420
}
412421
if( rc!=1 ){
413422
#if defined(_WIN32)
414423
int rc;
415
- char *zMbcs = fossil_utf8_to_mbcs(zName);
416
- rc = mkdir(zMbcs);
424
+ wchar_t *zMbcs = fossil_utf8_to_unicode(zName);
425
+ rc = _wmkdir(zMbcs);
417426
fossil_mbcs_free(zMbcs);
418427
return rc;
419428
#else
420429
return mkdir(zName, 0755);
421430
#endif
@@ -561,24 +570,24 @@
561570
}
562571
563572
/*
564573
** Get the current working directory.
565574
**
566
-** On windows, the name is converted from MBCS to UTF8 and all '\\'
575
+** On windows, the name is converted from unicode to UTF8 and all '\\'
567576
** characters are converted to '/'. No conversions are needed on
568577
** unix.
569578
*/
570579
void file_getcwd(char *zBuf, int nBuf){
571580
#ifdef _WIN32
572581
char *zPwdUtf8;
573582
int nPwd;
574583
int i;
575
- char zPwd[2000];
576
- if( getcwd(zPwd, sizeof(zPwd)-1)==0 ){
584
+ wchar_t zPwd[2000];
585
+ if( _wgetcwd(zPwd, sizeof(zPwd)/sizeof(zPwd[0])-1)==0 ){
577586
fossil_fatal("cannot find the current working directory.");
578587
}
579
- zPwdUtf8 = fossil_mbcs_to_utf8(zPwd);
588
+ zPwdUtf8 = fossil_unicode_to_utf8(zPwd);
580589
nPwd = strlen(zPwdUtf8);
581590
if( nPwd > nBuf-1 ){
582591
fossil_fatal("pwd too big: max %d\n", nBuf-1);
583592
}
584593
for(i=0; zPwdUtf8[i]; i++) if( zPwdUtf8[i]=='\\' ) zPwdUtf8[i] = '/';
@@ -928,14 +937,14 @@
928937
unsigned int i, j;
929938
const char *zDir = ".";
930939
int cnt = 0;
931940
932941
#if defined(_WIN32)
933
- char zTmpPath[MAX_PATH];
942
+ wchar_t zTmpPath[MAX_PATH];
934943
935
- if( GetTempPath(sizeof(zTmpPath), zTmpPath) ){
936
- azDirs[0] = zTmpPath;
944
+ if( GetTempPathW(MAX_PATH, zTmpPath) ){
945
+ azDirs[0] = fossil_unicode_to_utf8(zTmpPath);
937946
}
938947
939948
azDirs[1] = fossil_getenv("TEMP");
940949
azDirs[2] = fossil_getenv("TMP");
941950
#endif
@@ -994,11 +1003,10 @@
9941003
rc = blob_compare(&onDisk, pContent);
9951004
blob_reset(&onDisk);
9961005
return rc==0;
9971006
}
9981007
999
-
10001008
/**************************************************************************
10011009
** The following routines translate between MBCS and UTF8 on windows.
10021010
** Since everything is always UTF8 on unix, these routines are no-ops
10031011
** there.
10041012
*/
@@ -1014,10 +1022,29 @@
10141022
return sqlite3_win32_mbcs_to_utf8(zMbcs);
10151023
#else
10161024
return (char*)zMbcs; /* No-op on unix */
10171025
#endif
10181026
}
1027
+
1028
+/*
1029
+** Translate Unicode to UTF8. Return a pointer to the translated text.
1030
+** Call fossil_mbcs_free() to deallocate any memory used to store the
1031
+** returned pointer when done.
1032
+*/
1033
+char *fossil_unicode_to_utf8(const void *zUnicode){
1034
+#ifdef _WIN32
1035
+ int nByte = WideCharToMultiByte(CP_UTF8, 0, zUnicode, -1, 0, 0, 0, 0);
1036
+ char *zUtf = sqlite3_malloc( nByte );
1037
+ if( zUtf==0 ){
1038
+ return 0;
1039
+ }
1040
+ WideCharToMultiByte(CP_UTF8, 0, zUnicode, -1, zUtf, nByte, 0, 0);
1041
+ return zUtf;
1042
+#else
1043
+ return (char *)zUnicode; /* No-op on unix */
1044
+#endif
1045
+}
10191046
10201047
/*
10211048
** Translate UTF8 to MBCS for use in system calls. Return a pointer to the
10221049
** translated text.. Call fossil_mbcs_free() to deallocate any memory
10231050
** used to store the returned pointer when done.
@@ -1028,18 +1055,41 @@
10281055
return sqlite3_win32_utf8_to_mbcs(zUtf8);
10291056
#else
10301057
return (char*)zUtf8; /* No-op on unix */
10311058
#endif
10321059
}
1060
+
1061
+/*
1062
+** Translate UTF8 to unicode for use in system calls. Return a pointer to the
1063
+** translated text.. Call fossil_mbcs_free() to deallocate any memory
1064
+** used to store the returned pointer when done.
1065
+*/
1066
+void *fossil_utf8_to_unicode(const char *zUtf8){
1067
+#ifdef _WIN32
1068
+ int nByte = MultiByteToWideChar(CP_UTF8, 0, zUtf8, -1, 0, 0);
1069
+ wchar_t *zUnicode = sqlite3_malloc( nByte * 2 );
1070
+ if( zUnicode==0 ){
1071
+ return 0;
1072
+ }
1073
+ MultiByteToWideChar(CP_UTF8, 0, zUtf8, -1, zUnicode, nByte);
1074
+ return zUnicode;
1075
+#else
1076
+ return (void *)zUtf8; /* No-op on unix */
1077
+#endif
1078
+}
10331079
10341080
/*
10351081
** Return the value of an environment variable as UTF8.
10361082
*/
10371083
char *fossil_getenv(const char *zName){
1038
- char *zValue = getenv(zName);
10391084
#ifdef _WIN32
1040
- if( zValue ) zValue = fossil_mbcs_to_utf8(zValue);
1085
+ wchar_t *uName = fossil_utf8_to_unicode(zName);
1086
+ void *zValue = _wgetenv(uName);
1087
+ fossil_mbcs_free(uName);
1088
+ if( zValue ) zValue = fossil_unicode_to_utf8(zValue);
1089
+#else
1090
+ char *zValue = getenv(zName);
10411091
#endif
10421092
return zValue;
10431093
}
10441094
10451095
/*
@@ -1085,11 +1135,11 @@
10851135
10861136
/*
10871137
** Translate MBCS to UTF8. Return a pointer. Call fossil_mbcs_free()
10881138
** to deallocate any memory used to store the returned pointer when done.
10891139
*/
1090
-void fossil_mbcs_free(char *zOld){
1140
+void fossil_mbcs_free(void *zOld){
10911141
#ifdef _WIN32
10921142
extern void sqlite3_free(void*);
10931143
sqlite3_free(zOld);
10941144
#else
10951145
/* No-op on unix */
@@ -1098,10 +1148,16 @@
10981148
10991149
/*
11001150
** Like fopen() but always takes a UTF8 argument.
11011151
*/
11021152
FILE *fossil_fopen(const char *zName, const char *zMode){
1103
- char *zMbcs = fossil_utf8_to_mbcs(zName);
1104
- FILE *f = fopen(zMbcs, zMode);
1105
- fossil_mbcs_free(zMbcs);
1153
+#ifdef _WIN32
1154
+ wchar_t *uMode = fossil_utf8_to_unicode(zMode);
1155
+ wchar_t *uName = fossil_utf8_to_unicode(zName);
1156
+ FILE *f = _wfopen(uName, uMode);
1157
+ fossil_mbcs_free(uName);
1158
+ fossil_mbcs_free(uMode);
1159
+#else
1160
+ FILE *f = fopen(zName, zMode);
1161
+#endif
11061162
return f;
11071163
}
11081164
--- src/file.c
+++ src/file.c
@@ -1,7 +1,7 @@
1 /*
2 ** Copyright (c) 2006 D. Richard Hipp
3 **
4 ** This program is free software; you can redistribute it and/or
5 ** modify it under the terms of the Simplified BSD License (also
6 ** known as the "2-Clause License" or "FreeBSD License".)
7
@@ -32,10 +32,11 @@
32
33 /*
34 ** On Windows, include the Platform SDK header file.
35 */
36 #ifdef _WIN32
 
37 # include <windows.h>
38 #endif
39
40 /*
41 ** The file status information from the most recent stat() call.
@@ -68,12 +69,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 +299,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.
@@ -389,13 +394,17 @@
389
390 /*
391 ** Delete a file.
392 */
393 void file_delete(const char *zFilename){
394 char *z = fossil_utf8_to_mbcs(zFilename);
395 unlink(z);
 
396 fossil_mbcs_free(z);
 
 
 
397 }
398
399 /*
400 ** Create the directory named in the argument, if it does not already
401 ** exist. If forceFlag is 1, delete any prior non-directory object
@@ -410,12 +419,12 @@
410 file_delete(zName);
411 }
412 if( rc!=1 ){
413 #if defined(_WIN32)
414 int rc;
415 char *zMbcs = fossil_utf8_to_mbcs(zName);
416 rc = mkdir(zMbcs);
417 fossil_mbcs_free(zMbcs);
418 return rc;
419 #else
420 return mkdir(zName, 0755);
421 #endif
@@ -561,24 +570,24 @@
561 }
562
563 /*
564 ** Get the current working directory.
565 **
566 ** On windows, the name is converted from MBCS to UTF8 and all '\\'
567 ** characters are converted to '/'. No conversions are needed on
568 ** unix.
569 */
570 void file_getcwd(char *zBuf, int nBuf){
571 #ifdef _WIN32
572 char *zPwdUtf8;
573 int nPwd;
574 int i;
575 char zPwd[2000];
576 if( getcwd(zPwd, sizeof(zPwd)-1)==0 ){
577 fossil_fatal("cannot find the current working directory.");
578 }
579 zPwdUtf8 = fossil_mbcs_to_utf8(zPwd);
580 nPwd = strlen(zPwdUtf8);
581 if( nPwd > nBuf-1 ){
582 fossil_fatal("pwd too big: max %d\n", nBuf-1);
583 }
584 for(i=0; zPwdUtf8[i]; i++) if( zPwdUtf8[i]=='\\' ) zPwdUtf8[i] = '/';
@@ -928,14 +937,14 @@
928 unsigned int i, j;
929 const char *zDir = ".";
930 int cnt = 0;
931
932 #if defined(_WIN32)
933 char zTmpPath[MAX_PATH];
934
935 if( GetTempPath(sizeof(zTmpPath), zTmpPath) ){
936 azDirs[0] = zTmpPath;
937 }
938
939 azDirs[1] = fossil_getenv("TEMP");
940 azDirs[2] = fossil_getenv("TMP");
941 #endif
@@ -994,11 +1003,10 @@
994 rc = blob_compare(&onDisk, pContent);
995 blob_reset(&onDisk);
996 return rc==0;
997 }
998
999
1000 /**************************************************************************
1001 ** The following routines translate between MBCS and UTF8 on windows.
1002 ** Since everything is always UTF8 on unix, these routines are no-ops
1003 ** there.
1004 */
@@ -1014,10 +1022,29 @@
1014 return sqlite3_win32_mbcs_to_utf8(zMbcs);
1015 #else
1016 return (char*)zMbcs; /* No-op on unix */
1017 #endif
1018 }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1019
1020 /*
1021 ** Translate UTF8 to MBCS for use in system calls. Return a pointer to the
1022 ** translated text.. Call fossil_mbcs_free() to deallocate any memory
1023 ** used to store the returned pointer when done.
@@ -1028,18 +1055,41 @@
1028 return sqlite3_win32_utf8_to_mbcs(zUtf8);
1029 #else
1030 return (char*)zUtf8; /* No-op on unix */
1031 #endif
1032 }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1033
1034 /*
1035 ** Return the value of an environment variable as UTF8.
1036 */
1037 char *fossil_getenv(const char *zName){
1038 char *zValue = getenv(zName);
1039 #ifdef _WIN32
1040 if( zValue ) zValue = fossil_mbcs_to_utf8(zValue);
 
 
 
 
 
1041 #endif
1042 return zValue;
1043 }
1044
1045 /*
@@ -1085,11 +1135,11 @@
1085
1086 /*
1087 ** Translate MBCS to UTF8. Return a pointer. Call fossil_mbcs_free()
1088 ** to deallocate any memory used to store the returned pointer when done.
1089 */
1090 void fossil_mbcs_free(char *zOld){
1091 #ifdef _WIN32
1092 extern void sqlite3_free(void*);
1093 sqlite3_free(zOld);
1094 #else
1095 /* No-op on unix */
@@ -1098,10 +1148,16 @@
1098
1099 /*
1100 ** Like fopen() but always takes a UTF8 argument.
1101 */
1102 FILE *fossil_fopen(const char *zName, const char *zMode){
1103 char *zMbcs = fossil_utf8_to_mbcs(zName);
1104 FILE *f = fopen(zMbcs, zMode);
1105 fossil_mbcs_free(zMbcs);
 
 
 
 
 
 
1106 return f;
1107 }
1108
--- src/file.c
+++ src/file.c
@@ -1,7 +1,7 @@
1 /*
2 ** Copyright © 2006 D. Richard Hipp
3 **
4 ** This program is free software; you can redistribute it and/or
5 ** modify it under the terms of the Simplified BSD License (also
6 ** known as the "2-Clause License" or "FreeBSD License".)
7
@@ -32,10 +32,11 @@
32
33 /*
34 ** On Windows, include the Platform SDK header file.
35 */
36 #ifdef _WIN32
37 # include <direct.h>
38 # include <windows.h>
39 #endif
40
41 /*
42 ** The file status information from the most recent stat() call.
@@ -68,12 +69,12 @@
69 }else{
70 return stat(zFilename, buf);
71 }
72 #else
73 int rc = 0;
74 wchar_t *zMbcs = fossil_utf8_to_unicode(zFilename);
75 rc = _wstati64(zMbcs, buf);
76 fossil_mbcs_free(zMbcs);
77 return rc;
78 #endif
79 }
80
@@ -298,13 +299,17 @@
299
300 /*
301 ** Wrapper around the access() system call.
302 */
303 int file_access(const char *zFilename, int flags){
304 #ifdef _WIN32
305 wchar_t *zMbcs = fossil_utf8_to_unicode(zFilename);
306 int rc = _waccess(zMbcs, flags);
307 fossil_mbcs_free(zMbcs);
308 #else
309 int rc = access(zFilename, flags);
310 #endif
311 return rc;
312 }
313
314 /*
315 ** Find an unused filename similar to zBase with zSuffix appended.
@@ -389,13 +394,17 @@
394
395 /*
396 ** Delete a file.
397 */
398 void file_delete(const char *zFilename){
399 #ifdef _WIN32
400 wchar_t *z = fossil_utf8_to_unicode(zFilename);
401 _wunlink(z);
402 fossil_mbcs_free(z);
403 #else
404 unlink(zFilename);
405 #endif
406 }
407
408 /*
409 ** Create the directory named in the argument, if it does not already
410 ** exist. If forceFlag is 1, delete any prior non-directory object
@@ -410,12 +419,12 @@
419 file_delete(zName);
420 }
421 if( rc!=1 ){
422 #if defined(_WIN32)
423 int rc;
424 wchar_t *zMbcs = fossil_utf8_to_unicode(zName);
425 rc = _wmkdir(zMbcs);
426 fossil_mbcs_free(zMbcs);
427 return rc;
428 #else
429 return mkdir(zName, 0755);
430 #endif
@@ -561,24 +570,24 @@
570 }
571
572 /*
573 ** Get the current working directory.
574 **
575 ** On windows, the name is converted from unicode to UTF8 and all '\\'
576 ** characters are converted to '/'. No conversions are needed on
577 ** unix.
578 */
579 void file_getcwd(char *zBuf, int nBuf){
580 #ifdef _WIN32
581 char *zPwdUtf8;
582 int nPwd;
583 int i;
584 wchar_t zPwd[2000];
585 if( _wgetcwd(zPwd, sizeof(zPwd)/sizeof(zPwd[0])-1)==0 ){
586 fossil_fatal("cannot find the current working directory.");
587 }
588 zPwdUtf8 = fossil_unicode_to_utf8(zPwd);
589 nPwd = strlen(zPwdUtf8);
590 if( nPwd > nBuf-1 ){
591 fossil_fatal("pwd too big: max %d\n", nBuf-1);
592 }
593 for(i=0; zPwdUtf8[i]; i++) if( zPwdUtf8[i]=='\\' ) zPwdUtf8[i] = '/';
@@ -928,14 +937,14 @@
937 unsigned int i, j;
938 const char *zDir = ".";
939 int cnt = 0;
940
941 #if defined(_WIN32)
942 wchar_t zTmpPath[MAX_PATH];
943
944 if( GetTempPathW(MAX_PATH, zTmpPath) ){
945 azDirs[0] = fossil_unicode_to_utf8(zTmpPath);
946 }
947
948 azDirs[1] = fossil_getenv("TEMP");
949 azDirs[2] = fossil_getenv("TMP");
950 #endif
@@ -994,11 +1003,10 @@
1003 rc = blob_compare(&onDisk, pContent);
1004 blob_reset(&onDisk);
1005 return rc==0;
1006 }
1007
 
1008 /**************************************************************************
1009 ** The following routines translate between MBCS and UTF8 on windows.
1010 ** Since everything is always UTF8 on unix, these routines are no-ops
1011 ** there.
1012 */
@@ -1014,10 +1022,29 @@
1022 return sqlite3_win32_mbcs_to_utf8(zMbcs);
1023 #else
1024 return (char*)zMbcs; /* No-op on unix */
1025 #endif
1026 }
1027
1028 /*
1029 ** Translate Unicode to UTF8. Return a pointer to the translated text.
1030 ** Call fossil_mbcs_free() to deallocate any memory used to store the
1031 ** returned pointer when done.
1032 */
1033 char *fossil_unicode_to_utf8(const void *zUnicode){
1034 #ifdef _WIN32
1035 int nByte = WideCharToMultiByte(CP_UTF8, 0, zUnicode, -1, 0, 0, 0, 0);
1036 char *zUtf = sqlite3_malloc( nByte );
1037 if( zUtf==0 ){
1038 return 0;
1039 }
1040 WideCharToMultiByte(CP_UTF8, 0, zUnicode, -1, zUtf, nByte, 0, 0);
1041 return zUtf;
1042 #else
1043 return (char *)zUnicode; /* No-op on unix */
1044 #endif
1045 }
1046
1047 /*
1048 ** Translate UTF8 to MBCS for use in system calls. Return a pointer to the
1049 ** translated text.. Call fossil_mbcs_free() to deallocate any memory
1050 ** used to store the returned pointer when done.
@@ -1028,18 +1055,41 @@
1055 return sqlite3_win32_utf8_to_mbcs(zUtf8);
1056 #else
1057 return (char*)zUtf8; /* No-op on unix */
1058 #endif
1059 }
1060
1061 /*
1062 ** Translate UTF8 to unicode for use in system calls. Return a pointer to the
1063 ** translated text.. Call fossil_mbcs_free() to deallocate any memory
1064 ** used to store the returned pointer when done.
1065 */
1066 void *fossil_utf8_to_unicode(const char *zUtf8){
1067 #ifdef _WIN32
1068 int nByte = MultiByteToWideChar(CP_UTF8, 0, zUtf8, -1, 0, 0);
1069 wchar_t *zUnicode = sqlite3_malloc( nByte * 2 );
1070 if( zUnicode==0 ){
1071 return 0;
1072 }
1073 MultiByteToWideChar(CP_UTF8, 0, zUtf8, -1, zUnicode, nByte);
1074 return zUnicode;
1075 #else
1076 return (void *)zUtf8; /* No-op on unix */
1077 #endif
1078 }
1079
1080 /*
1081 ** Return the value of an environment variable as UTF8.
1082 */
1083 char *fossil_getenv(const char *zName){
 
1084 #ifdef _WIN32
1085 wchar_t *uName = fossil_utf8_to_unicode(zName);
1086 void *zValue = _wgetenv(uName);
1087 fossil_mbcs_free(uName);
1088 if( zValue ) zValue = fossil_unicode_to_utf8(zValue);
1089 #else
1090 char *zValue = getenv(zName);
1091 #endif
1092 return zValue;
1093 }
1094
1095 /*
@@ -1085,11 +1135,11 @@
1135
1136 /*
1137 ** Translate MBCS to UTF8. Return a pointer. Call fossil_mbcs_free()
1138 ** to deallocate any memory used to store the returned pointer when done.
1139 */
1140 void fossil_mbcs_free(void *zOld){
1141 #ifdef _WIN32
1142 extern void sqlite3_free(void*);
1143 sqlite3_free(zOld);
1144 #else
1145 /* No-op on unix */
@@ -1098,10 +1148,16 @@
1148
1149 /*
1150 ** Like fopen() but always takes a UTF8 argument.
1151 */
1152 FILE *fossil_fopen(const char *zName, const char *zMode){
1153 #ifdef _WIN32
1154 wchar_t *uMode = fossil_utf8_to_unicode(zMode);
1155 wchar_t *uName = fossil_utf8_to_unicode(zName);
1156 FILE *f = _wfopen(uName, uMode);
1157 fossil_mbcs_free(uName);
1158 fossil_mbcs_free(uMode);
1159 #else
1160 FILE *f = fopen(zName, zMode);
1161 #endif
1162 return f;
1163 }
1164
+79 -23
--- src/file.c
+++ src/file.c
@@ -1,7 +1,7 @@
11
/*
2
-** Copyright (c) 2006 D. Richard Hipp
2
+** Copyright © 2006 D. Richard Hipp
33
**
44
** This program is free software; you can redistribute it and/or
55
** modify it under the terms of the Simplified BSD License (also
66
** known as the "2-Clause License" or "FreeBSD License".)
77
@@ -32,10 +32,11 @@
3232
3333
/*
3434
** On Windows, include the Platform SDK header file.
3535
*/
3636
#ifdef _WIN32
37
+# include <direct.h>
3738
# include <windows.h>
3839
#endif
3940
4041
/*
4142
** The file status information from the most recent stat() call.
@@ -68,12 +69,12 @@
6869
}else{
6970
return stat(zFilename, buf);
7071
}
7172
#else
7273
int rc = 0;
73
- char *zMbcs = fossil_utf8_to_mbcs(zFilename);
74
- rc = stat(zMbcs, buf);
74
+ wchar_t *zMbcs = fossil_utf8_to_unicode(zFilename);
75
+ rc = _wstati64(zMbcs, buf);
7576
fossil_mbcs_free(zMbcs);
7677
return rc;
7778
#endif
7879
}
7980
@@ -298,13 +299,17 @@
298299
299300
/*
300301
** Wrapper around the access() system call.
301302
*/
302303
int file_access(const char *zFilename, int flags){
303
- char *zMbcs = fossil_utf8_to_mbcs(zFilename);
304
- int rc = access(zMbcs, flags);
304
+#ifdef _WIN32
305
+ wchar_t *zMbcs = fossil_utf8_to_unicode(zFilename);
306
+ int rc = _waccess(zMbcs, flags);
305307
fossil_mbcs_free(zMbcs);
308
+#else
309
+ int rc = access(zFilename, flags);
310
+#endif
306311
return rc;
307312
}
308313
309314
/*
310315
** Find an unused filename similar to zBase with zSuffix appended.
@@ -389,13 +394,17 @@
389394
390395
/*
391396
** Delete a file.
392397
*/
393398
void file_delete(const char *zFilename){
394
- char *z = fossil_utf8_to_mbcs(zFilename);
395
- unlink(z);
399
+#ifdef _WIN32
400
+ wchar_t *z = fossil_utf8_to_unicode(zFilename);
401
+ _wunlink(z);
396402
fossil_mbcs_free(z);
403
+#else
404
+ unlink(zFilename);
405
+#endif
397406
}
398407
399408
/*
400409
** Create the directory named in the argument, if it does not already
401410
** exist. If forceFlag is 1, delete any prior non-directory object
@@ -410,12 +419,12 @@
410419
file_delete(zName);
411420
}
412421
if( rc!=1 ){
413422
#if defined(_WIN32)
414423
int rc;
415
- char *zMbcs = fossil_utf8_to_mbcs(zName);
416
- rc = mkdir(zMbcs);
424
+ wchar_t *zMbcs = fossil_utf8_to_unicode(zName);
425
+ rc = _wmkdir(zMbcs);
417426
fossil_mbcs_free(zMbcs);
418427
return rc;
419428
#else
420429
return mkdir(zName, 0755);
421430
#endif
@@ -561,24 +570,24 @@
561570
}
562571
563572
/*
564573
** Get the current working directory.
565574
**
566
-** On windows, the name is converted from MBCS to UTF8 and all '\\'
575
+** On windows, the name is converted from unicode to UTF8 and all '\\'
567576
** characters are converted to '/'. No conversions are needed on
568577
** unix.
569578
*/
570579
void file_getcwd(char *zBuf, int nBuf){
571580
#ifdef _WIN32
572581
char *zPwdUtf8;
573582
int nPwd;
574583
int i;
575
- char zPwd[2000];
576
- if( getcwd(zPwd, sizeof(zPwd)-1)==0 ){
584
+ wchar_t zPwd[2000];
585
+ if( _wgetcwd(zPwd, sizeof(zPwd)/sizeof(zPwd[0])-1)==0 ){
577586
fossil_fatal("cannot find the current working directory.");
578587
}
579
- zPwdUtf8 = fossil_mbcs_to_utf8(zPwd);
588
+ zPwdUtf8 = fossil_unicode_to_utf8(zPwd);
580589
nPwd = strlen(zPwdUtf8);
581590
if( nPwd > nBuf-1 ){
582591
fossil_fatal("pwd too big: max %d\n", nBuf-1);
583592
}
584593
for(i=0; zPwdUtf8[i]; i++) if( zPwdUtf8[i]=='\\' ) zPwdUtf8[i] = '/';
@@ -928,14 +937,14 @@
928937
unsigned int i, j;
929938
const char *zDir = ".";
930939
int cnt = 0;
931940
932941
#if defined(_WIN32)
933
- char zTmpPath[MAX_PATH];
942
+ wchar_t zTmpPath[MAX_PATH];
934943
935
- if( GetTempPath(sizeof(zTmpPath), zTmpPath) ){
936
- azDirs[0] = zTmpPath;
944
+ if( GetTempPathW(MAX_PATH, zTmpPath) ){
945
+ azDirs[0] = fossil_unicode_to_utf8(zTmpPath);
937946
}
938947
939948
azDirs[1] = fossil_getenv("TEMP");
940949
azDirs[2] = fossil_getenv("TMP");
941950
#endif
@@ -994,11 +1003,10 @@
9941003
rc = blob_compare(&onDisk, pContent);
9951004
blob_reset(&onDisk);
9961005
return rc==0;
9971006
}
9981007
999
-
10001008
/**************************************************************************
10011009
** The following routines translate between MBCS and UTF8 on windows.
10021010
** Since everything is always UTF8 on unix, these routines are no-ops
10031011
** there.
10041012
*/
@@ -1014,10 +1022,29 @@
10141022
return sqlite3_win32_mbcs_to_utf8(zMbcs);
10151023
#else
10161024
return (char*)zMbcs; /* No-op on unix */
10171025
#endif
10181026
}
1027
+
1028
+/*
1029
+** Translate Unicode to UTF8. Return a pointer to the translated text.
1030
+** Call fossil_mbcs_free() to deallocate any memory used to store the
1031
+** returned pointer when done.
1032
+*/
1033
+char *fossil_unicode_to_utf8(const void *zUnicode){
1034
+#ifdef _WIN32
1035
+ int nByte = WideCharToMultiByte(CP_UTF8, 0, zUnicode, -1, 0, 0, 0, 0);
1036
+ char *zUtf = sqlite3_malloc( nByte );
1037
+ if( zUtf==0 ){
1038
+ return 0;
1039
+ }
1040
+ WideCharToMultiByte(CP_UTF8, 0, zUnicode, -1, zUtf, nByte, 0, 0);
1041
+ return zUtf;
1042
+#else
1043
+ return (char *)zUnicode; /* No-op on unix */
1044
+#endif
1045
+}
10191046
10201047
/*
10211048
** Translate UTF8 to MBCS for use in system calls. Return a pointer to the
10221049
** translated text.. Call fossil_mbcs_free() to deallocate any memory
10231050
** used to store the returned pointer when done.
@@ -1028,18 +1055,41 @@
10281055
return sqlite3_win32_utf8_to_mbcs(zUtf8);
10291056
#else
10301057
return (char*)zUtf8; /* No-op on unix */
10311058
#endif
10321059
}
1060
+
1061
+/*
1062
+** Translate UTF8 to unicode for use in system calls. Return a pointer to the
1063
+** translated text.. Call fossil_mbcs_free() to deallocate any memory
1064
+** used to store the returned pointer when done.
1065
+*/
1066
+void *fossil_utf8_to_unicode(const char *zUtf8){
1067
+#ifdef _WIN32
1068
+ int nByte = MultiByteToWideChar(CP_UTF8, 0, zUtf8, -1, 0, 0);
1069
+ wchar_t *zUnicode = sqlite3_malloc( nByte * 2 );
1070
+ if( zUnicode==0 ){
1071
+ return 0;
1072
+ }
1073
+ MultiByteToWideChar(CP_UTF8, 0, zUtf8, -1, zUnicode, nByte);
1074
+ return zUnicode;
1075
+#else
1076
+ return (void *)zUtf8; /* No-op on unix */
1077
+#endif
1078
+}
10331079
10341080
/*
10351081
** Return the value of an environment variable as UTF8.
10361082
*/
10371083
char *fossil_getenv(const char *zName){
1038
- char *zValue = getenv(zName);
10391084
#ifdef _WIN32
1040
- if( zValue ) zValue = fossil_mbcs_to_utf8(zValue);
1085
+ wchar_t *uName = fossil_utf8_to_unicode(zName);
1086
+ void *zValue = _wgetenv(uName);
1087
+ fossil_mbcs_free(uName);
1088
+ if( zValue ) zValue = fossil_unicode_to_utf8(zValue);
1089
+#else
1090
+ char *zValue = getenv(zName);
10411091
#endif
10421092
return zValue;
10431093
}
10441094
10451095
/*
@@ -1085,11 +1135,11 @@
10851135
10861136
/*
10871137
** Translate MBCS to UTF8. Return a pointer. Call fossil_mbcs_free()
10881138
** to deallocate any memory used to store the returned pointer when done.
10891139
*/
1090
-void fossil_mbcs_free(char *zOld){
1140
+void fossil_mbcs_free(void *zOld){
10911141
#ifdef _WIN32
10921142
extern void sqlite3_free(void*);
10931143
sqlite3_free(zOld);
10941144
#else
10951145
/* No-op on unix */
@@ -1098,10 +1148,16 @@
10981148
10991149
/*
11001150
** Like fopen() but always takes a UTF8 argument.
11011151
*/
11021152
FILE *fossil_fopen(const char *zName, const char *zMode){
1103
- char *zMbcs = fossil_utf8_to_mbcs(zName);
1104
- FILE *f = fopen(zMbcs, zMode);
1105
- fossil_mbcs_free(zMbcs);
1153
+#ifdef _WIN32
1154
+ wchar_t *uMode = fossil_utf8_to_unicode(zMode);
1155
+ wchar_t *uName = fossil_utf8_to_unicode(zName);
1156
+ FILE *f = _wfopen(uName, uMode);
1157
+ fossil_mbcs_free(uName);
1158
+ fossil_mbcs_free(uMode);
1159
+#else
1160
+ FILE *f = fopen(zName, zMode);
1161
+#endif
11061162
return f;
11071163
}
11081164
--- src/file.c
+++ src/file.c
@@ -1,7 +1,7 @@
1 /*
2 ** Copyright (c) 2006 D. Richard Hipp
3 **
4 ** This program is free software; you can redistribute it and/or
5 ** modify it under the terms of the Simplified BSD License (also
6 ** known as the "2-Clause License" or "FreeBSD License".)
7
@@ -32,10 +32,11 @@
32
33 /*
34 ** On Windows, include the Platform SDK header file.
35 */
36 #ifdef _WIN32
 
37 # include <windows.h>
38 #endif
39
40 /*
41 ** The file status information from the most recent stat() call.
@@ -68,12 +69,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 +299,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.
@@ -389,13 +394,17 @@
389
390 /*
391 ** Delete a file.
392 */
393 void file_delete(const char *zFilename){
394 char *z = fossil_utf8_to_mbcs(zFilename);
395 unlink(z);
 
396 fossil_mbcs_free(z);
 
 
 
397 }
398
399 /*
400 ** Create the directory named in the argument, if it does not already
401 ** exist. If forceFlag is 1, delete any prior non-directory object
@@ -410,12 +419,12 @@
410 file_delete(zName);
411 }
412 if( rc!=1 ){
413 #if defined(_WIN32)
414 int rc;
415 char *zMbcs = fossil_utf8_to_mbcs(zName);
416 rc = mkdir(zMbcs);
417 fossil_mbcs_free(zMbcs);
418 return rc;
419 #else
420 return mkdir(zName, 0755);
421 #endif
@@ -561,24 +570,24 @@
561 }
562
563 /*
564 ** Get the current working directory.
565 **
566 ** On windows, the name is converted from MBCS to UTF8 and all '\\'
567 ** characters are converted to '/'. No conversions are needed on
568 ** unix.
569 */
570 void file_getcwd(char *zBuf, int nBuf){
571 #ifdef _WIN32
572 char *zPwdUtf8;
573 int nPwd;
574 int i;
575 char zPwd[2000];
576 if( getcwd(zPwd, sizeof(zPwd)-1)==0 ){
577 fossil_fatal("cannot find the current working directory.");
578 }
579 zPwdUtf8 = fossil_mbcs_to_utf8(zPwd);
580 nPwd = strlen(zPwdUtf8);
581 if( nPwd > nBuf-1 ){
582 fossil_fatal("pwd too big: max %d\n", nBuf-1);
583 }
584 for(i=0; zPwdUtf8[i]; i++) if( zPwdUtf8[i]=='\\' ) zPwdUtf8[i] = '/';
@@ -928,14 +937,14 @@
928 unsigned int i, j;
929 const char *zDir = ".";
930 int cnt = 0;
931
932 #if defined(_WIN32)
933 char zTmpPath[MAX_PATH];
934
935 if( GetTempPath(sizeof(zTmpPath), zTmpPath) ){
936 azDirs[0] = zTmpPath;
937 }
938
939 azDirs[1] = fossil_getenv("TEMP");
940 azDirs[2] = fossil_getenv("TMP");
941 #endif
@@ -994,11 +1003,10 @@
994 rc = blob_compare(&onDisk, pContent);
995 blob_reset(&onDisk);
996 return rc==0;
997 }
998
999
1000 /**************************************************************************
1001 ** The following routines translate between MBCS and UTF8 on windows.
1002 ** Since everything is always UTF8 on unix, these routines are no-ops
1003 ** there.
1004 */
@@ -1014,10 +1022,29 @@
1014 return sqlite3_win32_mbcs_to_utf8(zMbcs);
1015 #else
1016 return (char*)zMbcs; /* No-op on unix */
1017 #endif
1018 }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1019
1020 /*
1021 ** Translate UTF8 to MBCS for use in system calls. Return a pointer to the
1022 ** translated text.. Call fossil_mbcs_free() to deallocate any memory
1023 ** used to store the returned pointer when done.
@@ -1028,18 +1055,41 @@
1028 return sqlite3_win32_utf8_to_mbcs(zUtf8);
1029 #else
1030 return (char*)zUtf8; /* No-op on unix */
1031 #endif
1032 }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1033
1034 /*
1035 ** Return the value of an environment variable as UTF8.
1036 */
1037 char *fossil_getenv(const char *zName){
1038 char *zValue = getenv(zName);
1039 #ifdef _WIN32
1040 if( zValue ) zValue = fossil_mbcs_to_utf8(zValue);
 
 
 
 
 
1041 #endif
1042 return zValue;
1043 }
1044
1045 /*
@@ -1085,11 +1135,11 @@
1085
1086 /*
1087 ** Translate MBCS to UTF8. Return a pointer. Call fossil_mbcs_free()
1088 ** to deallocate any memory used to store the returned pointer when done.
1089 */
1090 void fossil_mbcs_free(char *zOld){
1091 #ifdef _WIN32
1092 extern void sqlite3_free(void*);
1093 sqlite3_free(zOld);
1094 #else
1095 /* No-op on unix */
@@ -1098,10 +1148,16 @@
1098
1099 /*
1100 ** Like fopen() but always takes a UTF8 argument.
1101 */
1102 FILE *fossil_fopen(const char *zName, const char *zMode){
1103 char *zMbcs = fossil_utf8_to_mbcs(zName);
1104 FILE *f = fopen(zMbcs, zMode);
1105 fossil_mbcs_free(zMbcs);
 
 
 
 
 
 
1106 return f;
1107 }
1108
--- src/file.c
+++ src/file.c
@@ -1,7 +1,7 @@
1 /*
2 ** Copyright © 2006 D. Richard Hipp
3 **
4 ** This program is free software; you can redistribute it and/or
5 ** modify it under the terms of the Simplified BSD License (also
6 ** known as the "2-Clause License" or "FreeBSD License".)
7
@@ -32,10 +32,11 @@
32
33 /*
34 ** On Windows, include the Platform SDK header file.
35 */
36 #ifdef _WIN32
37 # include <direct.h>
38 # include <windows.h>
39 #endif
40
41 /*
42 ** The file status information from the most recent stat() call.
@@ -68,12 +69,12 @@
69 }else{
70 return stat(zFilename, buf);
71 }
72 #else
73 int rc = 0;
74 wchar_t *zMbcs = fossil_utf8_to_unicode(zFilename);
75 rc = _wstati64(zMbcs, buf);
76 fossil_mbcs_free(zMbcs);
77 return rc;
78 #endif
79 }
80
@@ -298,13 +299,17 @@
299
300 /*
301 ** Wrapper around the access() system call.
302 */
303 int file_access(const char *zFilename, int flags){
304 #ifdef _WIN32
305 wchar_t *zMbcs = fossil_utf8_to_unicode(zFilename);
306 int rc = _waccess(zMbcs, flags);
307 fossil_mbcs_free(zMbcs);
308 #else
309 int rc = access(zFilename, flags);
310 #endif
311 return rc;
312 }
313
314 /*
315 ** Find an unused filename similar to zBase with zSuffix appended.
@@ -389,13 +394,17 @@
394
395 /*
396 ** Delete a file.
397 */
398 void file_delete(const char *zFilename){
399 #ifdef _WIN32
400 wchar_t *z = fossil_utf8_to_unicode(zFilename);
401 _wunlink(z);
402 fossil_mbcs_free(z);
403 #else
404 unlink(zFilename);
405 #endif
406 }
407
408 /*
409 ** Create the directory named in the argument, if it does not already
410 ** exist. If forceFlag is 1, delete any prior non-directory object
@@ -410,12 +419,12 @@
419 file_delete(zName);
420 }
421 if( rc!=1 ){
422 #if defined(_WIN32)
423 int rc;
424 wchar_t *zMbcs = fossil_utf8_to_unicode(zName);
425 rc = _wmkdir(zMbcs);
426 fossil_mbcs_free(zMbcs);
427 return rc;
428 #else
429 return mkdir(zName, 0755);
430 #endif
@@ -561,24 +570,24 @@
570 }
571
572 /*
573 ** Get the current working directory.
574 **
575 ** On windows, the name is converted from unicode to UTF8 and all '\\'
576 ** characters are converted to '/'. No conversions are needed on
577 ** unix.
578 */
579 void file_getcwd(char *zBuf, int nBuf){
580 #ifdef _WIN32
581 char *zPwdUtf8;
582 int nPwd;
583 int i;
584 wchar_t zPwd[2000];
585 if( _wgetcwd(zPwd, sizeof(zPwd)/sizeof(zPwd[0])-1)==0 ){
586 fossil_fatal("cannot find the current working directory.");
587 }
588 zPwdUtf8 = fossil_unicode_to_utf8(zPwd);
589 nPwd = strlen(zPwdUtf8);
590 if( nPwd > nBuf-1 ){
591 fossil_fatal("pwd too big: max %d\n", nBuf-1);
592 }
593 for(i=0; zPwdUtf8[i]; i++) if( zPwdUtf8[i]=='\\' ) zPwdUtf8[i] = '/';
@@ -928,14 +937,14 @@
937 unsigned int i, j;
938 const char *zDir = ".";
939 int cnt = 0;
940
941 #if defined(_WIN32)
942 wchar_t zTmpPath[MAX_PATH];
943
944 if( GetTempPathW(MAX_PATH, zTmpPath) ){
945 azDirs[0] = fossil_unicode_to_utf8(zTmpPath);
946 }
947
948 azDirs[1] = fossil_getenv("TEMP");
949 azDirs[2] = fossil_getenv("TMP");
950 #endif
@@ -994,11 +1003,10 @@
1003 rc = blob_compare(&onDisk, pContent);
1004 blob_reset(&onDisk);
1005 return rc==0;
1006 }
1007
 
1008 /**************************************************************************
1009 ** The following routines translate between MBCS and UTF8 on windows.
1010 ** Since everything is always UTF8 on unix, these routines are no-ops
1011 ** there.
1012 */
@@ -1014,10 +1022,29 @@
1022 return sqlite3_win32_mbcs_to_utf8(zMbcs);
1023 #else
1024 return (char*)zMbcs; /* No-op on unix */
1025 #endif
1026 }
1027
1028 /*
1029 ** Translate Unicode to UTF8. Return a pointer to the translated text.
1030 ** Call fossil_mbcs_free() to deallocate any memory used to store the
1031 ** returned pointer when done.
1032 */
1033 char *fossil_unicode_to_utf8(const void *zUnicode){
1034 #ifdef _WIN32
1035 int nByte = WideCharToMultiByte(CP_UTF8, 0, zUnicode, -1, 0, 0, 0, 0);
1036 char *zUtf = sqlite3_malloc( nByte );
1037 if( zUtf==0 ){
1038 return 0;
1039 }
1040 WideCharToMultiByte(CP_UTF8, 0, zUnicode, -1, zUtf, nByte, 0, 0);
1041 return zUtf;
1042 #else
1043 return (char *)zUnicode; /* No-op on unix */
1044 #endif
1045 }
1046
1047 /*
1048 ** Translate UTF8 to MBCS for use in system calls. Return a pointer to the
1049 ** translated text.. Call fossil_mbcs_free() to deallocate any memory
1050 ** used to store the returned pointer when done.
@@ -1028,18 +1055,41 @@
1055 return sqlite3_win32_utf8_to_mbcs(zUtf8);
1056 #else
1057 return (char*)zUtf8; /* No-op on unix */
1058 #endif
1059 }
1060
1061 /*
1062 ** Translate UTF8 to unicode for use in system calls. Return a pointer to the
1063 ** translated text.. Call fossil_mbcs_free() to deallocate any memory
1064 ** used to store the returned pointer when done.
1065 */
1066 void *fossil_utf8_to_unicode(const char *zUtf8){
1067 #ifdef _WIN32
1068 int nByte = MultiByteToWideChar(CP_UTF8, 0, zUtf8, -1, 0, 0);
1069 wchar_t *zUnicode = sqlite3_malloc( nByte * 2 );
1070 if( zUnicode==0 ){
1071 return 0;
1072 }
1073 MultiByteToWideChar(CP_UTF8, 0, zUtf8, -1, zUnicode, nByte);
1074 return zUnicode;
1075 #else
1076 return (void *)zUtf8; /* No-op on unix */
1077 #endif
1078 }
1079
1080 /*
1081 ** Return the value of an environment variable as UTF8.
1082 */
1083 char *fossil_getenv(const char *zName){
 
1084 #ifdef _WIN32
1085 wchar_t *uName = fossil_utf8_to_unicode(zName);
1086 void *zValue = _wgetenv(uName);
1087 fossil_mbcs_free(uName);
1088 if( zValue ) zValue = fossil_unicode_to_utf8(zValue);
1089 #else
1090 char *zValue = getenv(zName);
1091 #endif
1092 return zValue;
1093 }
1094
1095 /*
@@ -1085,11 +1135,11 @@
1135
1136 /*
1137 ** Translate MBCS to UTF8. Return a pointer. Call fossil_mbcs_free()
1138 ** to deallocate any memory used to store the returned pointer when done.
1139 */
1140 void fossil_mbcs_free(void *zOld){
1141 #ifdef _WIN32
1142 extern void sqlite3_free(void*);
1143 sqlite3_free(zOld);
1144 #else
1145 /* No-op on unix */
@@ -1098,10 +1148,16 @@
1148
1149 /*
1150 ** Like fopen() but always takes a UTF8 argument.
1151 */
1152 FILE *fossil_fopen(const char *zName, const char *zMode){
1153 #ifdef _WIN32
1154 wchar_t *uMode = fossil_utf8_to_unicode(zMode);
1155 wchar_t *uName = fossil_utf8_to_unicode(zName);
1156 FILE *f = _wfopen(uName, uMode);
1157 fossil_mbcs_free(uName);
1158 fossil_mbcs_free(uMode);
1159 #else
1160 FILE *f = fopen(zName, zMode);
1161 #endif
1162 return f;
1163 }
1164
+2 -2
--- src/import.c
+++ src/import.c
@@ -1,7 +1,7 @@
11
/*
2
-** Copyright (c) 2010 D. Richard Hipp
2
+** Copyright © 2010 D. Richard Hipp
33
**
44
** This program is free software; you can redistribute it and/or
55
** modify it under the terms of the Simplified BSD License (also
66
** known as the "2-Clause License" or "FreeBSD License".)
77
@@ -732,11 +732,11 @@
732732
verify_all_options();
733733
if( g.argc!=3 && g.argc!=4 ){
734734
usage("REPOSITORY-NAME");
735735
}
736736
if( g.argc==4 ){
737
- pIn = fopen(g.argv[3], "rb");
737
+ pIn = fossil_fopen(g.argv[3], "rb");
738738
}else{
739739
pIn = stdin;
740740
fossil_binary_mode(pIn);
741741
}
742742
if( !incrFlag ){
743743
--- src/import.c
+++ src/import.c
@@ -1,7 +1,7 @@
1 /*
2 ** Copyright (c) 2010 D. Richard Hipp
3 **
4 ** This program is free software; you can redistribute it and/or
5 ** modify it under the terms of the Simplified BSD License (also
6 ** known as the "2-Clause License" or "FreeBSD License".)
7
@@ -732,11 +732,11 @@
732 verify_all_options();
733 if( g.argc!=3 && g.argc!=4 ){
734 usage("REPOSITORY-NAME");
735 }
736 if( g.argc==4 ){
737 pIn = fopen(g.argv[3], "rb");
738 }else{
739 pIn = stdin;
740 fossil_binary_mode(pIn);
741 }
742 if( !incrFlag ){
743
--- src/import.c
+++ src/import.c
@@ -1,7 +1,7 @@
1 /*
2 ** Copyright © 2010 D. Richard Hipp
3 **
4 ** This program is free software; you can redistribute it and/or
5 ** modify it under the terms of the Simplified BSD License (also
6 ** known as the "2-Clause License" or "FreeBSD License".)
7
@@ -732,11 +732,11 @@
732 verify_all_options();
733 if( g.argc!=3 && g.argc!=4 ){
734 usage("REPOSITORY-NAME");
735 }
736 if( g.argc==4 ){
737 pIn = fossil_fopen(g.argv[3], "rb");
738 }else{
739 pIn = stdin;
740 fossil_binary_mode(pIn);
741 }
742 if( !incrFlag ){
743

Keyboard Shortcuts

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