*/
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 */
}
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)
{
/*
* 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;
/*
* 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;
stdname = name;
name = getqzname(name, '>');
if (*name != '>')
- return -1;
+ return false;
stdlen = name - stdname;
name++;
}
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)
dstname = ++name;
name = getqzname(name, '>');
if (*name != '>')
- return -1;
+ return false;
dstlen = name - dstname;
name++;
}
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;
++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 */
/*
int j;
if (*name != '\0')
- return -1;
+ return false;
/*
* Initial values of theirstdoffset and theirdstoffset.
memcpy(cp, dstname, dstlen);
*(cp + dstlen) = '\0';
}
- return 0;
+ return true;
}
static void
*/
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");
}
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;