summaryrefslogtreecommitdiff
path: root/src/backend
diff options
context:
space:
mode:
Diffstat (limited to 'src/backend')
-rw-r--r--src/backend/Makefile8
-rw-r--r--src/backend/access/transam/xact.c6
-rw-r--r--src/backend/access/transam/xlog.c7
-rw-r--r--src/backend/bootstrap/bootparse.y4
-rw-r--r--src/backend/bootstrap/bootscanner.l5
-rw-r--r--src/backend/bootstrap/bootstrap.c9
-rw-r--r--src/backend/commands/variable.c257
-rw-r--r--src/backend/optimizer/geqo/geqo_main.c4
-rw-r--r--src/backend/postmaster/postmaster.c17
-rw-r--r--src/backend/tcop/postgres.c10
-rw-r--r--src/backend/utils/adt/date.c52
-rw-r--r--src/backend/utils/adt/datetime.c54
-rw-r--r--src/backend/utils/adt/formatting.c21
-rw-r--r--src/backend/utils/adt/misc.c3
-rw-r--r--src/backend/utils/adt/nabstime.c110
-rw-r--r--src/backend/utils/adt/timestamp.c102
-rw-r--r--src/backend/utils/error/elog.c13
-rw-r--r--src/backend/utils/misc/guc.c6
18 files changed, 202 insertions, 486 deletions
diff --git a/src/backend/Makefile b/src/backend/Makefile
index 920a3a244d7..2b78b9e7e87 100644
--- a/src/backend/Makefile
+++ b/src/backend/Makefile
@@ -4,7 +4,7 @@
#
# Copyright (c) 1994, Regents of the University of California
#
-# $PostgreSQL: pgsql/src/backend/Makefile,v 1.99 2004/04/30 16:08:01 momjian Exp $
+# $PostgreSQL: pgsql/src/backend/Makefile,v 1.100 2004/05/21 05:07:55 tgl Exp $
#
#-------------------------------------------------------------------------
@@ -14,11 +14,7 @@ include $(top_builddir)/src/Makefile.global
DIRS := access bootstrap catalog parser commands executor lib libpq \
main nodes optimizer port postmaster regex rewrite \
- storage tcop utils
-
-ifeq ($(USE_PGTZ), yes)
-DIRS+= $(top_builddir)/src/timezone
-endif
+ storage tcop utils $(top_builddir)/src/timezone
OBJS := $(DIRS:%=%/SUBSYS.o)
diff --git a/src/backend/access/transam/xact.c b/src/backend/access/transam/xact.c
index 4eefbb91abe..b29ccdf5f76 100644
--- a/src/backend/access/transam/xact.c
+++ b/src/backend/access/transam/xact.c
@@ -8,7 +8,7 @@
*
*
* IDENTIFICATION
- * $PostgreSQL: pgsql/src/backend/access/transam/xact.c,v 1.165 2004/04/05 03:11:39 momjian Exp $
+ * $PostgreSQL: pgsql/src/backend/access/transam/xact.c,v 1.166 2004/05/21 05:07:56 tgl Exp $
*
* NOTES
* Transaction aborts can now occur two ways:
@@ -1828,7 +1828,7 @@ xact_desc(char *buf, uint8 xl_info, char *rec)
if (info == XLOG_XACT_COMMIT)
{
xl_xact_commit *xlrec = (xl_xact_commit *) rec;
- struct tm *tm = localtime(&xlrec->xtime);
+ struct pg_tm *tm = pg_localtime(&xlrec->xtime);
sprintf(buf + strlen(buf), "commit: %04u-%02u-%02u %02u:%02u:%02u",
tm->tm_year + 1900, tm->tm_mon + 1, tm->tm_mday,
@@ -1838,7 +1838,7 @@ xact_desc(char *buf, uint8 xl_info, char *rec)
else if (info == XLOG_XACT_ABORT)
{
xl_xact_abort *xlrec = (xl_xact_abort *) rec;
- struct tm *tm = localtime(&xlrec->xtime);
+ struct pg_tm *tm = pg_localtime(&xlrec->xtime);
sprintf(buf + strlen(buf), "abort: %04u-%02u-%02u %02u:%02u:%02u",
tm->tm_year + 1900, tm->tm_mon + 1, tm->tm_mday,
diff --git a/src/backend/access/transam/xlog.c b/src/backend/access/transam/xlog.c
index b6199706f67..2d92c0c0c02 100644
--- a/src/backend/access/transam/xlog.c
+++ b/src/backend/access/transam/xlog.c
@@ -7,7 +7,7 @@
* Portions Copyright (c) 1996-2003, PostgreSQL Global Development Group
* Portions Copyright (c) 1994, Regents of the University of California
*
- * $PostgreSQL: pgsql/src/backend/access/transam/xlog.c,v 1.140 2004/05/07 00:24:57 tgl Exp $
+ * $PostgreSQL: pgsql/src/backend/access/transam/xlog.c,v 1.141 2004/05/21 05:07:56 tgl Exp $
*
*-------------------------------------------------------------------------
*/
@@ -18,7 +18,6 @@
#include <signal.h>
#include <unistd.h>
#include <sys/stat.h>
-#include <sys/time.h>
#include "access/clog.h"
#include "access/transam.h"
@@ -2764,9 +2763,9 @@ str_time(time_t tnow)
{
static char buf[128];
- strftime(buf, sizeof(buf),
+ pg_strftime(buf, sizeof(buf),
"%Y-%m-%d %H:%M:%S %Z",
- localtime(&tnow));
+ pg_localtime(&tnow));
return buf;
}
diff --git a/src/backend/bootstrap/bootparse.y b/src/backend/bootstrap/bootparse.y
index 679ef5577fa..debf24e892d 100644
--- a/src/backend/bootstrap/bootparse.y
+++ b/src/backend/bootstrap/bootparse.y
@@ -9,14 +9,13 @@
*
*
* IDENTIFICATION
- * $PostgreSQL: pgsql/src/backend/bootstrap/bootparse.y,v 1.66 2004/05/05 04:48:45 tgl Exp $
+ * $PostgreSQL: pgsql/src/backend/bootstrap/bootparse.y,v 1.67 2004/05/21 05:07:56 tgl Exp $
*
*-------------------------------------------------------------------------
*/
#include "postgres.h"
-#include <time.h>
#include <unistd.h>
#include "access/attnum.h"
@@ -39,6 +38,7 @@
#include "nodes/parsenodes.h"
#include "nodes/pg_list.h"
#include "nodes/primnodes.h"
+#include "pgtime.h"
#include "rewrite/prs2lock.h"
#include "storage/block.h"
#include "storage/fd.h"
diff --git a/src/backend/bootstrap/bootscanner.l b/src/backend/bootstrap/bootscanner.l
index d8f683596d9..3f8777ea664 100644
--- a/src/backend/bootstrap/bootscanner.l
+++ b/src/backend/bootstrap/bootscanner.l
@@ -9,14 +9,12 @@
*
*
* IDENTIFICATION
- * $PostgreSQL: pgsql/src/backend/bootstrap/bootscanner.l,v 1.33 2004/02/24 22:06:32 tgl Exp $
+ * $PostgreSQL: pgsql/src/backend/bootstrap/bootscanner.l,v 1.34 2004/05/21 05:07:56 tgl Exp $
*
*-------------------------------------------------------------------------
*/
#include "postgres.h"
-#include <time.h>
-
#include "access/attnum.h"
#include "access/htup.h"
#include "access/itup.h"
@@ -31,6 +29,7 @@
#include "nodes/pg_list.h"
#include "nodes/primnodes.h"
#include "parser/scansup.h"
+#include "pgtime.h"
#include "rewrite/prs2lock.h"
#include "storage/block.h"
#include "storage/fd.h"
diff --git a/src/backend/bootstrap/bootstrap.c b/src/backend/bootstrap/bootstrap.c
index c7fcb400873..3aca65e845c 100644
--- a/src/backend/bootstrap/bootstrap.c
+++ b/src/backend/bootstrap/bootstrap.c
@@ -8,14 +8,13 @@
* Portions Copyright (c) 1994, Regents of the University of California
*
* IDENTIFICATION
- * $PostgreSQL: pgsql/src/backend/bootstrap/bootstrap.c,v 1.178 2004/04/01 21:28:43 tgl Exp $
+ * $PostgreSQL: pgsql/src/backend/bootstrap/bootstrap.c,v 1.179 2004/05/21 05:07:56 tgl Exp $
*
*-------------------------------------------------------------------------
*/
#include "postgres.h"
#include <unistd.h>
-#include <time.h>
#include <signal.h>
#include <setjmp.h>
#ifdef HAVE_GETOPT_H
@@ -34,6 +33,7 @@
#include "executor/executor.h"
#include "libpq/pqsignal.h"
#include "miscadmin.h"
+#include "pgtime.h"
#include "storage/freespace.h"
#include "storage/ipc.h"
#include "storage/pg_shmem.h"
@@ -392,8 +392,8 @@ BootstrapMain(int argc, char *argv[])
if (IsUnderPostmaster)
{
#ifdef EXEC_BACKEND
- read_nondefault_variables();
read_backend_variables(backendID,NULL);
+ read_nondefault_variables();
SSDataBaseInit(xlogop);
#endif
@@ -401,6 +401,9 @@ BootstrapMain(int argc, char *argv[])
else
ProcessConfigFile(PGC_POSTMASTER);
+ /* If timezone is not set, determine what the OS uses */
+ pg_timezone_initialize();
+
if (IsUnderPostmaster)
{
/*
diff --git a/src/backend/commands/variable.c b/src/backend/commands/variable.c
index f83ce51baca..45ed717951e 100644
--- a/src/backend/commands/variable.c
+++ b/src/backend/commands/variable.c
@@ -9,7 +9,7 @@
*
*
* IDENTIFICATION
- * $PostgreSQL: pgsql/src/backend/commands/variable.c,v 1.94 2004/05/07 00:24:57 tgl Exp $
+ * $PostgreSQL: pgsql/src/backend/commands/variable.c,v 1.95 2004/05/21 05:07:57 tgl Exp $
*
*-------------------------------------------------------------------------
*/
@@ -17,13 +17,13 @@
#include "postgres.h"
#include <ctype.h>
-#include <time.h>
#include "access/xact.h"
#include "catalog/pg_shadow.h"
#include "commands/variable.h"
#include "miscadmin.h"
#include "parser/scansup.h"
+#include "pgtime.h"
#include "utils/builtins.h"
#include "utils/guc.h"
#include "utils/syscache.h"
@@ -31,17 +31,6 @@
#include "mb/pg_wchar.h"
/*
- * Some systems have tzname[] but don't declare it in <time.h>. Use this
- * to duplicate the test in AC_STRUCT_TIMEZONE.
- */
-#ifdef HAVE_TZNAME
-#ifndef tzname /* For SGI. */
-extern char *tzname[];
-#endif
-#endif
-
-
-/*
* DATESTYLE
*/
@@ -238,149 +227,6 @@ assign_datestyle(const char *value, bool doit, GucSource source)
*/
/*
- * Storage for TZ env var is allocated with an arbitrary size of 64 bytes.
- */
-#define TZBUF_LEN 64
-
-static char tzbuf[TZBUF_LEN];
-
-/*
- * First time through, we remember the original environment TZ value, if any.
- */
-static bool have_saved_tz = false;
-static char orig_tzbuf[TZBUF_LEN];
-
-/*
- * Convenience subroutine for assigning the value of TZ
- */
-static void
-set_tz(const char *tz)
-{
- strcpy(tzbuf, "TZ=");
- strncpy(tzbuf + 3, tz, sizeof(tzbuf) - 4);
- if (putenv(tzbuf) != 0) /* shouldn't happen? */
- elog(LOG, "could not set TZ environment variable");
- tzset();
-}
-
-/*
- * Remove any value of TZ we have established
- *
- * Note: this leaves us with *no* value of TZ in the environment, and
- * is therefore only appropriate for reverting to that state, not for
- * reverting to a state where TZ was set to something else.
- */
-static void
-clear_tz(void)
-{
- /*
- * unsetenv() works fine, but is BSD, not POSIX, and is not available
- * under Solaris, among others. Apparently putenv() called as below
- * clears the process-specific environment variables. Other
- * reasonable arguments to putenv() (e.g. "TZ=", "TZ", "") result in a
- * core dump (under Linux anyway). - thomas 1998-01-26
- */
- if (tzbuf[0] == 'T')
- {
- strcpy(tzbuf, "=");
- if (putenv(tzbuf) != 0)
- elog(LOG, "could not clear TZ environment variable");
- tzset();
- }
-}
-
-/*
- * Check whether tzset() succeeded
- *
- * Unfortunately, tzset doesn't offer any well-defined way to detect that the
- * value of TZ was bad. Often it will just select UTC (GMT) as the effective
- * timezone. We use the following heuristics:
- *
- * If tzname[1] is a nonempty string, *or* the global timezone variable is
- * not zero, then tzset must have recognized the TZ value as something
- * different from UTC. Return true.
- *
- * Otherwise, check to see if the TZ name is a known spelling of "UTC"
- * (ie, appears in our internal tables as a timezone equivalent to UTC).
- * If so, accept it.
- *
- * This will reject nonstandard spellings of UTC unless tzset() chose to
- * set tzname[1] as well as tzname[0]. The glibc version of tzset() will
- * do so, but on other systems we may be tightening the spec a little.
- *
- * Another problem is that on some platforms (eg HPUX), if tzset thinks the
- * input is bogus then it will adopt the system default timezone, which we
- * really can't tell is not the intended translation of the input.
- *
- * Still, it beats failing to detect bad TZ names at all, and a silent
- * failure mode of adopting the system-wide default is much better than
- * a silent failure mode of adopting UTC.
- *
- * NB: this must NOT ereport(ERROR). The caller must get control back so that
- * it can restore the old value of TZ if we don't like the new one.
- */
-static bool
-tzset_succeeded(const char *tz)
-{
- char *tztmp;
- int tzval;
-
- /*
- * Check first set of heuristics to say that tzset definitely worked.
- */
-#ifdef HAVE_TZNAME
- if (tzname[1] && tzname[1][0] != '\0')
- return true;
-#endif
- if (TIMEZONE_GLOBAL != 0)
- return true;
-
- /*
- * Check for known spellings of "UTC". Note we must downcase the
- * input before passing it to DecodePosixTimezone().
- */
- tztmp = downcase_truncate_identifier(tz, strlen(tz), false);
- if (DecodePosixTimezone(tztmp, &tzval) == 0)
- if (tzval == 0)
- return true;
-
- return false;
-}
-
-/*
- * Check whether timezone is acceptable.
- *
- * What we are doing here is checking for leap-second-aware timekeeping.
- * We need to reject such TZ settings because they'll wreak havoc with our
- * date/time arithmetic.
- *
- * NB: this must NOT ereport(ERROR). The caller must get control back so that
- * it can restore the old value of TZ if we don't like the new one.
- */
-static bool
-tz_acceptable(void)
-{
- struct tm tt;
- time_t time2000;
-
- /*
- * To detect leap-second timekeeping, compute the time_t value for
- * local midnight, 2000-01-01. Insist that this be a multiple of 60;
- * any partial-minute offset has to be due to leap seconds.
- */
- MemSet(&tt, 0, sizeof(tt));
- tt.tm_year = 100;
- tt.tm_mon = 0;
- tt.tm_mday = 1;
- tt.tm_isdst = -1;
- time2000 = mktime(&tt);
- if ((time2000 % 60) != 0)
- return false;
-
- return true;
-}
-
-/*
* assign_timezone: GUC assign_hook for timezone
*/
const char *
@@ -391,21 +237,6 @@ assign_timezone(const char *value, bool doit, GucSource source)
double hours;
/*
- * On first call, see if there is a TZ in the original environment.
- * Save that value permanently.
- */
- if (!have_saved_tz)
- {
- char *orig_tz = getenv("TZ");
-
- if (orig_tz)
- StrNCpy(orig_tzbuf, orig_tz, sizeof(orig_tzbuf));
- else
- orig_tzbuf[0] = '\0';
- have_saved_tz = true;
- }
-
- /*
* Check for INTERVAL 'foo'
*/
if (pg_strncasecmp(value, "interval", 8) == 0)
@@ -476,36 +307,21 @@ assign_timezone(const char *value, bool doit, GucSource source)
{
/*
* UNKNOWN is the value shown as the "default" for TimeZone in
- * guc.c. We interpret it as meaning the original TZ
- * inherited from the environment. Note that if there is an
- * original TZ setting, we will return that rather than
+ * guc.c. We interpret it as being a complete no-op; we don't
+ * change the timezone setting. Note that if there is a known
+ * timezone setting, we will return that name rather than
* UNKNOWN as the canonical spelling.
+ *
+ * During GUC initialization, since the timezone library isn't
+ * set up yet, pg_get_current_timezone will return NULL and we
+ * will leave the setting as UNKNOWN. If this isn't overridden
+ * from the config file then pg_timezone_initialize() will
+ * eventually select a default value from the environment.
*/
- if (doit)
- {
- bool ok;
-
- /* Revert to original setting of TZ, whatever it was */
- if (orig_tzbuf[0])
- {
- set_tz(orig_tzbuf);
- ok = tzset_succeeded(orig_tzbuf) && tz_acceptable();
- }
- else
- {
- clear_tz();
- ok = tz_acceptable();
- }
+ const char *curzone = pg_get_current_timezone();
- if (ok)
- HasCTZSet = false;
- else
- {
- /* Bogus, so force UTC (equivalent to INTERVAL 0) */
- CTimeZone = 0;
- HasCTZSet = true;
- }
- }
+ if (curzone)
+ value = curzone;
}
else
{
@@ -514,22 +330,22 @@ assign_timezone(const char *value, bool doit, GucSource source)
*
* We have to actually apply the change before we can have any
* hope of checking it. So, save the old value in case we
- * have to back out. Note that it's possible the old setting
- * is in tzbuf, so we'd better copy it.
+ * have to back out. We have to copy since pg_get_current_timezone
+ * returns a pointer to its static state.
*/
- char save_tzbuf[TZBUF_LEN];
+ const char *cur_tz;
char *save_tz;
bool known,
acceptable;
- save_tz = getenv("TZ");
- if (save_tz)
- StrNCpy(save_tzbuf, save_tz, sizeof(save_tzbuf));
-
- set_tz(value);
+ cur_tz = pg_get_current_timezone();
+ if (cur_tz)
+ save_tz = pstrdup(cur_tz);
+ else
+ save_tz = NULL;
- known = tzset_succeeded(value);
- acceptable = tz_acceptable();
+ known = pg_tzset(value);
+ acceptable = known ? tz_acceptable() : false;
if (doit && known && acceptable)
{
@@ -544,9 +360,9 @@ assign_timezone(const char *value, bool doit, GucSource source)
* a fixed offset, we still are.
*/
if (save_tz)
- set_tz(save_tzbuf);
- else
- clear_tz();
+ pg_tzset(save_tz);
+ else /* TZ library not initialized yet */
+ select_default_timezone();
/* Complain if it was bad */
if (!known)
{
@@ -578,17 +394,16 @@ assign_timezone(const char *value, bool doit, GucSource source)
/*
* Prepare the canonical string to return. GUC wants it malloc'd.
*/
- result = (char *) malloc(sizeof(tzbuf));
- if (!result)
- return NULL;
-
if (HasCTZSet)
- snprintf(result, sizeof(tzbuf), "%.5f",
+ {
+ result = (char *) malloc(64);
+ if (!result)
+ return NULL;
+ snprintf(result, 64, "%.5f",
(double) (-CTimeZone) / 3600.0);
- else if (tzbuf[0] == 'T')
- strcpy(result, tzbuf + 3);
+ }
else
- strcpy(result, "UNKNOWN");
+ result = strdup(value);
return result;
}
@@ -599,7 +414,7 @@ assign_timezone(const char *value, bool doit, GucSource source)
const char *
show_timezone(void)
{
- char *tzn;
+ const char *tzn;
if (HasCTZSet)
{
@@ -612,7 +427,7 @@ show_timezone(void)
IntervalPGetDatum(&interval)));
}
else
- tzn = getenv("TZ");
+ tzn = pg_get_current_timezone();
if (tzn != NULL)
return tzn;
diff --git a/src/backend/optimizer/geqo/geqo_main.c b/src/backend/optimizer/geqo/geqo_main.c
index caba3b593f8..902fcbcd269 100644
--- a/src/backend/optimizer/geqo/geqo_main.c
+++ b/src/backend/optimizer/geqo/geqo_main.c
@@ -7,7 +7,7 @@
* Portions Copyright (c) 1996-2003, PostgreSQL Global Development Group
* Portions Copyright (c) 1994, Regents of the University of California
*
- * $PostgreSQL: pgsql/src/backend/optimizer/geqo/geqo_main.c,v 1.43 2004/01/23 23:54:21 tgl Exp $
+ * $PostgreSQL: pgsql/src/backend/optimizer/geqo/geqo_main.c,v 1.44 2004/05/21 05:07:57 tgl Exp $
*
*-------------------------------------------------------------------------
*/
@@ -24,7 +24,6 @@
#include "postgres.h"
-#include <time.h>
#include <math.h>
#include "optimizer/geqo.h"
@@ -32,6 +31,7 @@
#include "optimizer/geqo_mutation.h"
#include "optimizer/geqo_pool.h"
#include "optimizer/geqo_selection.h"
+#include "pgtime.h"
/*
diff --git a/src/backend/postmaster/postmaster.c b/src/backend/postmaster/postmaster.c
index 2abb4abb957..c141ca67875 100644
--- a/src/backend/postmaster/postmaster.c
+++ b/src/backend/postmaster/postmaster.c
@@ -37,7 +37,7 @@
*
*
* IDENTIFICATION
- * $PostgreSQL: pgsql/src/backend/postmaster/postmaster.c,v 1.392 2004/05/19 19:11:25 momjian Exp $
+ * $PostgreSQL: pgsql/src/backend/postmaster/postmaster.c,v 1.393 2004/05/21 05:07:57 tgl Exp $
*
* NOTES
*
@@ -66,11 +66,9 @@
#include <sys/wait.h>
#include <ctype.h>
#include <sys/stat.h>
-#include <sys/time.h>
#include <sys/socket.h>
#include <errno.h>
#include <fcntl.h>
-#include <time.h>
#include <sys/param.h>
#include <netinet/in.h>
#include <arpa/inet.h>
@@ -99,6 +97,7 @@
#include "libpq/pqsignal.h"
#include "miscadmin.h"
#include "nodes/nodes.h"
+#include "pgtime.h"
#include "storage/fd.h"
#include "storage/ipc.h"
#include "storage/pg_shmem.h"
@@ -636,6 +635,10 @@ PostmasterMain(int argc, char *argv[])
SetDataDir(potential_DataDir);
ProcessConfigFile(PGC_POSTMASTER);
+
+ /* If timezone is not set, determine what the OS uses */
+ pg_timezone_initialize();
+
#ifdef EXEC_BACKEND
write_nondefault_variables(PGC_POSTMASTER);
#endif
@@ -906,7 +909,7 @@ PostmasterMain(int argc, char *argv[])
{
time_t now = time(NULL);
- (void) localtime(&now);
+ (void) pg_localtime(&now);
}
/*
@@ -2704,8 +2707,8 @@ SubPostmasterMain(int argc, char* argv[])
DataDir = strdup(argv[argc++]);
/* Read in file-based context */
- read_nondefault_variables();
read_backend_variables(backendID,&port);
+ read_nondefault_variables();
/* Remaining initialization */
pgstat_init_forkexec_backend();
@@ -3356,6 +3359,8 @@ write_backend_variables(Port *port)
write_var(debug_flag,fp);
write_var(PostmasterPid,fp);
+ fwrite((void *)my_exec_path, MAXPGPATH, 1, fp);
+
/* Release file */
if (FreeFile(fp))
{
@@ -3418,6 +3423,8 @@ read_backend_variables(unsigned long id, Port *port)
read_var(debug_flag,fp);
read_var(PostmasterPid,fp);
+ fread((void *)my_exec_path, MAXPGPATH, 1, fp);
+
/* Release file */
FreeFile(fp);
if (unlink(filename) != 0)
diff --git a/src/backend/tcop/postgres.c b/src/backend/tcop/postgres.c
index 1c3e0c28475..d097612ba30 100644
--- a/src/backend/tcop/postgres.c
+++ b/src/backend/tcop/postgres.c
@@ -8,7 +8,7 @@
*
*
* IDENTIFICATION
- * $PostgreSQL: pgsql/src/backend/tcop/postgres.c,v 1.412 2004/05/19 21:17:33 momjian Exp $
+ * $PostgreSQL: pgsql/src/backend/tcop/postgres.c,v 1.413 2004/05/21 05:07:58 tgl Exp $
*
* NOTES
* this is the "main" module of the postgres backend and
@@ -21,8 +21,6 @@
#include <unistd.h>
#include <signal.h>
-#include <time.h>
-#include <sys/time.h>
#include <fcntl.h>
#include <sys/socket.h>
#include <errno.h>
@@ -48,6 +46,7 @@
#include "optimizer/planner.h"
#include "parser/analyze.h"
#include "parser/parser.h"
+#include "pgtime.h"
#include "rewrite/rewriteHandler.h"
#include "storage/freespace.h"
#include "storage/ipc.h"
@@ -2145,7 +2144,7 @@ PostgresMain(int argc, char *argv[], const char *username)
char stack_base;
StringInfoData input_message;
volatile bool send_rfq = true;
-
+
/*
* Catch standard options before doing much else. This even works on
* systems without getopt_long.
@@ -2566,6 +2565,9 @@ PostgresMain(int argc, char *argv[], const char *username)
} else
ProcessConfigFile(PGC_POSTMASTER);
+ /* If timezone is not set, determine what the OS uses */
+ pg_timezone_initialize();
+
/*
* Set up signal handlers and masks.
*
diff --git a/src/backend/utils/adt/date.c b/src/backend/utils/adt/date.c
index 555ba5455ad..ab6e41d2e40 100644
--- a/src/backend/utils/adt/date.c
+++ b/src/backend/utils/adt/date.c
@@ -8,7 +8,7 @@
*
*
* IDENTIFICATION
- * $PostgreSQL: pgsql/src/backend/utils/adt/date.c,v 1.96 2004/05/07 00:24:58 tgl Exp $
+ * $PostgreSQL: pgsql/src/backend/utils/adt/date.c,v 1.97 2004/05/21 05:08:01 tgl Exp $
*
*-------------------------------------------------------------------------
*/
@@ -17,13 +17,13 @@
#include <ctype.h>
#include <limits.h>
-#include <time.h>
#include <float.h>
#include "access/hash.h"
#include "libpq/pqformat.h"
#include "miscadmin.h"
#include "parser/scansup.h"
+#include "pgtime.h"
#include "utils/builtins.h"
#include "utils/date.h"
#include "utils/nabstime.h"
@@ -38,10 +38,10 @@
#endif
-static int time2tm(TimeADT time, struct tm * tm, fsec_t *fsec);
-static int timetz2tm(TimeTzADT *time, struct tm * tm, fsec_t *fsec, int *tzp);
-static int tm2time(struct tm * tm, fsec_t fsec, TimeADT *result);
-static int tm2timetz(struct tm * tm, fsec_t fsec, int tz, TimeTzADT *result);
+static int time2tm(TimeADT time, struct pg_tm * tm, fsec_t *fsec);
+static int timetz2tm(TimeTzADT *time, struct pg_tm * tm, fsec_t *fsec, int *tzp);
+static int tm2time(struct pg_tm * tm, fsec_t fsec, TimeADT *result);
+static int tm2timetz(struct pg_tm * tm, fsec_t fsec, int tz, TimeTzADT *result);
static void AdjustTimeForTypmod(TimeADT *time, int32 typmod);
/*****************************************************************************
@@ -58,7 +58,7 @@ date_in(PG_FUNCTION_ARGS)
char *str = PG_GETARG_CSTRING(0);
DateADT date;
fsec_t fsec;
- struct tm tt,
+ struct pg_tm tt,
*tm = &tt;
int tzp;
int dtype;
@@ -112,7 +112,7 @@ date_out(PG_FUNCTION_ARGS)
{
DateADT date = PG_GETARG_DATEADT(0);
char *result;
- struct tm tt,
+ struct pg_tm tt,
*tm = &tt;
char buf[MAXDATELEN + 1];
@@ -293,7 +293,7 @@ static TimestampTz
date2timestamptz(DateADT dateVal)
{
TimestampTz result;
- struct tm tt,
+ struct pg_tm tt,
*tm = &tt;
j2date(dateVal + POSTGRES_EPOCH_JDATE,
@@ -733,7 +733,7 @@ timestamp_date(PG_FUNCTION_ARGS)
{
Timestamp timestamp = PG_GETARG_TIMESTAMP(0);
DateADT result;
- struct tm tt,
+ struct pg_tm tt,
*tm = &tt;
fsec_t fsec;
@@ -774,7 +774,7 @@ timestamptz_date(PG_FUNCTION_ARGS)
{
TimestampTz timestamp = PG_GETARG_TIMESTAMP(0);
DateADT result;
- struct tm tt,
+ struct pg_tm tt,
*tm = &tt;
fsec_t fsec;
int tz;
@@ -802,7 +802,7 @@ abstime_date(PG_FUNCTION_ARGS)
{
AbsoluteTime abstime = PG_GETARG_ABSOLUTETIME(0);
DateADT result;
- struct tm tt,
+ struct pg_tm tt,
*tm = &tt;
int tz;
@@ -903,7 +903,7 @@ time_in(PG_FUNCTION_ARGS)
int32 typmod = PG_GETARG_INT32(2);
TimeADT result;
fsec_t fsec;
- struct tm tt,
+ struct pg_tm tt,
*tm = &tt;
int tz;
int nf;
@@ -932,7 +932,7 @@ time_in(PG_FUNCTION_ARGS)
* Convert a tm structure to a time data type.
*/
static int
-tm2time(struct tm * tm, fsec_t fsec, TimeADT *result)
+tm2time(struct pg_tm * tm, fsec_t fsec, TimeADT *result)
{
#ifdef HAVE_INT64_TIMESTAMP
*result = ((((((tm->tm_hour * 60) + tm->tm_min) * 60) + tm->tm_sec)
@@ -949,7 +949,7 @@ tm2time(struct tm * tm, fsec_t fsec, TimeADT *result)
* local time zone. If out of this range, leave as GMT. - tgl 97/05/27
*/
static int
-time2tm(TimeADT time, struct tm * tm, fsec_t *fsec)
+time2tm(TimeADT time, struct pg_tm * tm, fsec_t *fsec)
{
#ifdef HAVE_INT64_TIMESTAMP
tm->tm_hour = (time / INT64CONST(3600000000));
@@ -977,7 +977,7 @@ time_out(PG_FUNCTION_ARGS)
{
TimeADT time = PG_GETARG_TIMEADT(0);
char *result;
- struct tm tt,
+ struct pg_tm tt,
*tm = &tt;
fsec_t fsec;
char buf[MAXDATELEN + 1];
@@ -1338,7 +1338,7 @@ timestamp_time(PG_FUNCTION_ARGS)
{
Timestamp timestamp = PG_GETARG_TIMESTAMP(0);
TimeADT result;
- struct tm tt,
+ struct pg_tm tt,
*tm = &tt;
fsec_t fsec;
@@ -1373,7 +1373,7 @@ timestamptz_time(PG_FUNCTION_ARGS)
{
TimestampTz timestamp = PG_GETARG_TIMESTAMP(0);
TimeADT result;
- struct tm tt,
+ struct pg_tm tt,
*tm = &tt;
int tz;
fsec_t fsec;
@@ -1641,7 +1641,7 @@ time_part(PG_FUNCTION_ARGS)
if (type == UNITS)
{
fsec_t fsec;
- struct tm tt,
+ struct pg_tm tt,
*tm = &tt;
time2tm(time, tm, &fsec);
@@ -1731,7 +1731,7 @@ time_part(PG_FUNCTION_ARGS)
* Convert a tm structure to a time data type.
*/
static int
-tm2timetz(struct tm * tm, fsec_t fsec, int tz, TimeTzADT *result)
+tm2timetz(struct pg_tm * tm, fsec_t fsec, int tz, TimeTzADT *result)
{
#ifdef HAVE_INT64_TIMESTAMP
result->time = ((((((tm->tm_hour * 60) + tm->tm_min) * 60) + tm->tm_sec)
@@ -1755,7 +1755,7 @@ timetz_in(PG_FUNCTION_ARGS)
int32 typmod = PG_GETARG_INT32(2);
TimeTzADT *result;
fsec_t fsec;
- struct tm tt,
+ struct pg_tm tt,
*tm = &tt;
int tz;
int nf;
@@ -1786,7 +1786,7 @@ timetz_out(PG_FUNCTION_ARGS)
{
TimeTzADT *time = PG_GETARG_TIMETZADT_P(0);
char *result;
- struct tm tt,
+ struct pg_tm tt,
*tm = &tt;
fsec_t fsec;
int tz;
@@ -1844,7 +1844,7 @@ timetz_send(PG_FUNCTION_ARGS)
* Convert TIME WITH TIME ZONE data type to POSIX time structure.
*/
static int
-timetz2tm(TimeTzADT *time, struct tm * tm, fsec_t *fsec, int *tzp)
+timetz2tm(TimeTzADT *time, struct pg_tm * tm, fsec_t *fsec, int *tzp)
{
#ifdef HAVE_INT64_TIMESTAMP
int64 trem = time->time;
@@ -2237,7 +2237,7 @@ time_timetz(PG_FUNCTION_ARGS)
{
TimeADT time = PG_GETARG_TIMEADT(0);
TimeTzADT *result;
- struct tm tt,
+ struct pg_tm tt,
*tm = &tt;
fsec_t fsec;
int tz;
@@ -2263,7 +2263,7 @@ timestamptz_timetz(PG_FUNCTION_ARGS)
{
TimestampTz timestamp = PG_GETARG_TIMESTAMP(0);
TimeTzADT *result;
- struct tm tt,
+ struct pg_tm tt,
*tm = &tt;
int tz;
fsec_t fsec;
@@ -2394,7 +2394,7 @@ timetz_part(PG_FUNCTION_ARGS)
double dummy;
int tz;
fsec_t fsec;
- struct tm tt,
+ struct pg_tm tt,
*tm = &tt;
timetz2tm(time, tm, &fsec, &tz);
diff --git a/src/backend/utils/adt/datetime.c b/src/backend/utils/adt/datetime.c
index 040e1691daf..8402d8cccb1 100644
--- a/src/backend/utils/adt/datetime.c
+++ b/src/backend/utils/adt/datetime.c
@@ -8,7 +8,7 @@
*
*
* IDENTIFICATION
- * $PostgreSQL: pgsql/src/backend/utils/adt/datetime.c,v 1.127 2004/05/07 00:24:58 tgl Exp $
+ * $PostgreSQL: pgsql/src/backend/utils/adt/datetime.c,v 1.128 2004/05/21 05:08:01 tgl Exp $
*
*-------------------------------------------------------------------------
*/
@@ -27,15 +27,16 @@
static int DecodeNumber(int flen, char *field, bool haveTextMonth,
int fmask, int *tmask,
- struct tm * tm, fsec_t *fsec, int *is2digits);
+ struct pg_tm * tm, fsec_t *fsec, int *is2digits);
static int DecodeNumberField(int len, char *str,
int fmask, int *tmask,
- struct tm * tm, fsec_t *fsec, int *is2digits);
+ struct pg_tm * tm, fsec_t *fsec, int *is2digits);
static int DecodeTime(char *str, int fmask, int *tmask,
- struct tm * tm, fsec_t *fsec);
+ struct pg_tm * tm, fsec_t *fsec);
static int DecodeTimezone(char *str, int *tzp);
+static int DecodePosixTimezone(char *str, int *tzp);
static datetkn *datebsearch(char *key, datetkn *base, unsigned int nel);
-static int DecodeDate(char *str, int fmask, int *tmask, struct tm * tm);
+static int DecodeDate(char *str, int fmask, int *tmask, struct pg_tm * tm);
static void TrimTrailingZeros(char *str);
@@ -913,7 +914,7 @@ ParseDateTime(const char *timestr, char *lowstr,
*/
int
DecodeDateTime(char **field, int *ftype, int nf,
- int *dtype, struct tm * tm, fsec_t *fsec, int *tzp)
+ int *dtype, struct pg_tm * tm, fsec_t *fsec, int *tzp)
{
int fmask = 0,
tmask,
@@ -1566,9 +1567,9 @@ DecodeDateTime(char **field, int *ftype, int nf,
/* DetermineLocalTimeZone()
*
- * Given a struct tm in which tm_year, tm_mon, tm_mday, tm_hour, tm_min, and
+ * Given a struct pg_tm in which tm_year, tm_mon, tm_mday, tm_hour, tm_min, and
* tm_sec fields are set, attempt to determine the applicable local zone
- * (ie, regular or daylight-savings time) at that time. Set the struct tm's
+ * (ie, regular or daylight-savings time) at that time. Set the struct pg_tm's
* tm_isdst field accordingly, and return the actual timezone offset.
*
* Note: this subroutine exists because mktime() has such a spectacular
@@ -1577,7 +1578,7 @@ DecodeDateTime(char **field, int *ftype, int nf,
* mktime() anywhere else.
*/
int
-DetermineLocalTimeZone(struct tm * tm)
+DetermineLocalTimeZone(struct pg_tm * tm)
{
int tz;
@@ -1600,7 +1601,7 @@ DetermineLocalTimeZone(struct tm * tm)
delta1,
delta2;
time_t mytime;
- struct tm *tx;
+ struct pg_tm *tx;
day = date2j(tm->tm_year, tm->tm_mon, tm->tm_mday) - UNIX_EPOCH_JDATE;
mysec = tm->tm_sec + (tm->tm_min + (day * 24 + tm->tm_hour) * 60) * 60;
@@ -1610,7 +1611,7 @@ DetermineLocalTimeZone(struct tm * tm)
* Use localtime to convert that time_t to broken-down time,
* and reassemble to get a representation of local time.
*/
- tx = localtime(&mytime);
+ tx = pg_localtime(&mytime);
if (!tx)
ereport(ERROR,
(errcode(ERRCODE_DATETIME_VALUE_OUT_OF_RANGE),
@@ -1624,7 +1625,6 @@ DetermineLocalTimeZone(struct tm * tm)
* computable as mysec - locsec.
*/
delta1 = mysec - locsec;
-
/*
* However, if that GMT time and the local time we are
* actually interested in are on opposite sides of a
@@ -1635,7 +1635,7 @@ DetermineLocalTimeZone(struct tm * tm)
*/
mysec += delta1;
mytime = (time_t) mysec;
- tx = localtime(&mytime);
+ tx = pg_localtime(&mytime);
if (!tx)
ereport(ERROR,
(errcode(ERRCODE_DATETIME_VALUE_OUT_OF_RANGE),
@@ -1660,7 +1660,7 @@ DetermineLocalTimeZone(struct tm * tm)
{
mysec += (delta2 - delta1);
mytime = (time_t) mysec;
- tx = localtime(&mytime);
+ tx = pg_localtime(&mytime);
if (!tx)
ereport(ERROR,
(errcode(ERRCODE_DATETIME_VALUE_OUT_OF_RANGE),
@@ -1698,7 +1698,7 @@ DetermineLocalTimeZone(struct tm * tm)
*/
int
DecodeTimeOnly(char **field, int *ftype, int nf,
- int *dtype, struct tm * tm, fsec_t *fsec, int *tzp)
+ int *dtype, struct pg_tm * tm, fsec_t *fsec, int *tzp)
{
int fmask = 0,
tmask,
@@ -2201,7 +2201,7 @@ DecodeTimeOnly(char **field, int *ftype, int nf,
/* timezone not specified? then find local timezone if possible */
if ((tzp != NULL) && (!(fmask & DTK_M(TZ))))
{
- struct tm tt,
+ struct pg_tm tt,
*tmp = &tt;
/*
@@ -2236,7 +2236,7 @@ DecodeTimeOnly(char **field, int *ftype, int nf,
* Insist on a complete set of fields.
*/
static int
-DecodeDate(char *str, int fmask, int *tmask, struct tm * tm)
+DecodeDate(char *str, int fmask, int *tmask, struct pg_tm * tm)
{
fsec_t fsec;
int nf = 0;
@@ -2394,7 +2394,7 @@ DecodeDate(char *str, int fmask, int *tmask, struct tm * tm)
* can be used to represent time spans.
*/
static int
-DecodeTime(char *str, int fmask, int *tmask, struct tm * tm, fsec_t *fsec)
+DecodeTime(char *str, int fmask, int *tmask, struct pg_tm * tm, fsec_t *fsec)
{
char *cp;
@@ -2461,7 +2461,7 @@ DecodeTime(char *str, int fmask, int *tmask, struct tm * tm, fsec_t *fsec)
*/
static int
DecodeNumber(int flen, char *str, bool haveTextMonth, int fmask,
- int *tmask, struct tm * tm, fsec_t *fsec, int *is2digits)
+ int *tmask, struct pg_tm * tm, fsec_t *fsec, int *is2digits)
{
int val;
char *cp;
@@ -2651,7 +2651,7 @@ DecodeNumber(int flen, char *str, bool haveTextMonth, int fmask,
*/
static int
DecodeNumberField(int len, char *str, int fmask,
- int *tmask, struct tm * tm, fsec_t *fsec, int *is2digits)
+ int *tmask, struct pg_tm * tm, fsec_t *fsec, int *is2digits)
{
char *cp;
@@ -2797,10 +2797,8 @@ DecodeTimezone(char *str, int *tzp)
* - thomas 2000-03-15
*
* Return 0 if okay (and set *tzp), a DTERR code if not okay.
- *
- * NB: this must *not* ereport on failure; see commands/variable.c.
*/
-int
+static int
DecodePosixTimezone(char *str, int *tzp)
{
int val,
@@ -2911,7 +2909,7 @@ DecodeSpecial(int field, char *lowtoken, int *val)
* preceding an hh:mm:ss field. - thomas 1998-04-30
*/
int
-DecodeInterval(char **field, int *ftype, int nf, int *dtype, struct tm * tm, fsec_t *fsec)
+DecodeInterval(char **field, int *ftype, int nf, int *dtype, struct pg_tm * tm, fsec_t *fsec)
{
int is_before = FALSE;
char *cp;
@@ -3365,7 +3363,7 @@ datebsearch(char *key, datetkn *base, unsigned int nel)
* Encode date as local time.
*/
int
-EncodeDateOnly(struct tm * tm, int style, char *str)
+EncodeDateOnly(struct pg_tm * tm, int style, char *str)
{
if ((tm->tm_mon < 1) || (tm->tm_mon > 12))
return -1;
@@ -3425,7 +3423,7 @@ EncodeDateOnly(struct tm * tm, int style, char *str)
* Encode time fields only.
*/
int
-EncodeTimeOnly(struct tm * tm, fsec_t fsec, int *tzp, int style, char *str)
+EncodeTimeOnly(struct pg_tm * tm, fsec_t fsec, int *tzp, int style, char *str)
{
if ((tm->tm_hour < 0) || (tm->tm_hour > 24))
return -1;
@@ -3478,7 +3476,7 @@ EncodeTimeOnly(struct tm * tm, fsec_t fsec, int *tzp, int style, char *str)
* European - dd/mm/yyyy
*/
int
-EncodeDateTime(struct tm * tm, fsec_t fsec, int *tzp, char **tzn, int style, char *str)
+EncodeDateTime(struct pg_tm * tm, fsec_t fsec, int *tzp, char **tzn, int style, char *str)
{
int day,
hour,
@@ -3709,7 +3707,7 @@ EncodeDateTime(struct tm * tm, fsec_t fsec, int *tzp, char **tzn, int style, cha
* - thomas 1998-04-30
*/
int
-EncodeInterval(struct tm * tm, fsec_t fsec, int style, char *str)
+EncodeInterval(struct pg_tm * tm, fsec_t fsec, int style, char *str)
{
int is_before = FALSE;
int is_nonzero = FALSE;
diff --git a/src/backend/utils/adt/formatting.c b/src/backend/utils/adt/formatting.c
index 6a9f26e0001..5df25da8e9b 100644
--- a/src/backend/utils/adt/formatting.c
+++ b/src/backend/utils/adt/formatting.c
@@ -1,7 +1,7 @@
/* -----------------------------------------------------------------------
* formatting.c
*
- * $PostgreSQL: pgsql/src/backend/utils/adt/formatting.c,v 1.74 2004/05/07 00:24:58 tgl Exp $
+ * $PostgreSQL: pgsql/src/backend/utils/adt/formatting.c,v 1.75 2004/05/21 05:08:02 tgl Exp $
*
*
* Portions Copyright (c) 1999-2003, PostgreSQL Global Development Group
@@ -70,7 +70,6 @@
#include "postgres.h"
#include <ctype.h>
-#include <sys/time.h>
#include <unistd.h>
#include <math.h>
#include <float.h>
@@ -410,7 +409,7 @@ typedef struct
*/
typedef struct TmToChar
{
- struct tm tm; /* classic 'tm' struct */
+ struct pg_tm tm; /* classic 'tm' struct */
fsec_t fsec; /* fractional seconds */
char *tzn; /* timezone */
} TmToChar;
@@ -897,7 +896,7 @@ static int dch_global(int arg, char *inout, int suf, int flag, FormatNode *node,
static int dch_time(int arg, char *inout, int suf, int flag, FormatNode *node, void *data);
static int dch_date(int arg, char *inout, int suf, int flag, FormatNode *node, void *data);
static void do_to_timestamp(text *date_txt, text *fmt,
- struct tm *tm, fsec_t *fsec);
+ struct pg_tm *tm, fsec_t *fsec);
static char *fill_str(char *str, int c, int max);
static FormatNode *NUM_cache(int len, NUMDesc *Num, char *pars_str, bool *shouldFree);
static char *int_to_roman(int number);
@@ -1695,7 +1694,7 @@ static int
dch_time(int arg, char *inout, int suf, int flag, FormatNode *node, void *data)
{
char *p_inout = inout;
- struct tm *tm = NULL;
+ struct pg_tm *tm = NULL;
TmFromChar *tmfc = NULL;
TmToChar *tmtc = NULL;
@@ -2057,7 +2056,7 @@ dch_date(int arg, char *inout, int suf, int flag, FormatNode *node, void *data)
*p_inout;
int i,
len;
- struct tm *tm = NULL;
+ struct pg_tm *tm = NULL;
TmFromChar *tmfc = NULL;
TmToChar *tmtc = NULL;
@@ -2768,7 +2767,7 @@ static text *
datetime_to_char_body(TmToChar *tmtc, text *fmt)
{
FormatNode *format;
- struct tm *tm = NULL;
+ struct pg_tm *tm = NULL;
char *fmt_str,
*result;
bool incache;
@@ -2962,7 +2961,7 @@ to_timestamp(PG_FUNCTION_ARGS)
text *fmt = PG_GETARG_TEXT_P(1);
Timestamp result;
int tz;
- struct tm tm;
+ struct pg_tm tm;
fsec_t fsec;
do_to_timestamp(date_txt, fmt, &tm, &fsec);
@@ -2988,7 +2987,7 @@ to_date(PG_FUNCTION_ARGS)
text *date_txt = PG_GETARG_TEXT_P(0);
text *fmt = PG_GETARG_TEXT_P(1);
DateADT result;
- struct tm tm;
+ struct pg_tm tm;
fsec_t fsec;
do_to_timestamp(date_txt, fmt, &tm, &fsec);
@@ -3001,12 +3000,12 @@ to_date(PG_FUNCTION_ARGS)
/*
* do_to_timestamp: shared code for to_timestamp and to_date
*
- * Parse the 'date_txt' according to 'fmt', return results as a struct tm
+ * Parse the 'date_txt' according to 'fmt', return results as a struct pg_tm
* and fractional seconds.
*/
static void
do_to_timestamp(text *date_txt, text *fmt,
- struct tm *tm, fsec_t *fsec)
+ struct pg_tm *tm, fsec_t *fsec)
{
FormatNode *format;
TmFromChar tmfc;
diff --git a/src/backend/utils/adt/misc.c b/src/backend/utils/adt/misc.c
index 2bd013eb149..673b175bbc0 100644
--- a/src/backend/utils/adt/misc.c
+++ b/src/backend/utils/adt/misc.c
@@ -8,14 +8,13 @@
*
*
* IDENTIFICATION
- * $PostgreSQL: pgsql/src/backend/utils/adt/misc.c,v 1.32 2003/11/29 19:51:58 pgsql Exp $
+ * $PostgreSQL: pgsql/src/backend/utils/adt/misc.c,v 1.33 2004/05/21 05:08:02 tgl Exp $
*
*-------------------------------------------------------------------------
*/
#include "postgres.h"
#include <sys/file.h>
-#include <time.h>
#include "commands/dbcommands.h"
#include "miscadmin.h"
diff --git a/src/backend/utils/adt/nabstime.c b/src/backend/utils/adt/nabstime.c
index 20fc55309c1..fb17bc13c9a 100644
--- a/src/backend/utils/adt/nabstime.c
+++ b/src/backend/utils/adt/nabstime.c
@@ -10,21 +10,20 @@
*
*
* IDENTIFICATION
- * $PostgreSQL: pgsql/src/backend/utils/adt/nabstime.c,v 1.120 2004/05/05 17:28:46 tgl Exp $
+ * $PostgreSQL: pgsql/src/backend/utils/adt/nabstime.c,v 1.121 2004/05/21 05:08:02 tgl Exp $
*
*-------------------------------------------------------------------------
*/
#include "postgres.h"
#include <ctype.h>
-#include <time.h>
-#include <sys/time.h>
#include <float.h>
#include <limits.h>
#include "access/xact.h"
#include "libpq/pqformat.h"
#include "miscadmin.h"
+#include "pgtime.h"
#include "utils/builtins.h"
@@ -76,8 +75,8 @@
* Function prototypes -- internal to this file only
*/
-static AbsoluteTime tm2abstime(struct tm * tm, int tz);
-static void reltime2tm(RelativeTime time, struct tm * tm);
+static AbsoluteTime tm2abstime(struct pg_tm * tm, int tz);
+static void reltime2tm(RelativeTime time, struct pg_tm * tm);
static int istinterval(char *i_string,
AbsoluteTime *i_start,
AbsoluteTime *i_end);
@@ -142,10 +141,10 @@ AbsoluteTimeUsecToTimestampTz(AbsoluteTime sec, int usec)
/*
* GetCurrentDateTime()
*
- * Get the transaction start time ("now()") broken down as a struct tm.
+ * Get the transaction start time ("now()") broken down as a struct pg_tm.
*/
void
-GetCurrentDateTime(struct tm * tm)
+GetCurrentDateTime(struct pg_tm * tm)
{
int tz;
@@ -155,11 +154,11 @@ GetCurrentDateTime(struct tm * tm)
/*
* GetCurrentTimeUsec()
*
- * Get the transaction start time ("now()") broken down as a struct tm,
+ * Get the transaction start time ("now()") broken down as a struct pg_tm,
* including fractional seconds and timezone offset.
*/
void
-GetCurrentTimeUsec(struct tm * tm, fsec_t *fsec, int *tzp)
+GetCurrentTimeUsec(struct pg_tm * tm, fsec_t *fsec, int *tzp)
{
int tz;
int usec;
@@ -177,10 +176,10 @@ GetCurrentTimeUsec(struct tm * tm, fsec_t *fsec, int *tzp)
void
-abstime2tm(AbsoluteTime _time, int *tzp, struct tm * tm, char **tzn)
+abstime2tm(AbsoluteTime _time, int *tzp, struct pg_tm * tm, char **tzn)
{
time_t time = (time_t) _time;
- struct tm *tx;
+ struct pg_tm *tx;
/*
* If HasCTZSet is true then we have a brute force time zone
@@ -191,9 +190,9 @@ abstime2tm(AbsoluteTime _time, int *tzp, struct tm * tm, char **tzn)
time -= CTimeZone;
if ((!HasCTZSet) && (tzp != NULL))
- tx = localtime(&time);
+ tx = pg_localtime(&time);
else
- tx = gmtime(&time);
+ tx = pg_gmtime(&time);
tm->tm_year = tx->tm_year + 1900;
tm->tm_mon = tx->tm_mon + 1;
@@ -203,7 +202,6 @@ abstime2tm(AbsoluteTime _time, int *tzp, struct tm * tm, char **tzn)
tm->tm_sec = tx->tm_sec;
tm->tm_isdst = tx->tm_isdst;
-#if defined(HAVE_TM_ZONE)
tm->tm_gmtoff = tx->tm_gmtoff;
tm->tm_zone = tx->tm_zone;
@@ -248,66 +246,6 @@ abstime2tm(AbsoluteTime _time, int *tzp, struct tm * tm, char **tzn)
}
else
tm->tm_isdst = -1;
-#elif defined(HAVE_INT_TIMEZONE)
- if (tzp != NULL)
- {
- /*
- * We have a brute force time zone per SQL99? Then use it without
- * change since we have already rotated to the time zone.
- */
- if (HasCTZSet)
- {
- *tzp = CTimeZone;
- tm->tm_isdst = 0;
- if (tzn != NULL)
- *tzn = NULL;
- }
- else
- {
- *tzp = ((tm->tm_isdst > 0) ? (TIMEZONE_GLOBAL - 3600) : TIMEZONE_GLOBAL);
-
- if (tzn != NULL)
- {
- /*
- * Copy no more than MAXTZLEN bytes of timezone to tzn, in
- * case it contains an error message, which doesn't fit in
- * the buffer
- */
- StrNCpy(*tzn, tzname[tm->tm_isdst], MAXTZLEN + 1);
- if (strlen(tzname[tm->tm_isdst]) > MAXTZLEN)
- ereport(WARNING,
- (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
- errmsg("invalid time zone name: \"%s\"",
- tzname[tm->tm_isdst])));
- }
- }
- }
- else
- tm->tm_isdst = -1;
-#else /* not (HAVE_TM_ZONE || HAVE_INT_TIMEZONE) */
- if (tzp != NULL)
- {
- /*
- * We have a brute force time zone per SQL99? Then use it without
- * change since we have already rotated to the time zone.
- */
- if (HasCTZSet)
- {
- *tzp = CTimeZone;
- if (tzn != NULL)
- *tzn = NULL;
- }
- else
- {
- /* default to UTC */
- *tzp = 0;
- if (tzn != NULL)
- *tzn = NULL;
- }
- }
- else
- tm->tm_isdst = -1;
-#endif
}
@@ -316,7 +254,7 @@ abstime2tm(AbsoluteTime _time, int *tzp, struct tm * tm, char **tzn)
* Note that tm has full year (not 1900-based) and 1-based month.
*/
static AbsoluteTime
-tm2abstime(struct tm * tm, int tz)
+tm2abstime(struct pg_tm * tm, int tz)
{
int day;
AbsoluteTime sec;
@@ -362,7 +300,7 @@ abstimein(PG_FUNCTION_ARGS)
AbsoluteTime result;
fsec_t fsec;
int tz = 0;
- struct tm date,
+ struct pg_tm date,
*tm = &date;
int dterr;
char *field[MAXDATEFIELDS];
@@ -428,7 +366,7 @@ abstimeout(PG_FUNCTION_ARGS)
char *result;
int tz;
double fsec = 0;
- struct tm tt,
+ struct pg_tm tt,
*tm = &tt;
char buf[MAXDATELEN + 1];
char zone[MAXDATELEN + 1],
@@ -611,7 +549,7 @@ timestamp_abstime(PG_FUNCTION_ARGS)
AbsoluteTime result;
fsec_t fsec;
int tz;
- struct tm tt,
+ struct pg_tm tt,
*tm = &tt;
if (TIMESTAMP_IS_NOBEGIN(timestamp))
@@ -642,7 +580,7 @@ abstime_timestamp(PG_FUNCTION_ARGS)
{
AbsoluteTime abstime = PG_GETARG_ABSOLUTETIME(0);
Timestamp result;
- struct tm tt,
+ struct pg_tm tt,
*tm = &tt;
int tz;
char zone[MAXDATELEN + 1],
@@ -687,7 +625,7 @@ timestamptz_abstime(PG_FUNCTION_ARGS)
TimestampTz timestamp = PG_GETARG_TIMESTAMP(0);
AbsoluteTime result;
fsec_t fsec;
- struct tm tt,
+ struct pg_tm tt,
*tm = &tt;
if (TIMESTAMP_IS_NOBEGIN(timestamp))
@@ -715,7 +653,7 @@ abstime_timestamptz(PG_FUNCTION_ARGS)
{
AbsoluteTime abstime = PG_GETARG_ABSOLUTETIME(0);
TimestampTz result;
- struct tm tt,
+ struct pg_tm tt,
*tm = &tt;
int tz;
char zone[MAXDATELEN + 1],
@@ -763,7 +701,7 @@ reltimein(PG_FUNCTION_ARGS)
{
char *str = PG_GETARG_CSTRING(0);
RelativeTime result;
- struct tm tt,
+ struct pg_tm tt,
*tm = &tt;
fsec_t fsec;
int dtype;
@@ -811,7 +749,7 @@ reltimeout(PG_FUNCTION_ARGS)
{
RelativeTime time = PG_GETARG_RELATIVETIME(0);
char *result;
- struct tm tt,
+ struct pg_tm tt,
*tm = &tt;
char buf[MAXDATELEN + 1];
@@ -849,7 +787,7 @@ reltimesend(PG_FUNCTION_ARGS)
static void
-reltime2tm(RelativeTime time, struct tm * tm)
+reltime2tm(RelativeTime time, struct pg_tm * tm)
{
double dtime = time;
@@ -1732,8 +1670,8 @@ timeofday(PG_FUNCTION_ARGS)
gettimeofday(&tp, &tpz);
tt = (time_t) tp.tv_sec;
- strftime(templ, sizeof(templ), "%a %b %d %H:%M:%S.%%06d %Y %Z",
- localtime(&tt));
+ pg_strftime(templ, sizeof(templ), "%a %b %d %H:%M:%S.%%06d %Y %Z",
+ pg_localtime(&tt));
snprintf(buf, sizeof(buf), templ, tp.tv_usec);
len = VARHDRSZ + strlen(buf);
diff --git a/src/backend/utils/adt/timestamp.c b/src/backend/utils/adt/timestamp.c
index cd59b7f34ad..1705441329f 100644
--- a/src/backend/utils/adt/timestamp.c
+++ b/src/backend/utils/adt/timestamp.c
@@ -8,7 +8,7 @@
*
*
* IDENTIFICATION
- * $PostgreSQL: pgsql/src/backend/utils/adt/timestamp.c,v 1.105 2004/05/07 00:24:58 tgl Exp $
+ * $PostgreSQL: pgsql/src/backend/utils/adt/timestamp.c,v 1.106 2004/05/21 05:08:02 tgl Exp $
*
*-------------------------------------------------------------------------
*/
@@ -70,7 +70,7 @@ timestamp_in(PG_FUNCTION_ARGS)
int32 typmod = PG_GETARG_INT32(2);
Timestamp result;
fsec_t fsec;
- struct tm tt,
+ struct pg_tm tt,
*tm = &tt;
int tz;
int dtype;
@@ -137,7 +137,7 @@ timestamp_out(PG_FUNCTION_ARGS)
{
Timestamp timestamp = PG_GETARG_TIMESTAMP(0);
char *result;
- struct tm tt,
+ struct pg_tm tt,
*tm = &tt;
fsec_t fsec;
char *tzn = NULL;
@@ -296,7 +296,7 @@ timestamptz_in(PG_FUNCTION_ARGS)
int32 typmod = PG_GETARG_INT32(2);
TimestampTz result;
fsec_t fsec;
- struct tm tt,
+ struct pg_tm tt,
*tm = &tt;
int tz;
int dtype;
@@ -364,7 +364,7 @@ timestamptz_out(PG_FUNCTION_ARGS)
TimestampTz dt = PG_GETARG_TIMESTAMPTZ(0);
char *result;
int tz;
- struct tm tt,
+ struct pg_tm tt,
*tm = &tt;
fsec_t fsec;
char *tzn;
@@ -456,7 +456,7 @@ interval_in(PG_FUNCTION_ARGS)
int32 typmod = PG_GETARG_INT32(2);
Interval *result;
fsec_t fsec;
- struct tm tt,
+ struct pg_tm tt,
*tm = &tt;
int dtype;
int nf;
@@ -520,7 +520,7 @@ interval_out(PG_FUNCTION_ARGS)
{
Interval *span = PG_GETARG_INTERVAL_P(0);
char *result;
- struct tm tt,
+ struct pg_tm tt,
*tm = &tt;
fsec_t fsec;
char buf[MAXDATELEN + 1];
@@ -933,23 +933,19 @@ dt2time(Timestamp jd, int *hour, int *min, int *sec, fsec_t *fsec)
* local time zone. If out of this range, leave as GMT. - tgl 97/05/27
*/
int
-timestamp2tm(Timestamp dt, int *tzp, struct tm * tm, fsec_t *fsec, char **tzn)
+timestamp2tm(Timestamp dt, int *tzp, struct pg_tm * tm, fsec_t *fsec, char **tzn)
{
#ifdef HAVE_INT64_TIMESTAMP
int date,
date0;
int64 time;
-
#else
double date,
date0;
double time;
#endif
time_t utime;
-
-#if defined(HAVE_TM_ZONE) || defined(HAVE_INT_TIMEZONE)
- struct tm *tx;
-#endif
+ struct pg_tm *tx;
date0 = POSTGRES_EPOCH_JDATE;
@@ -1006,10 +1002,8 @@ timestamp2tm(Timestamp dt, int *tzp, struct tm * tm, fsec_t *fsec, char **tzn)
{
*tzp = CTimeZone;
tm->tm_isdst = 0;
-#if defined(HAVE_TM_ZONE)
tm->tm_gmtoff = CTimeZone;
tm->tm_zone = NULL;
-#endif
if (tzn != NULL)
*tzn = NULL;
}
@@ -1027,46 +1021,20 @@ timestamp2tm(Timestamp dt, int *tzp, struct tm * tm, fsec_t *fsec, char **tzn)
utime = (dt + ((date0 - UNIX_EPOCH_JDATE) * 86400));
#endif
-#if defined(HAVE_TM_ZONE) || defined(HAVE_INT_TIMEZONE)
- tx = localtime(&utime);
+ tx = pg_localtime(&utime);
tm->tm_year = tx->tm_year + 1900;
tm->tm_mon = tx->tm_mon + 1;
tm->tm_mday = tx->tm_mday;
tm->tm_hour = tx->tm_hour;
tm->tm_min = tx->tm_min;
-#if NOT_USED
-/* XXX HACK
- * Argh! My Linux box puts in a 1 second offset for dates less than 1970
- * but only if the seconds field was non-zero. So, don't copy the seconds
- * field and instead carry forward from the original - thomas 97/06/18
- * Note that Linux uses the standard freeware zic package as do
- * many other platforms so this may not be Linux/ix86-specific.
- * Still shows a problem on my up to date Linux box - thomas 2001-01-17
- */
tm->tm_sec = tx->tm_sec;
-#endif
tm->tm_isdst = tx->tm_isdst;
-
-#if defined(HAVE_TM_ZONE)
tm->tm_gmtoff = tx->tm_gmtoff;
tm->tm_zone = tx->tm_zone;
- *tzp = -(tm->tm_gmtoff); /* tm_gmtoff is Sun/DEC-ism */
+ *tzp = -(tm->tm_gmtoff);
if (tzn != NULL)
*tzn = (char *) tm->tm_zone;
-#elif defined(HAVE_INT_TIMEZONE)
- *tzp = ((tm->tm_isdst > 0) ? (TIMEZONE_GLOBAL - 3600) : TIMEZONE_GLOBAL);
- if (tzn != NULL)
- *tzn = tzname[(tm->tm_isdst > 0)];
-#endif
-
-#else /* not (HAVE_TM_ZONE || HAVE_INT_TIMEZONE) */
- *tzp = 0;
- /* Mark this as *no* time zone available */
- tm->tm_isdst = -1;
- if (tzn != NULL)
- *tzn = NULL;
-#endif
}
else
{
@@ -1096,12 +1064,11 @@ timestamp2tm(Timestamp dt, int *tzp, struct tm * tm, fsec_t *fsec, char **tzn)
* Returns -1 on failure (value out of range).
*/
int
-tm2timestamp(struct tm * tm, fsec_t fsec, int *tzp, Timestamp *result)
+tm2timestamp(struct pg_tm * tm, fsec_t fsec, int *tzp, Timestamp *result)
{
#ifdef HAVE_INT64_TIMESTAMP
int date;
int64 time;
-
#else
double date,
time;
@@ -1135,11 +1102,10 @@ tm2timestamp(struct tm * tm, fsec_t fsec, int *tzp, Timestamp *result)
* Convert a interval data type to a tm structure.
*/
int
-interval2tm(Interval span, struct tm * tm, fsec_t *fsec)
+interval2tm(Interval span, struct pg_tm * tm, fsec_t *fsec)
{
#ifdef HAVE_INT64_TIMESTAMP
int64 time;
-
#else
double time;
#endif
@@ -1179,7 +1145,7 @@ interval2tm(Interval span, struct tm * tm, fsec_t *fsec)
}
int
-tm2interval(struct tm * tm, fsec_t fsec, Interval *span)
+tm2interval(struct pg_tm * tm, fsec_t fsec, Interval *span)
{
span->month = ((tm->tm_year * 12) + tm->tm_mon);
#ifdef HAVE_INT64_TIMESTAMP
@@ -1251,12 +1217,12 @@ interval_finite(PG_FUNCTION_ARGS)
*---------------------------------------------------------*/
void
-GetEpochTime(struct tm * tm)
+GetEpochTime(struct pg_tm * tm)
{
- struct tm *t0;
+ struct pg_tm *t0;
time_t epoch = 0;
- t0 = gmtime(&epoch);
+ t0 = pg_gmtime(&epoch);
tm->tm_year = t0->tm_year;
tm->tm_mon = t0->tm_mon;
@@ -1276,7 +1242,7 @@ Timestamp
SetEpochTimestamp(void)
{
Timestamp dt;
- struct tm tt,
+ struct pg_tm tt,
*tm = &tt;
GetEpochTime(tm);
@@ -1896,7 +1862,7 @@ timestamp_pl_interval(PG_FUNCTION_ARGS)
{
if (span->month != 0)
{
- struct tm tt,
+ struct pg_tm tt,
*tm = &tt;
fsec_t fsec;
@@ -1974,7 +1940,7 @@ timestamptz_pl_interval(PG_FUNCTION_ARGS)
{
if (span->month != 0)
{
- struct tm tt,
+ struct pg_tm tt,
*tm = &tt;
fsec_t fsec;
@@ -2296,11 +2262,11 @@ timestamp_age(PG_FUNCTION_ARGS)
fsec_t fsec,
fsec1,
fsec2;
- struct tm tt,
+ struct pg_tm tt,
*tm = &tt;
- struct tm tt1,
+ struct pg_tm tt1,
*tm1 = &tt1;
- struct tm tt2,
+ struct pg_tm tt2,
*tm2 = &tt2;
result = (Interval *) palloc(sizeof(Interval));
@@ -2407,11 +2373,11 @@ timestamptz_age(PG_FUNCTION_ARGS)
fsec_t fsec,
fsec1,
fsec2;
- struct tm tt,
+ struct pg_tm tt,
*tm = &tt;
- struct tm tt1,
+ struct pg_tm tt1,
*tm1 = &tt1;
- struct tm tt2,
+ struct pg_tm tt2,
*tm2 = &tt2;
result = (Interval *) palloc(sizeof(Interval));
@@ -2702,7 +2668,7 @@ timestamp_trunc(PG_FUNCTION_ARGS)
val;
char *lowunits;
fsec_t fsec;
- struct tm tt,
+ struct pg_tm tt,
*tm = &tt;
if (TIMESTAMP_NOT_FINITE(timestamp))
@@ -2806,7 +2772,7 @@ timestamptz_trunc(PG_FUNCTION_ARGS)
char *lowunits;
fsec_t fsec;
char *tzn;
- struct tm tt,
+ struct pg_tm tt,
*tm = &tt;
if (TIMESTAMP_NOT_FINITE(timestamp))
@@ -2909,7 +2875,7 @@ interval_trunc(PG_FUNCTION_ARGS)
val;
char *lowunits;
fsec_t fsec;
- struct tm tt,
+ struct pg_tm tt,
*tm = &tt;
result = (Interval *) palloc(sizeof(Interval));
@@ -3142,7 +3108,7 @@ timestamp_part(PG_FUNCTION_ARGS)
val;
char *lowunits;
fsec_t fsec;
- struct tm tt,
+ struct pg_tm tt,
*tm = &tt;
if (TIMESTAMP_NOT_FINITE(timestamp))
@@ -3355,7 +3321,7 @@ timestamptz_part(PG_FUNCTION_ARGS)
double dummy;
fsec_t fsec;
char *tzn;
- struct tm tt,
+ struct pg_tm tt,
*tm = &tt;
if (TIMESTAMP_NOT_FINITE(timestamp))
@@ -3544,7 +3510,7 @@ interval_part(PG_FUNCTION_ARGS)
val;
char *lowunits;
fsec_t fsec;
- struct tm tt,
+ struct pg_tm tt,
*tm = &tt;
lowunits = downcase_truncate_identifier(VARDATA(units),
@@ -3755,7 +3721,7 @@ static TimestampTz
timestamp2timestamptz(Timestamp timestamp)
{
TimestampTz result;
- struct tm tt,
+ struct pg_tm tt,
*tm = &tt;
fsec_t fsec;
int tz;
@@ -3788,7 +3754,7 @@ timestamptz_timestamp(PG_FUNCTION_ARGS)
{
TimestampTz timestamp = PG_GETARG_TIMESTAMPTZ(0);
Timestamp result;
- struct tm tt,
+ struct pg_tm tt,
*tm = &tt;
fsec_t fsec;
char *tzn;
diff --git a/src/backend/utils/error/elog.c b/src/backend/utils/error/elog.c
index 012842b61d9..d7e5a983763 100644
--- a/src/backend/utils/error/elog.c
+++ b/src/backend/utils/error/elog.c
@@ -37,18 +37,16 @@
*
*
* IDENTIFICATION
- * $PostgreSQL: pgsql/src/backend/utils/error/elog.c,v 1.136 2004/05/07 00:24:58 tgl Exp $
+ * $PostgreSQL: pgsql/src/backend/utils/error/elog.c,v 1.137 2004/05/21 05:08:02 tgl Exp $
*
*-------------------------------------------------------------------------
*/
#include "postgres.h"
-#include <time.h>
#include <fcntl.h>
#include <errno.h>
#include <unistd.h>
#include <signal.h>
-#include <sys/time.h>
#include <ctype.h>
#ifdef HAVE_SYSLOG
#include <syslog.h>
@@ -58,6 +56,7 @@
#include "libpq/pqformat.h"
#include "mb/pg_wchar.h"
#include "miscadmin.h"
+#include "pgtime.h"
#include "storage/ipc.h"
#include "tcop/tcopprot.h"
#include "utils/memutils.h"
@@ -1217,8 +1216,8 @@ log_line_prefix(StringInfo buf)
time_t stamp_time = time(NULL);
char strfbuf[128];
- strftime(strfbuf, sizeof(strfbuf), "%Y-%m-%d %H:%M:%S %Z",
- localtime(&stamp_time));
+ pg_strftime(strfbuf, sizeof(strfbuf), "%Y-%m-%d %H:%M:%S %Z",
+ pg_localtime(&stamp_time));
appendStringInfoString(buf, strfbuf);
}
break;
@@ -1228,8 +1227,8 @@ log_line_prefix(StringInfo buf)
time_t stamp_time = MyProcPort->session_start.tv_sec;
char strfbuf[128];
- strftime(strfbuf, sizeof(strfbuf), "%Y-%m-%d %H:%M:%S %Z",
- localtime(&stamp_time));
+ pg_strftime(strfbuf, sizeof(strfbuf), "%Y-%m-%d %H:%M:%S %Z",
+ pg_localtime(&stamp_time));
appendStringInfoString(buf, strfbuf);
}
break;
diff --git a/src/backend/utils/misc/guc.c b/src/backend/utils/misc/guc.c
index f59e872f57b..8a51e8aa049 100644
--- a/src/backend/utils/misc/guc.c
+++ b/src/backend/utils/misc/guc.c
@@ -10,7 +10,7 @@
* Written by Peter Eisentraut <[email protected]>.
*
* IDENTIFICATION
- * $PostgreSQL: pgsql/src/backend/utils/misc/guc.c,v 1.205 2004/05/08 02:11:46 momjian Exp $
+ * $PostgreSQL: pgsql/src/backend/utils/misc/guc.c,v 1.206 2004/05/21 05:08:03 tgl Exp $
*
*--------------------------------------------------------------------
*/
@@ -2094,10 +2094,6 @@ InitializeGUCOptions(void)
if (env != NULL)
SetConfigOption("datestyle", env, PGC_POSTMASTER, PGC_S_ENV_VAR);
- env = getenv("TZ");
- if (env != NULL)
- SetConfigOption("timezone", env, PGC_POSTMASTER, PGC_S_ENV_VAR);
-
env = getenv("PGCLIENTENCODING");
if (env != NULL)
SetConfigOption("client_encoding", env, PGC_POSTMASTER, PGC_S_ENV_VAR);