@@ -72,22 +72,39 @@ static PQExpBufferData show_buf;
7272static bool first_instance = true;
7373static int32 json_level = 0 ;
7474
75+ static const char * lc_env_locale ;
7576typedef enum {
76- LOCALE_PROBACKUP ,
77+ LOCALE_OUTPUT ,
7778 LOCALE_ENV
7879} output_numeric_locale ;
7980
81+ #ifdef HAVE_USELOCALE
82+ static locale_t env_locale , out_locale ;
83+ #endif
84+ void memorize_environment_locale () {
85+ lc_env_locale = (const char * )getenv ("LC_NUMERIC" );
86+ lc_env_locale = lc_env_locale != NULL ? lc_env_locale : "C" ;
87+ #ifdef HAVE_USELOCALE
88+ env_locale = newlocale (LC_NUMERIC_MASK , lc_env_locale , (locale_t )0 );
89+ out_locale = newlocale (LC_NUMERIC_MASK , "C" , (locale_t )0 );
90+ #endif
91+ }
92+
93+ void free_environment_locale () {
94+ #ifdef HAVE_USELOCALE
95+ freelocale (env_locale );
96+ freelocale (out_locale );
97+ #endif
98+ }
99+
80100static void set_output_numeric_locale (output_numeric_locale loc ) {
81- const char * l = loc == LOCALE_PROBACKUP ? "C" :
82- getenv ("LC_NUMERIC" ) != NULL ? (const char * )getenv ("LC_NUMERIC" ) : "C" ;
83- // Setting environment-specified locale
84101#ifdef HAVE_USELOCALE
85- uselocale (newlocale ( LC_NUMERIC_MASK , l , ( locale_t ) 0 ) );
102+ uselocale (loc == LOCALE_OUTPUT ? out_locale : env_locale );
86103#else
87104#ifdef HAVE__CONFIGTHREADLOCALE
88105 _configthreadlocale (_ENABLE_PER_THREAD_LOCALE );
89106#endif
90- setlocale (LC_NUMERIC , l );
107+ setlocale (LC_NUMERIC , loc == LOCALE_OUTPUT ? lc_env_locale : "C" );
91108#endif
92109}
93110
@@ -131,7 +148,7 @@ do_show(CatalogState *catalogState, InstanceState *instanceState,
131148 show_instance (instanceState , INVALID_BACKUP_ID , true);
132149 }
133150 show_instance_end ();
134- set_output_numeric_locale (LOCALE_PROBACKUP );
151+ set_output_numeric_locale (LOCALE_OUTPUT );
135152
136153 return 0 ;
137154 }
@@ -150,7 +167,7 @@ do_show(CatalogState *catalogState, InstanceState *instanceState,
150167 show_instance (instanceState , requested_backup_id , false);
151168
152169 show_instance_end ();
153- set_output_numeric_locale (LOCALE_PROBACKUP );
170+ set_output_numeric_locale (LOCALE_OUTPUT );
154171
155172 return 0 ;
156173 }
@@ -164,7 +181,7 @@ do_show(CatalogState *catalogState, InstanceState *instanceState,
164181 else
165182 show_backup (instanceState , requested_backup_id );
166183
167- set_output_numeric_locale (LOCALE_PROBACKUP );
184+ set_output_numeric_locale (LOCALE_OUTPUT );
168185 return 0 ;
169186 }
170187}
0 commit comments