Skip to content

Commit 1f4e9da

Browse files
committed
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.
1 parent f5f15ea commit 1f4e9da

File tree

4 files changed

+26
-29
lines changed

4 files changed

+26
-29
lines changed

src/bin/initdb/findtimezone.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -99,15 +99,15 @@ pg_load_tz(const char *name)
9999
*/
100100
if (strcmp(name, "GMT") == 0)
101101
{
102-
if (tzparse(name, &tz.state, TRUE) != 0)
102+
if (!tzparse(name, &tz.state, true))
103103
{
104104
/* This really, really should not happen ... */
105105
return NULL;
106106
}
107107
}
108-
else if (tzload(name, NULL, &tz.state, TRUE) != 0)
108+
else if (tzload(name, NULL, &tz.state, true) != 0)
109109
{
110-
if (name[0] == ':' || tzparse(name, &tz.state, FALSE) != 0)
110+
if (name[0] == ':' || !tzparse(name, &tz.state, false))
111111
{
112112
return NULL; /* unknown timezone */
113113
}

src/timezone/localtime.c

Lines changed: 19 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -409,7 +409,7 @@ tzloadbody(char const * name, char *canonname, struct state * sp, bool doextend,
409409
struct state *ts = &lsp->u.st;
410410

411411
up->buf[nread - 1] = '\0';
412-
if (tzparse(&up->buf[1], ts, false) == 0
412+
if (tzparse(&up->buf[1], ts, false)
413413
&& ts->typecnt == 2)
414414
{
415415
/*
@@ -534,7 +534,7 @@ tzloadbody(char const * name, char *canonname, struct state * sp, bool doextend,
534534
* given name is stored there (the buffer must be > TZ_STRLEN_MAX bytes!).
535535
*/
536536
int
537-
tzload(const char *name, char *canonname, struct state * sp, int doextend)
537+
tzload(const char *name, char *canonname, struct state * sp, bool doextend)
538538
{
539539
union local_storage ls;
540540

@@ -864,13 +864,10 @@ transtime(int year, const struct rule * rulep,
864864
/*
865865
* Given a POSIX section 8-style TZ string, fill in the rule tables as
866866
* appropriate.
867-
*
868-
* Returns 0 on success, -1 on failure. (Note: tzcode has converted this
869-
* to a bool true-on-success convention, but we're holding the line in PG
870-
* for the moment, to avoid external API changes.)
867+
* Returns true on success, false on failure.
871868
*/
872-
int
873-
tzparse(const char *name, struct state * sp, int lastditch)
869+
bool
870+
tzparse(const char *name, struct state * sp, bool lastditch)
874871
{
875872
const char *stdname;
876873
const char *dstname = NULL;
@@ -908,7 +905,7 @@ tzparse(const char *name, struct state * sp, int lastditch)
908905
stdname = name;
909906
name = getqzname(name, '>');
910907
if (*name != '>')
911-
return -1;
908+
return false;
912909
stdlen = name - stdname;
913910
name++;
914911
}
@@ -918,13 +915,13 @@ tzparse(const char *name, struct state * sp, int lastditch)
918915
stdlen = name - stdname;
919916
}
920917
if (*name == '\0') /* we allow empty STD abbrev, unlike IANA */
921-
return -1;
918+
return false;
922919
name = getoffset(name, &stdoffset);
923920
if (name == NULL)
924-
return -1;
921+
return false;
925922
charcnt = stdlen + 1;
926923
if (sizeof sp->chars < charcnt)
927-
return -1;
924+
return false;
928925
load_ok = tzload(TZDEFRULES, NULL, sp, false) == 0;
929926
}
930927
if (!load_ok)
@@ -936,7 +933,7 @@ tzparse(const char *name, struct state * sp, int lastditch)
936933
dstname = ++name;
937934
name = getqzname(name, '>');
938935
if (*name != '>')
939-
return -1;
936+
return false;
940937
dstlen = name - dstname;
941938
name++;
942939
}
@@ -947,15 +944,15 @@ tzparse(const char *name, struct state * sp, int lastditch)
947944
dstlen = name - dstname; /* length of DST zone name */
948945
}
949946
if (!dstlen)
950-
return -1;
947+
return false;
951948
charcnt += dstlen + 1;
952949
if (sizeof sp->chars < charcnt)
953-
return -1;
950+
return false;
954951
if (*name != '\0' && *name != ',' && *name != ';')
955952
{
956953
name = getoffset(name, &dstoffset);
957954
if (name == NULL)
958-
return -1;
955+
return false;
959956
}
960957
else
961958
dstoffset = stdoffset - SECSPERHOUR;
@@ -972,13 +969,13 @@ tzparse(const char *name, struct state * sp, int lastditch)
972969

973970
++name;
974971
if ((name = getrule(name, &start)) == NULL)
975-
return -1;
972+
return false;
976973
if (*name++ != ',')
977-
return -1;
974+
return false;
978975
if ((name = getrule(name, &end)) == NULL)
979-
return -1;
976+
return false;
980977
if (*name != '\0')
981-
return -1;
978+
return false;
982979
sp->typecnt = 2; /* standard time and DST */
983980

984981
/*
@@ -1044,7 +1041,7 @@ tzparse(const char *name, struct state * sp, int lastditch)
10441041
int j;
10451042

10461043
if (*name != '\0')
1047-
return -1;
1044+
return false;
10481045

10491046
/*
10501047
* Initial values of theirstdoffset and theirdstoffset.
@@ -1148,7 +1145,7 @@ tzparse(const char *name, struct state * sp, int lastditch)
11481145
memcpy(cp, dstname, dstlen);
11491146
*(cp + dstlen) = '\0';
11501147
}
1151-
return 0;
1148+
return true;
11521149
}
11531150

11541151
static void

src/timezone/pgtz.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -256,7 +256,7 @@ pg_tzset(const char *name)
256256
*/
257257
if (strcmp(uppername, "GMT") == 0)
258258
{
259-
if (tzparse(uppername, &tzstate, true) != 0)
259+
if (!tzparse(uppername, &tzstate, true))
260260
{
261261
/* This really, really should not happen ... */
262262
elog(ERROR, "could not initialize GMT time zone");
@@ -266,7 +266,7 @@ pg_tzset(const char *name)
266266
}
267267
else if (tzload(uppername, canonname, &tzstate, true) != 0)
268268
{
269-
if (uppername[0] == ':' || tzparse(uppername, &tzstate, false) != 0)
269+
if (uppername[0] == ':' || !tzparse(uppername, &tzstate, false))
270270
{
271271
/* Unknown timezone. Fail our call instead of loading GMT! */
272272
return NULL;

src/timezone/pgtz.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ extern int pg_open_tzfile(const char *name, char *canonname);
6969

7070
/* in localtime.c */
7171
extern int tzload(const char *name, char *canonname, struct state * sp,
72-
int doextend);
73-
extern int tzparse(const char *name, struct state * sp, int lastditch);
72+
bool doextend);
73+
extern bool tzparse(const char *name, struct state * sp, bool lastditch);
7474

7575
#endif /* _PGTZ_H */

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