|
39 | 39 | * Portions Copyright (c) 1994, Regents of the University of California
|
40 | 40 | * Portions taken from FreeBSD.
|
41 | 41 | *
|
42 |
| - * $PostgreSQL: pgsql/src/bin/initdb/initdb.c,v 1.56 2004/10/06 09:13:10 momjian Exp $ |
| 42 | + * $PostgreSQL: pgsql/src/bin/initdb/initdb.c,v 1.57 2004/10/07 16:53:25 momjian Exp $ |
43 | 43 | *
|
44 | 44 | *-------------------------------------------------------------------------
|
45 | 45 | */
|
@@ -181,6 +181,7 @@ static void vacuum_db(void);
|
181 | 181 | static void make_template0(void);
|
182 | 182 | static void trapsig(int signum);
|
183 | 183 | static void check_ok(void);
|
| 184 | +static void escape_locale(char **locale); |
184 | 185 | static bool chklocale(const char *locale);
|
185 | 186 | static void setlocales(void);
|
186 | 187 | static void usage(const char *progname);
|
@@ -1099,16 +1100,20 @@ setup_config(void)
|
1099 | 1100 | snprintf(repltok, sizeof(repltok), "shared_buffers = %d", n_buffers);
|
1100 | 1101 | conflines = replace_token(conflines, "#shared_buffers = 1000", repltok);
|
1101 | 1102 |
|
| 1103 | + |
| 1104 | + escape_locale(&lc_messages); |
1102 | 1105 | snprintf(repltok, sizeof(repltok), "lc_messages = '%s'", lc_messages);
|
1103 | 1106 | conflines = replace_token(conflines, "#lc_messages = 'C'", repltok);
|
1104 | 1107 |
|
| 1108 | + escape_locale(&lc_monetary); |
1105 | 1109 | snprintf(repltok, sizeof(repltok), "lc_monetary = '%s'", lc_monetary);
|
1106 | 1110 | conflines = replace_token(conflines, "#lc_monetary = 'C'", repltok);
|
1107 | 1111 |
|
| 1112 | + escape_locale(&lc_numeric); |
1108 | 1113 | snprintf(repltok, sizeof(repltok), "lc_numeric = '%s'", lc_numeric);
|
1109 |
| - |
1110 | 1114 | conflines = replace_token(conflines, "#lc_numeric = 'C'", repltok);
|
1111 | 1115 |
|
| 1116 | + escape_locale(&lc_time); |
1112 | 1117 | snprintf(repltok, sizeof(repltok), "lc_time = '%s'", lc_time);
|
1113 | 1118 | conflines = replace_token(conflines, "#lc_time = 'C'", repltok);
|
1114 | 1119 |
|
@@ -1896,11 +1901,27 @@ check_ok()
|
1896 | 1901 | }
|
1897 | 1902 | }
|
1898 | 1903 |
|
| 1904 | +/* |
| 1905 | + * Escape any single quotes or backslashes in locale |
| 1906 | + */ |
| 1907 | +static void |
| 1908 | +escape_locale(char **locale) |
| 1909 | +{ |
| 1910 | + int len = strlen(*locale), |
| 1911 | + i, j; |
| 1912 | + char *loc_temp = xmalloc(len * 2); |
| 1913 | + |
| 1914 | + for (i = 0, j = 0; i < len; i++) |
| 1915 | + { |
| 1916 | + if ((*locale)[i] == '\'' || (*locale)[i] == '\\') |
| 1917 | + loc_temp[j++] = '\\'; |
| 1918 | + loc_temp[j++] = (*locale)[i]; |
| 1919 | + } |
| 1920 | + *locale = loc_temp; |
| 1921 | +} |
1899 | 1922 |
|
1900 | 1923 | /*
|
1901 | 1924 | * check if given string is a valid locale specifier
|
1902 |
| - * based on some code given to me by Peter Eisentraut |
1903 |
| - * (but I take responsibility for it :-) |
1904 | 1925 | */
|
1905 | 1926 | static bool
|
1906 | 1927 | chklocale(const char *locale)
|
|
0 commit comments