Fossil SCM

Always convert the result of getenv() into UTF8.

drh 2012-02-16 01:03 trunk
Commit 57152086b87f9ab8c62b6834dd836b7d7cffaca7
+1 -1
--- src/cgi.c
+++ src/cgi.c
@@ -914,11 +914,11 @@
914914
/* If no match is found and the name begins with an upper-case
915915
** letter, then check to see if there is an environment variable
916916
** with the given name.
917917
*/
918918
if( fossil_isupper(zName[0]) ){
919
- const char *zValue = getenv(zName);
919
+ const char *zValue = fossil_getenv(zName);
920920
if( zValue ){
921921
cgi_set_parameter_nocopy(zName, zValue);
922922
CGIDEBUG(("env-match [%s] = [%s]\n", zName, zValue));
923923
return zValue;
924924
}
925925
--- src/cgi.c
+++ src/cgi.c
@@ -914,11 +914,11 @@
914 /* If no match is found and the name begins with an upper-case
915 ** letter, then check to see if there is an environment variable
916 ** with the given name.
917 */
918 if( fossil_isupper(zName[0]) ){
919 const char *zValue = getenv(zName);
920 if( zValue ){
921 cgi_set_parameter_nocopy(zName, zValue);
922 CGIDEBUG(("env-match [%s] = [%s]\n", zName, zValue));
923 return zValue;
924 }
925
--- src/cgi.c
+++ src/cgi.c
@@ -914,11 +914,11 @@
914 /* If no match is found and the name begins with an upper-case
915 ** letter, then check to see if there is an environment variable
916 ** with the given name.
917 */
918 if( fossil_isupper(zName[0]) ){
919 const char *zValue = fossil_getenv(zName);
920 if( zValue ){
921 cgi_set_parameter_nocopy(zName, zValue);
922 CGIDEBUG(("env-match [%s] = [%s]\n", zName, zValue));
923 return zValue;
924 }
925
+2 -2
--- src/checkin.c
+++ src/checkin.c
@@ -456,14 +456,14 @@
456456
);
457457
}
458458
status_report(&text, "# ", 1, 0);
459459
zEditor = db_get("editor", 0);
460460
if( zEditor==0 ){
461
- zEditor = getenv("VISUAL");
461
+ zEditor = fossil_getenv("VISUAL");
462462
}
463463
if( zEditor==0 ){
464
- zEditor = getenv("EDITOR");
464
+ zEditor = fossil_getenv("EDITOR");
465465
}
466466
if( zEditor==0 ){
467467
blob_append(&text,
468468
"#\n"
469469
"# Since no default text editor is set using EDITOR or VISUAL\n"
470470
--- src/checkin.c
+++ src/checkin.c
@@ -456,14 +456,14 @@
456 );
457 }
458 status_report(&text, "# ", 1, 0);
459 zEditor = db_get("editor", 0);
460 if( zEditor==0 ){
461 zEditor = getenv("VISUAL");
462 }
463 if( zEditor==0 ){
464 zEditor = getenv("EDITOR");
465 }
466 if( zEditor==0 ){
467 blob_append(&text,
468 "#\n"
469 "# Since no default text editor is set using EDITOR or VISUAL\n"
470
--- src/checkin.c
+++ src/checkin.c
@@ -456,14 +456,14 @@
456 );
457 }
458 status_report(&text, "# ", 1, 0);
459 zEditor = db_get("editor", 0);
460 if( zEditor==0 ){
461 zEditor = fossil_getenv("VISUAL");
462 }
463 if( zEditor==0 ){
464 zEditor = fossil_getenv("EDITOR");
465 }
466 if( zEditor==0 ){
467 blob_append(&text,
468 "#\n"
469 "# Since no default text editor is set using EDITOR or VISUAL\n"
470
+8 -9
--- src/db.c
+++ src/db.c
@@ -661,11 +661,11 @@
661661
static sqlite3 *openDatabase(const char *zDbName){
662662
int rc;
663663
const char *zVfs;
664664
sqlite3 *db;
665665
666
- zVfs = getenv("FOSSIL_VFS");
666
+ zVfs = fossil_getenv("FOSSIL_VFS");
667667
rc = sqlite3_open_v2(
668668
zDbName, &db,
669669
SQLITE_OPEN_READWRITE | SQLITE_OPEN_CREATE,
670670
zVfs
671671
);
@@ -709,27 +709,26 @@
709709
void db_open_config(int useAttach){
710710
char *zDbName;
711711
const char *zHome;
712712
if( g.configOpen ) return;
713713
#if defined(_WIN32)
714
- zHome = getenv("LOCALAPPDATA");
714
+ zHome = fossil_getenv("LOCALAPPDATA");
715715
if( zHome==0 ){
716
- zHome = getenv("APPDATA");
716
+ zHome = fossil_getenv("APPDATA");
717717
if( zHome==0 ){
718
- char *zDrive = getenv("HOMEDRIVE");
719
- zHome = getenv("HOMEPATH");
718
+ char *zDrive = fossil_getenv("HOMEDRIVE");
719
+ zHome = fossil_getenv("HOMEPATH");
720720
if( zDrive && zHome ) zHome = mprintf("%s%s", zDrive, zHome);
721721
}
722722
}
723723
if( zHome==0 ){
724724
fossil_fatal("cannot locate home directory - "
725725
"please set the LOCALAPPDATA or APPDATA or HOMEPATH "
726726
"environment variables");
727727
}
728
- zHome = fossil_mbcs_to_utf8(zHome);
729728
#else
730
- zHome = getenv("HOME");
729
+ zHome = fossil_getenv("HOME");
731730
if( zHome==0 ){
732731
fossil_fatal("cannot locate home directory - "
733732
"please set the HOME environment variable");
734733
}
735734
#endif
@@ -1143,13 +1142,13 @@
11431142
if( zUser==0 ){
11441143
zUser = db_get("default-user", 0);
11451144
}
11461145
if( zUser==0 ){
11471146
#if defined(_WIN32)
1148
- zUser = getenv("USERNAME");
1147
+ zUser = fossil_getenv("USERNAME");
11491148
#else
1150
- zUser = getenv("USER");
1149
+ zUser = fossil_getenv("USER");
11511150
#endif
11521151
}
11531152
if( zUser==0 ){
11541153
zUser = "root";
11551154
}
11561155
--- src/db.c
+++ src/db.c
@@ -661,11 +661,11 @@
661 static sqlite3 *openDatabase(const char *zDbName){
662 int rc;
663 const char *zVfs;
664 sqlite3 *db;
665
666 zVfs = getenv("FOSSIL_VFS");
667 rc = sqlite3_open_v2(
668 zDbName, &db,
669 SQLITE_OPEN_READWRITE | SQLITE_OPEN_CREATE,
670 zVfs
671 );
@@ -709,27 +709,26 @@
709 void db_open_config(int useAttach){
710 char *zDbName;
711 const char *zHome;
712 if( g.configOpen ) return;
713 #if defined(_WIN32)
714 zHome = getenv("LOCALAPPDATA");
715 if( zHome==0 ){
716 zHome = getenv("APPDATA");
717 if( zHome==0 ){
718 char *zDrive = getenv("HOMEDRIVE");
719 zHome = getenv("HOMEPATH");
720 if( zDrive && zHome ) zHome = mprintf("%s%s", zDrive, zHome);
721 }
722 }
723 if( zHome==0 ){
724 fossil_fatal("cannot locate home directory - "
725 "please set the LOCALAPPDATA or APPDATA or HOMEPATH "
726 "environment variables");
727 }
728 zHome = fossil_mbcs_to_utf8(zHome);
729 #else
730 zHome = getenv("HOME");
731 if( zHome==0 ){
732 fossil_fatal("cannot locate home directory - "
733 "please set the HOME environment variable");
734 }
735 #endif
@@ -1143,13 +1142,13 @@
1143 if( zUser==0 ){
1144 zUser = db_get("default-user", 0);
1145 }
1146 if( zUser==0 ){
1147 #if defined(_WIN32)
1148 zUser = getenv("USERNAME");
1149 #else
1150 zUser = getenv("USER");
1151 #endif
1152 }
1153 if( zUser==0 ){
1154 zUser = "root";
1155 }
1156
--- src/db.c
+++ src/db.c
@@ -661,11 +661,11 @@
661 static sqlite3 *openDatabase(const char *zDbName){
662 int rc;
663 const char *zVfs;
664 sqlite3 *db;
665
666 zVfs = fossil_getenv("FOSSIL_VFS");
667 rc = sqlite3_open_v2(
668 zDbName, &db,
669 SQLITE_OPEN_READWRITE | SQLITE_OPEN_CREATE,
670 zVfs
671 );
@@ -709,27 +709,26 @@
709 void db_open_config(int useAttach){
710 char *zDbName;
711 const char *zHome;
712 if( g.configOpen ) return;
713 #if defined(_WIN32)
714 zHome = fossil_getenv("LOCALAPPDATA");
715 if( zHome==0 ){
716 zHome = fossil_getenv("APPDATA");
717 if( zHome==0 ){
718 char *zDrive = fossil_getenv("HOMEDRIVE");
719 zHome = fossil_getenv("HOMEPATH");
720 if( zDrive && zHome ) zHome = mprintf("%s%s", zDrive, zHome);
721 }
722 }
723 if( zHome==0 ){
724 fossil_fatal("cannot locate home directory - "
725 "please set the LOCALAPPDATA or APPDATA or HOMEPATH "
726 "environment variables");
727 }
 
728 #else
729 zHome = fossil_getenv("HOME");
730 if( zHome==0 ){
731 fossil_fatal("cannot locate home directory - "
732 "please set the HOME environment variable");
733 }
734 #endif
@@ -1143,13 +1142,13 @@
1142 if( zUser==0 ){
1143 zUser = db_get("default-user", 0);
1144 }
1145 if( zUser==0 ){
1146 #if defined(_WIN32)
1147 zUser = fossil_getenv("USERNAME");
1148 #else
1149 zUser = fossil_getenv("USER");
1150 #endif
1151 }
1152 if( zUser==0 ){
1153 zUser = "root";
1154 }
1155
+11
--- src/file.c
+++ src/file.c
@@ -961,10 +961,21 @@
961961
return sqlite3_win32_utf8_to_mbcs(zUtf8);
962962
#else
963963
return (char*)zUtf8; /* No-op on unix */
964964
#endif
965965
}
966
+
967
+/*
968
+** Return the value of an environment variable as UTF8.
969
+*/
970
+char *fossil_getenv(const char *zName){
971
+ char *zValue = getenv(zName);
972
+#ifdef _WIN32
973
+ if( zValue ) zValue = fossil_msbc_to_utf8(zValue);
974
+#endif
975
+ return zValue;
976
+}
966977
967978
/*
968979
** Translate UTF8 to MBCS for display on the console. Return a pointer to the
969980
** translated text.. Call fossil_mbcs_free() to deallocate any memory
970981
** used to store the returned pointer when done.
971982
--- src/file.c
+++ src/file.c
@@ -961,10 +961,21 @@
961 return sqlite3_win32_utf8_to_mbcs(zUtf8);
962 #else
963 return (char*)zUtf8; /* No-op on unix */
964 #endif
965 }
 
 
 
 
 
 
 
 
 
 
 
966
967 /*
968 ** Translate UTF8 to MBCS for display on the console. Return a pointer to the
969 ** translated text.. Call fossil_mbcs_free() to deallocate any memory
970 ** used to store the returned pointer when done.
971
--- src/file.c
+++ src/file.c
@@ -961,10 +961,21 @@
961 return sqlite3_win32_utf8_to_mbcs(zUtf8);
962 #else
963 return (char*)zUtf8; /* No-op on unix */
964 #endif
965 }
966
967 /*
968 ** Return the value of an environment variable as UTF8.
969 */
970 char *fossil_getenv(const char *zName){
971 char *zValue = getenv(zName);
972 #ifdef _WIN32
973 if( zValue ) zValue = fossil_msbc_to_utf8(zValue);
974 #endif
975 return zValue;
976 }
977
978 /*
979 ** Translate UTF8 to MBCS for display on the console. Return a pointer to the
980 ** translated text.. Call fossil_mbcs_free() to deallocate any memory
981 ** used to store the returned pointer when done.
982
+1 -1
--- src/json.c
+++ src/json.c
@@ -435,11 +435,11 @@
435435
if(!cv && !g.isHTTP){
436436
/* reminder to self: in CLI mode i'd like to try
437437
find_option(zKey,NULL,XYZ) here, but we don't have a sane
438438
default for the XYZ param here.
439439
*/
440
- cv = getenv(zKey);
440
+ cv = fossil_getenv(zKey);
441441
}
442442
if(cv){/*transform it to JSON for later use.*/
443443
/* use sscanf() to figure out if it's an int,
444444
and transform it to JSON int if it is.
445445
446446
--- src/json.c
+++ src/json.c
@@ -435,11 +435,11 @@
435 if(!cv && !g.isHTTP){
436 /* reminder to self: in CLI mode i'd like to try
437 find_option(zKey,NULL,XYZ) here, but we don't have a sane
438 default for the XYZ param here.
439 */
440 cv = getenv(zKey);
441 }
442 if(cv){/*transform it to JSON for later use.*/
443 /* use sscanf() to figure out if it's an int,
444 and transform it to JSON int if it is.
445
446
--- src/json.c
+++ src/json.c
@@ -435,11 +435,11 @@
435 if(!cv && !g.isHTTP){
436 /* reminder to self: in CLI mode i'd like to try
437 find_option(zKey,NULL,XYZ) here, but we don't have a sane
438 default for the XYZ param here.
439 */
440 cv = fossil_getenv(zKey);
441 }
442 if(cv){/*transform it to JSON for later use.*/
443 /* use sscanf() to figure out if it's an int,
444 and transform it to JSON int if it is.
445
446
+2 -2
--- src/main.c
+++ src/main.c
@@ -439,11 +439,11 @@
439439
#endif /* FOSSIL_ENABLE_JSON */
440440
expand_args_option();
441441
argc = g.argc;
442442
argv = g.argv;
443443
for(i=0; i<argc; i++) g.argv[i] = fossil_mbcs_to_utf8(argv[i]);
444
- if( getenv("GATEWAY_INTERFACE")!=0 && !find_option("nocgi", 0, 0)){
444
+ if( fossil_getenv("GATEWAY_INTERFACE")!=0 && !find_option("nocgi", 0, 0)){
445445
zCmdName = "cgi";
446446
g.isHTTP = 1;
447447
}else if( argc<2 ){
448448
fossil_print(
449449
"Usage: %s COMMAND ...\n"
@@ -1629,11 +1629,11 @@
16291629
/*
16301630
** Search for an executable on the PATH environment variable.
16311631
** Return true (1) if found and false (0) if not found.
16321632
*/
16331633
static int binaryOnPath(const char *zBinary){
1634
- const char *zPath = getenv("PATH");
1634
+ const char *zPath = fossil_getenv("PATH");
16351635
char *zFull;
16361636
int i;
16371637
int bExists;
16381638
while( zPath && zPath[0] ){
16391639
while( zPath[0]==':' ) zPath++;
16401640
--- src/main.c
+++ src/main.c
@@ -439,11 +439,11 @@
439 #endif /* FOSSIL_ENABLE_JSON */
440 expand_args_option();
441 argc = g.argc;
442 argv = g.argv;
443 for(i=0; i<argc; i++) g.argv[i] = fossil_mbcs_to_utf8(argv[i]);
444 if( getenv("GATEWAY_INTERFACE")!=0 && !find_option("nocgi", 0, 0)){
445 zCmdName = "cgi";
446 g.isHTTP = 1;
447 }else if( argc<2 ){
448 fossil_print(
449 "Usage: %s COMMAND ...\n"
@@ -1629,11 +1629,11 @@
1629 /*
1630 ** Search for an executable on the PATH environment variable.
1631 ** Return true (1) if found and false (0) if not found.
1632 */
1633 static int binaryOnPath(const char *zBinary){
1634 const char *zPath = getenv("PATH");
1635 char *zFull;
1636 int i;
1637 int bExists;
1638 while( zPath && zPath[0] ){
1639 while( zPath[0]==':' ) zPath++;
1640
--- src/main.c
+++ src/main.c
@@ -439,11 +439,11 @@
439 #endif /* FOSSIL_ENABLE_JSON */
440 expand_args_option();
441 argc = g.argc;
442 argv = g.argv;
443 for(i=0; i<argc; i++) g.argv[i] = fossil_mbcs_to_utf8(argv[i]);
444 if( fossil_getenv("GATEWAY_INTERFACE")!=0 && !find_option("nocgi", 0, 0)){
445 zCmdName = "cgi";
446 g.isHTTP = 1;
447 }else if( argc<2 ){
448 fossil_print(
449 "Usage: %s COMMAND ...\n"
@@ -1629,11 +1629,11 @@
1629 /*
1630 ** Search for an executable on the PATH environment variable.
1631 ** Return true (1) if found and false (0) if not found.
1632 */
1633 static int binaryOnPath(const char *zBinary){
1634 const char *zPath = fossil_getenv("PATH");
1635 char *zFull;
1636 int i;
1637 int bExists;
1638 while( zPath && zPath[0] ){
1639 while( zPath[0]==':' ) zPath++;
1640
--- src/report.c
+++ src/report.c
@@ -1141,6 +1141,5 @@
11411141
report_unrestrict_sql();
11421142
if( zFilter ){
11431143
free(zSql);
11441144
}
11451145
}
1146
-
11471146
--- src/report.c
+++ src/report.c
@@ -1141,6 +1141,5 @@
1141 report_unrestrict_sql();
1142 if( zFilter ){
1143 free(zSql);
1144 }
1145 }
1146
1147
--- src/report.c
+++ src/report.c
@@ -1141,6 +1141,5 @@
1141 report_unrestrict_sql();
1142 if( zFilter ){
1143 free(zSql);
1144 }
1145 }
 
1146
+1 -1
--- src/url.c
+++ src/url.c
@@ -265,11 +265,11 @@
265265
const char *zProxy;
266266
zProxy = zProxyOpt;
267267
if( zProxy==0 ){
268268
zProxy = db_get("proxy", 0);
269269
if( zProxy==0 || zProxy[0]==0 || is_truth(zProxy) ){
270
- zProxy = getenv("http_proxy");
270
+ zProxy = fossil_getenv("http_proxy");
271271
}
272272
}
273273
if( zProxy && zProxy[0] && !is_false(zProxy) ){
274274
char *zOriginalUrl = g.urlCanonical;
275275
char *zOriginalHost = g.urlHostname;
276276
--- src/url.c
+++ src/url.c
@@ -265,11 +265,11 @@
265 const char *zProxy;
266 zProxy = zProxyOpt;
267 if( zProxy==0 ){
268 zProxy = db_get("proxy", 0);
269 if( zProxy==0 || zProxy[0]==0 || is_truth(zProxy) ){
270 zProxy = getenv("http_proxy");
271 }
272 }
273 if( zProxy && zProxy[0] && !is_false(zProxy) ){
274 char *zOriginalUrl = g.urlCanonical;
275 char *zOriginalHost = g.urlHostname;
276
--- src/url.c
+++ src/url.c
@@ -265,11 +265,11 @@
265 const char *zProxy;
266 zProxy = zProxyOpt;
267 if( zProxy==0 ){
268 zProxy = db_get("proxy", 0);
269 if( zProxy==0 || zProxy[0]==0 || is_truth(zProxy) ){
270 zProxy = fossil_getenv("http_proxy");
271 }
272 }
273 if( zProxy && zProxy[0] && !is_false(zProxy) ){
274 char *zOriginalUrl = g.urlCanonical;
275 char *zOriginalHost = g.urlHostname;
276
+1 -1
--- src/user.c
+++ src/user.c
@@ -324,11 +324,11 @@
324324
325325
if( g.localOpen && attempt_user(db_lget("default-user",0)) ) return;
326326
327327
if( attempt_user(db_get("default-user", 0)) ) return;
328328
329
- if( attempt_user(getenv("USER")) ) return;
329
+ if( attempt_user(fossil_getenv("USER")) ) return;
330330
331331
db_prepare(&s,
332332
"SELECT uid, login FROM user"
333333
" WHERE login NOT IN ('anonymous','nobody','reader','developer')"
334334
);
335335
--- src/user.c
+++ src/user.c
@@ -324,11 +324,11 @@
324
325 if( g.localOpen && attempt_user(db_lget("default-user",0)) ) return;
326
327 if( attempt_user(db_get("default-user", 0)) ) return;
328
329 if( attempt_user(getenv("USER")) ) return;
330
331 db_prepare(&s,
332 "SELECT uid, login FROM user"
333 " WHERE login NOT IN ('anonymous','nobody','reader','developer')"
334 );
335
--- src/user.c
+++ src/user.c
@@ -324,11 +324,11 @@
324
325 if( g.localOpen && attempt_user(db_lget("default-user",0)) ) return;
326
327 if( attempt_user(db_get("default-user", 0)) ) return;
328
329 if( attempt_user(fossil_getenv("USER")) ) return;
330
331 db_prepare(&s,
332 "SELECT uid, login FROM user"
333 " WHERE login NOT IN ('anonymous','nobody','reader','developer')"
334 );
335

Keyboard Shortcuts

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