diff options
| author | Even Rouault <even.rouault@spatialys.com> | 2015-07-07 18:46:36 +0200 |
|---|---|---|
| committer | Even Rouault <even.rouault@spatialys.com> | 2015-07-07 18:46:36 +0200 |
| commit | 2b5b97942016c2f18a0992b934d1b6b460391dac (patch) | |
| tree | 46cffbdad4a652422cc94f6077e3ab3955e6dc0f /src/cs2cs.c | |
| parent | 396afc3312243ff4a8e95c3b9398d56c5582e30d (diff) | |
| download | PROJ-2b5b97942016c2f18a0992b934d1b6b460391dac.tar.gz PROJ-2b5b97942016c2f18a0992b934d1b6b460391dac.zip | |
Make pj_init() locale safe and no longer modify locale (#226)
Remove setlocale() use in pj_init_ctx(), and replace uses of atof() &
strtod() by their locale safe variants pj_atof() and pj_strtod().
Proj versions from now advertize #define PJ_LOCALE_SAFE 1 in proj_api.h
and export pj_atof() & pj_strtod()
Diffstat (limited to 'src/cs2cs.c')
| -rw-r--r-- | src/cs2cs.c | 19 |
1 files changed, 19 insertions, 0 deletions
diff --git a/src/cs2cs.c b/src/cs2cs.c index 43f7bf86..90369326 100644 --- a/src/cs2cs.c +++ b/src/cs2cs.c @@ -33,6 +33,7 @@ #include <string.h> #include <math.h> #include "emess.h" +#include <locale.h> #define MAX_LINE 1000 #define MAX_PARGS 100 @@ -167,6 +168,12 @@ int main(int argc, char **argv) FILE *fid; int from_argc=0, to_argc=0, eargc = 0, c, mon = 0; int have_to_flag = 0, inverse = 0, i; + int use_env_locale = 0; + + /* This is just to check that pj_init() is locale-safe */ + /* Used by nad/testvarious */ + if( getenv("PROJ_USE_ENV_LOCALE") != NULL ) + use_env_locale = 1; if ((emess_dat.Prog_name = strrchr(*argv,DIR_CHAR)) != NULL) ++emess_dat.Prog_name; @@ -336,6 +343,12 @@ int main(int argc, char **argv) to_argc = argcount; } + if( use_env_locale ) + { + /* Set locale from environment */ + setlocale(LC_ALL, ""); + } + if( from_argc == 0 && to_argc != 0 ) { /* we will generate the from proj as the latlong of the +to in a bit */ @@ -389,6 +402,12 @@ int main(int argc, char **argv) } } + if( use_env_locale ) + { + /* Restore C locale to avoid issues in parsing/outputing numbers*/ + setlocale(LC_ALL, "C"); + } + if (mon) { printf( "%c ---- From Coordinate System ----\n", tag ); pj_pr_list(fromProj); |
