aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorTom Lane <tgl@sss.pgh.pa.us>2016-03-28 17:19:29 -0400
committerTom Lane <tgl@sss.pgh.pa.us>2016-03-28 17:19:29 -0400
commit1f4e9da624a0caf78bcb526f6b05f5993e26f2c7 (patch)
treedfb146d595c366297548e4fb9c00067fcbe81a2f /src
parentf5f15ea6aad1b75c1c133a914cf29f9831089a6e (diff)
downloadpostgresql-1f4e9da624a0caf78bcb526f6b05f5993e26f2c7.tar.gz
postgresql-1f4e9da624a0caf78bcb526f6b05f5993e26f2c7.zip
Sync tzload() and tzparse() APIs with IANA release tzcode2016c.
This brings us a bit closer to matching upstream, but since it affects files outside src/timezone/, we might choose not to back-patch it. Hence keep it separate from the main update patch.
Diffstat (limited to 'src')
-rw-r--r--src/bin/initdb/findtimezone.c6
-rw-r--r--src/timezone/localtime.c41
-rw-r--r--src/timezone/pgtz.c4
-rw-r--r--src/timezone/pgtz.h4
4 files changed, 26 insertions, 29 deletions
diff --git a/src/bin/initdb/findtimezone.c b/src/bin/initdb/findtimezone.c
index 95958734cab..5a443131eed 100644
--- a/src/bin/initdb/findtimezone.c
+++ b/src/bin/initdb/findtimezone.c
@@ -99,15 +99,15 @@ pg_load_tz(const char *name)
*/
if (strcmp(name, "GMT") == 0)
{
- if (tzparse(name, &tz.state, TRUE) != 0)
+ if (!tzparse(name, &tz.state, true))
{
/* This really, really should not happen ... */
return NULL;
}
}
- else if (tzload(name, NULL, &tz.state, TRUE) != 0)
+ else if (tzload(name, NULL, &tz.state, true) != 0)
{
- if (name[0] == ':' || tzparse(name, &tz.state, FALSE) != 0)
+ if (name[0] == ':' || !tzparse(name, &tz.state, false))
{
return NULL; /* unknown timezone */
}
diff --git a/src/timezone/localtime.c b/src/timezone/localtime.c
index 23e022695fa..985ad56da20 100644
--- a/src/timezone/localtime.c
+++ b/src/timezone/localtime.c
@@ -409,7 +409,7 @@ tzloadbody(char const * name, char *canonname, struct state * sp, bool doextend,
struct state *ts = &lsp->u.st;
up->buf[nread - 1] = '\0';
- if (tzparse(&up->buf[1], ts, false) == 0
+ if (tzparse(&up->buf[1], ts, false)
&& ts->typecnt == 2)
{
/*
@@ -534,7 +534,7 @@ tzloadbody(char const * name, char *canonname, struct state * sp, bool doextend,
* given name is stored there (the buffer must be > TZ_STRLEN_MAX bytes!).
*/
int
-tzload(const char *name, char *canonname, struct state * sp, int doextend)
+tzload(const char *name, char *canonname, struct state * sp, bool doextend)
{
union local_storage ls;
@@ -864,13 +864,10 @@ transtime(int year, const struct rule * rulep,
/*
* Given a POSIX section 8-style TZ string, fill in the rule tables as
* appropriate.
- *
- * Returns 0 on success, -1 on failure. (Note: tzcode has converted this
- * to a bool true-on-success convention, but we're holding the line in PG
- * for the moment, to avoid external API changes.)
+ * Returns true on success, false on failure.
*/
-int
-tzparse(const char *name, struct state * sp, int lastditch)
+bool
+tzparse(const char *name, struct state * sp, bool lastditch)
{
const char *stdname;
const char *dstname = NULL;
@@ -908,7 +905,7 @@ tzparse(const char *name, struct state * sp, int lastditch)
stdname = name;
name = getqzname(name, '>');
if (*name != '>')
- return -1;
+ return false;
stdlen = name - stdname;
name++;
}
@@ -918,13 +915,13 @@ tzparse(const char *name, struct state * sp, int lastditch)
stdlen = name - stdname;
}
if (*name == '\0') /* we allow empty STD abbrev, unlike IANA */
- return -1;
+ return false;
name = getoffset(name, &stdoffset);
if (name == NULL)
- return -1;
+ return false;
charcnt = stdlen + 1;
if (sizeof sp->chars < charcnt)
- return -1;
+ return false;
load_ok = tzload(TZDEFRULES, NULL, sp, false) == 0;
}
if (!load_ok)
@@ -936,7 +933,7 @@ tzparse(const char *name, struct state * sp, int lastditch)
dstname = ++name;
name = getqzname(name, '>');
if (*name != '>')
- return -1;
+ return false;
dstlen = name - dstname;
name++;
}
@@ -947,15 +944,15 @@ tzparse(const char *name, struct state * sp, int lastditch)
dstlen = name - dstname; /* length of DST zone name */
}
if (!dstlen)
- return -1;
+ return false;
charcnt += dstlen + 1;
if (sizeof sp->chars < charcnt)
- return -1;
+ return false;
if (*name != '\0' && *name != ',' && *name != ';')
{
name = getoffset(name, &dstoffset);
if (name == NULL)
- return -1;
+ return false;
}
else
dstoffset = stdoffset - SECSPERHOUR;
@@ -972,13 +969,13 @@ tzparse(const char *name, struct state * sp, int lastditch)
++name;
if ((name = getrule(name, &start)) == NULL)
- return -1;
+ return false;
if (*name++ != ',')
- return -1;
+ return false;
if ((name = getrule(name, &end)) == NULL)
- return -1;
+ return false;
if (*name != '\0')
- return -1;
+ return false;
sp->typecnt = 2; /* standard time and DST */
/*
@@ -1044,7 +1041,7 @@ tzparse(const char *name, struct state * sp, int lastditch)
int j;
if (*name != '\0')
- return -1;
+ return false;
/*
* Initial values of theirstdoffset and theirdstoffset.
@@ -1148,7 +1145,7 @@ tzparse(const char *name, struct state * sp, int lastditch)
memcpy(cp, dstname, dstlen);
*(cp + dstlen) = '\0';
}
- return 0;
+ return true;
}
static void
diff --git a/src/timezone/pgtz.c b/src/timezone/pgtz.c
index c28e6dbfad8..4fa3d0da89c 100644
--- a/src/timezone/pgtz.c
+++ b/src/timezone/pgtz.c
@@ -256,7 +256,7 @@ pg_tzset(const char *name)
*/
if (strcmp(uppername, "GMT") == 0)
{
- if (tzparse(uppername, &tzstate, true) != 0)
+ if (!tzparse(uppername, &tzstate, true))
{
/* This really, really should not happen ... */
elog(ERROR, "could not initialize GMT time zone");
@@ -266,7 +266,7 @@ pg_tzset(const char *name)
}
else if (tzload(uppername, canonname, &tzstate, true) != 0)
{
- if (uppername[0] == ':' || tzparse(uppername, &tzstate, false) != 0)
+ if (uppername[0] == ':' || !tzparse(uppername, &tzstate, false))
{
/* Unknown timezone. Fail our call instead of loading GMT! */
return NULL;
diff --git a/src/timezone/pgtz.h b/src/timezone/pgtz.h
index deee7464ed5..2adec198386 100644
--- a/src/timezone/pgtz.h
+++ b/src/timezone/pgtz.h
@@ -69,7 +69,7 @@ extern int pg_open_tzfile(const char *name, char *canonname);
/* in localtime.c */
extern int tzload(const char *name, char *canonname, struct state * sp,
- int doextend);
-extern int tzparse(const char *name, struct state * sp, int lastditch);
+ bool doextend);
+extern bool tzparse(const char *name, struct state * sp, bool lastditch);
#endif /* _PGTZ_H */