|
42 | 42 | * Portions Copyright (c) 1994, Regents of the University of California
|
43 | 43 | * Portions taken from FreeBSD.
|
44 | 44 | *
|
45 |
| - * $PostgreSQL: pgsql/src/bin/initdb/initdb.c,v 1.100 2005/11/22 18:17:28 momjian Exp $ |
| 45 | + * $PostgreSQL: pgsql/src/bin/initdb/initdb.c,v 1.101 2005/12/09 15:51:14 petere Exp $ |
46 | 46 | *
|
47 | 47 | *-------------------------------------------------------------------------
|
48 | 48 | */
|
|
57 | 57 | #ifdefHAVE_LANGINFO_H
|
58 | 58 | #include<langinfo.h>
|
59 | 59 | #endif
|
| 60 | +#include<time.h> |
60 | 61 |
|
61 | 62 | #include"libpq/pqsignal.h"
|
62 | 63 | #include"mb/pg_wchar.h"
|
63 | 64 | #include"getaddrinfo.h"
|
64 | 65 | #include"getopt_long.h"
|
| 66 | +#include"miscadmin.h" |
65 | 67 |
|
66 | 68 | #ifndefHAVE_INT_OPTRESET
|
67 | 69 | intoptreset;
|
@@ -186,6 +188,7 @@ static void make_postgres(void);
|
186 | 188 | staticvoidtrapsig(intsignum);
|
187 | 189 | staticvoidcheck_ok(void);
|
188 | 190 | staticchar*escape_quotes(constchar*src);
|
| 191 | +staticintlocale_date_order(constchar*locale); |
189 | 192 | staticboolchklocale(constchar*locale);
|
190 | 193 | staticvoidsetlocales(void);
|
191 | 194 | staticvoidusage(constchar*progname);
|
@@ -1195,6 +1198,20 @@ setup_config(void)
|
1195 | 1198 | snprintf(repltok,sizeof(repltok),"lc_time = '%s'",lc_time);
|
1196 | 1199 | conflines=replace_token(conflines,"#lc_time = 'C'",repltok);
|
1197 | 1200 |
|
| 1201 | +switch (locale_date_order(lc_time)) { |
| 1202 | +caseDATEORDER_YMD: |
| 1203 | +strcpy(repltok,"datestyle = 'iso, ymd'"); |
| 1204 | +break; |
| 1205 | +caseDATEORDER_DMY: |
| 1206 | +strcpy(repltok,"datestyle = 'iso, dmy'"); |
| 1207 | +break; |
| 1208 | +caseDATEORDER_MDY: |
| 1209 | +default: |
| 1210 | +strcpy(repltok,"datestyle = 'iso, mdy'"); |
| 1211 | +break; |
| 1212 | +} |
| 1213 | +conflines=replace_token(conflines,"#datestyle = 'iso, mdy'",repltok); |
| 1214 | + |
1198 | 1215 | snprintf(path,sizeof(path),"%s/postgresql.conf",pg_data);
|
1199 | 1216 |
|
1200 | 1217 | writefile(path,conflines);
|
@@ -2052,6 +2069,60 @@ escape_quotes(const char *src)
|
2052 | 2069 | returnresult;
|
2053 | 2070 | }
|
2054 | 2071 |
|
| 2072 | +/* |
| 2073 | + * Determine likely date order from locale |
| 2074 | + */ |
| 2075 | +staticint |
| 2076 | +locale_date_order(constchar*locale) |
| 2077 | +{ |
| 2078 | +structtmtesttime; |
| 2079 | +charbuf[128]; |
| 2080 | +char*posD; |
| 2081 | +char*posM; |
| 2082 | +char*posY; |
| 2083 | +char*save; |
| 2084 | +size_tres; |
| 2085 | +intresult; |
| 2086 | + |
| 2087 | +result=DATEORDER_MDY;/* default */ |
| 2088 | + |
| 2089 | +save=setlocale(LC_TIME,NULL); |
| 2090 | +if (!save) |
| 2091 | +returnresult; |
| 2092 | +save=xstrdup(save); |
| 2093 | + |
| 2094 | +setlocale(LC_TIME,locale); |
| 2095 | + |
| 2096 | +memset(&testtime,0,sizeof(testtime)); |
| 2097 | +testtime.tm_mday=22; |
| 2098 | +testtime.tm_mon=10;/* November, should come out as "11" */ |
| 2099 | +testtime.tm_year=133;/* 2033 */ |
| 2100 | + |
| 2101 | +res=strftime(buf,sizeof(buf),"%x",&testtime); |
| 2102 | + |
| 2103 | +setlocale(LC_TIME,save); |
| 2104 | +free(save); |
| 2105 | + |
| 2106 | +if (res==0) |
| 2107 | +returnresult; |
| 2108 | + |
| 2109 | +posM=strstr(buf,"11"); |
| 2110 | +posD=strstr(buf,"22"); |
| 2111 | +posY=strstr(buf,"33"); |
| 2112 | + |
| 2113 | +if (!posM|| !posD|| !posY) |
| 2114 | +returnresult; |
| 2115 | + |
| 2116 | +if (posY<posM&&posM<posD) |
| 2117 | +result=DATEORDER_YMD; |
| 2118 | +elseif (posD<posM) |
| 2119 | +result=DATEORDER_DMY; |
| 2120 | +else |
| 2121 | +result=DATEORDER_MDY; |
| 2122 | + |
| 2123 | +returnresult; |
| 2124 | +} |
| 2125 | + |
2055 | 2126 | /*
|
2056 | 2127 | * check if given string is a valid locale specifier
|
2057 | 2128 | */
|
|