Skip to content

Commit ee24d2b

Browse files
committed
Clean up excessive code
The encoding ID was converted between string and number too many times, probably a remnant from the shell script days. Reviewed-by: Aleksandr Parfenov <a.parfenov@postgrespro.ru>
1 parent 8e67380 commit ee24d2b

File tree

1 file changed

+11
-15
lines changed

1 file changed

+11
-15
lines changed

src/bin/initdb/initdb.c

Lines changed: 11 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,7 @@ static char *xlog_dir = NULL;
145145

146146
/* internal vars */
147147
static const char *progname;
148-
static char *encodingid = "0";
148+
static int encodingid;
149149
static char *bki_file;
150150
static char *desc_file;
151151
static char *shdesc_file;
@@ -236,7 +236,7 @@ static void writefile(char *path, char **lines);
236236
static FILE *popen_check(const char *command, const char *mode);
237237
static void exit_nicely(void);
238238
static char *get_id(void);
239-
static char *get_encoding_id(char *encoding_name);
239+
static int get_encoding_id(char *encoding_name);
240240
static void set_input(char **dest, char *filename);
241241
static void check_input(char *path);
242242
static void write_version_file(char *extrapath);
@@ -636,15 +636,15 @@ encodingid_to_string(int enc)
636636
/*
637637
* get the encoding id for a given encoding name
638638
*/
639-
static char *
639+
static int
640640
get_encoding_id(char *encoding_name)
641641
{
642642
int enc;
643643

644644
if (encoding_name && *encoding_name)
645645
{
646646
if ((enc = pg_valid_server_encoding(encoding_name)) >= 0)
647-
return encodingid_to_string(enc);
647+
return enc;
648648
}
649649
fprintf(stderr, _("%s: \"%s\" is not a valid server encoding name\n"),
650650
progname, encoding_name ? encoding_name : "(null)");
@@ -1328,7 +1328,7 @@ bootstrap_template1(void)
13281328

13291329
bki_lines = replace_token(bki_lines, "POSTGRES", escape_quotes(username));
13301330

1331-
bki_lines = replace_token(bki_lines, "ENCODING", encodingid);
1331+
bki_lines = replace_token(bki_lines, "ENCODING", encodingid_to_string(encodingid));
13321332

13331333
bki_lines = replace_token(bki_lines, "LC_COLLATE", escape_quotes(lc_collate));
13341334

@@ -2454,8 +2454,6 @@ setup_bin_paths(const char *argv0)
24542454
void
24552455
setup_locale_encoding(void)
24562456
{
2457-
int user_enc;
2458-
24592457
setlocales();
24602458

24612459
if (strcmp(lc_ctype, lc_collate) == 0 &&
@@ -2505,12 +2503,11 @@ setup_locale_encoding(void)
25052503
* UTF-8.
25062504
*/
25072505
#ifdef WIN32
2506+
encodingid = PG_UTF8;
25082507
printf(_("Encoding \"%s\" implied by locale is not allowed as a server-side encoding.\n"
25092508
"The default database encoding will be set to \"%s\" instead.\n"),
25102509
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));
25142511
#else
25152512
fprintf(stderr,
25162513
_("%s: locale \"%s\" requires unsupported encoding \"%s\"\n"),
@@ -2524,17 +2521,16 @@ setup_locale_encoding(void)
25242521
}
25252522
else
25262523
{
2527-
encodingid = encodingid_to_string(ctype_enc);
2524+
encodingid = ctype_enc;
25282525
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));
25302527
}
25312528
}
25322529
else
25332530
encodingid = get_encoding_id(encoding);
25342531

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))
25382534
exit(1); /* check_locale_encoding printed the error */
25392535

25402536
}

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy