@@ -145,7 +145,7 @@ static char *xlog_dir = NULL;
145
145
146
146
/* internal vars */
147
147
static const char * progname ;
148
- static char * encodingid = "0" ;
148
+ static int encodingid ;
149
149
static char * bki_file ;
150
150
static char * desc_file ;
151
151
static char * shdesc_file ;
@@ -236,7 +236,7 @@ static void writefile(char *path, char **lines);
236
236
static FILE * popen_check (const char * command , const char * mode );
237
237
static void exit_nicely (void );
238
238
static char * get_id (void );
239
- static char * get_encoding_id (char * encoding_name );
239
+ static int get_encoding_id (char * encoding_name );
240
240
static void set_input (char * * dest , char * filename );
241
241
static void check_input (char * path );
242
242
static void write_version_file (char * extrapath );
@@ -636,15 +636,15 @@ encodingid_to_string(int enc)
636
636
/*
637
637
* get the encoding id for a given encoding name
638
638
*/
639
- static char *
639
+ static int
640
640
get_encoding_id (char * encoding_name )
641
641
{
642
642
int enc ;
643
643
644
644
if (encoding_name && * encoding_name )
645
645
{
646
646
if ((enc = pg_valid_server_encoding (encoding_name )) >= 0 )
647
- return encodingid_to_string ( enc ) ;
647
+ return enc ;
648
648
}
649
649
fprintf (stderr , _ ("%s: \"%s\" is not a valid server encoding name\n" ),
650
650
progname , encoding_name ? encoding_name : "(null)" );
@@ -1328,7 +1328,7 @@ bootstrap_template1(void)
1328
1328
1329
1329
bki_lines = replace_token (bki_lines , "POSTGRES" , escape_quotes (username ));
1330
1330
1331
- bki_lines = replace_token (bki_lines , "ENCODING" , encodingid );
1331
+ bki_lines = replace_token (bki_lines , "ENCODING" , encodingid_to_string ( encodingid ) );
1332
1332
1333
1333
bki_lines = replace_token (bki_lines , "LC_COLLATE" , escape_quotes (lc_collate ));
1334
1334
@@ -2454,8 +2454,6 @@ setup_bin_paths(const char *argv0)
2454
2454
void
2455
2455
setup_locale_encoding (void )
2456
2456
{
2457
- int user_enc ;
2458
-
2459
2457
setlocales ();
2460
2458
2461
2459
if (strcmp (lc_ctype , lc_collate ) == 0 &&
@@ -2505,12 +2503,11 @@ setup_locale_encoding(void)
2505
2503
* UTF-8.
2506
2504
*/
2507
2505
#ifdef WIN32
2506
+ encodingid = PG_UTF8 ;
2508
2507
printf (_ ("Encoding \"%s\" implied by locale is not allowed as a server-side encoding.\n"
2509
2508
"The default database encoding will be set to \"%s\" instead.\n" ),
2510
2509
pg_encoding_to_char (ctype_enc ),
2511
- pg_encoding_to_char (PG_UTF8 ));
2512
- ctype_enc = PG_UTF8 ;
2513
- encodingid = encodingid_to_string (ctype_enc );
2510
+ pg_encoding_to_char (encodingid ));
2514
2511
#else
2515
2512
fprintf (stderr ,
2516
2513
_ ("%s: locale \"%s\" requires unsupported encoding \"%s\"\n" ),
@@ -2524,17 +2521,16 @@ setup_locale_encoding(void)
2524
2521
}
2525
2522
else
2526
2523
{
2527
- encodingid = encodingid_to_string ( ctype_enc ) ;
2524
+ encodingid = ctype_enc ;
2528
2525
printf (_ ("The default database encoding has accordingly been set to \"%s\".\n" ),
2529
- pg_encoding_to_char (ctype_enc ));
2526
+ pg_encoding_to_char (encodingid ));
2530
2527
}
2531
2528
}
2532
2529
else
2533
2530
encodingid = get_encoding_id (encoding );
2534
2531
2535
- user_enc = atoi (encodingid );
2536
- if (!check_locale_encoding (lc_ctype , user_enc ) ||
2537
- !check_locale_encoding (lc_collate , user_enc ))
2532
+ if (!check_locale_encoding (lc_ctype , encodingid ) ||
2533
+ !check_locale_encoding (lc_collate , encodingid ))
2538
2534
exit (1 ); /* check_locale_encoding printed the error */
2539
2535
2540
2536
}
0 commit comments