aboutsummaryrefslogtreecommitdiff
path: root/src/backend/utils/adt/timestamp.c
diff options
context:
space:
mode:
authorTom Lane <tgl@sss.pgh.pa.us>2008-02-17 02:09:32 +0000
committerTom Lane <tgl@sss.pgh.pa.us>2008-02-17 02:09:32 +0000
commitcd004067742ee16ee63e55abfb4acbd5f09fbaab (patch)
tree62995d45f55faf5f5cdddc791d4d83d3de495b03 /src/backend/utils/adt/timestamp.c
parentee7a6770f607e9e7f0e1b29dc25a7b7d63cb7940 (diff)
downloadpostgresql-cd004067742ee16ee63e55abfb4acbd5f09fbaab.tar.gz
postgresql-cd004067742ee16ee63e55abfb4acbd5f09fbaab.zip
Replace time_t with pg_time_t (same values, but always int64) in on-disk
data structures and backend internal APIs. This solves problems we've seen recently with inconsistent layout of pg_control between machines that have 32-bit time_t and those that have already migrated to 64-bit time_t. Also, we can get out from under the problem that Windows' Unix-API emulation is not consistent about the width of time_t. There are a few remaining places where local time_t variables are used to hold the current or recent result of time(NULL). I didn't bother changing these since they do not affect any cross-module APIs and surely all platforms will have 64-bit time_t before overflow becomes an actual risk. time_t should be avoided for anything visible to extension modules, however.
Diffstat (limited to 'src/backend/utils/adt/timestamp.c')
-rw-r--r--src/backend/utils/adt/timestamp.c22
1 files changed, 16 insertions, 6 deletions
diff --git a/src/backend/utils/adt/timestamp.c b/src/backend/utils/adt/timestamp.c
index 1277562b794..f450922f26e 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.184 2008/01/01 19:45:52 momjian Exp $
+ * $PostgreSQL: pgsql/src/backend/utils/adt/timestamp.c,v 1.185 2008/02/17 02:09:28 tgl Exp $
*
*-------------------------------------------------------------------------
*/
@@ -1264,9 +1264,14 @@ TimestampDifferenceExceeds(TimestampTz start_time,
*
* We do not use time_t internally in Postgres, but this is provided for use
* by functions that need to interpret, say, a stat(2) result.
+ *
+ * To avoid having the function's ABI vary depending on the width of time_t,
+ * we declare the argument as pg_time_t, which is cast-compatible with
+ * time_t but always 64 bits wide (unless the platform has no 64-bit type).
+ * This detail should be invisible to callers, at least at source code level.
*/
TimestampTz
-time_t_to_timestamptz(time_t tm)
+time_t_to_timestamptz(pg_time_t tm)
{
TimestampTz result;
@@ -1284,17 +1289,22 @@ time_t_to_timestamptz(time_t tm)
* Convert a TimestampTz to time_t.
*
* This too is just marginally useful, but some places need it.
+ *
+ * To avoid having the function's ABI vary depending on the width of time_t,
+ * we declare the result as pg_time_t, which is cast-compatible with
+ * time_t but always 64 bits wide (unless the platform has no 64-bit type).
+ * This detail should be invisible to callers, at least at source code level.
*/
-time_t
+pg_time_t
timestamptz_to_time_t(TimestampTz t)
{
- time_t result;
+ pg_time_t result;
#ifdef HAVE_INT64_TIMESTAMP
- result = (time_t) (t / USECS_PER_SEC +
+ result = (pg_time_t) (t / USECS_PER_SEC +
((POSTGRES_EPOCH_JDATE - UNIX_EPOCH_JDATE) * SECS_PER_DAY));
#else
- result = (time_t) (t +
+ result = (pg_time_t) (t +
((POSTGRES_EPOCH_JDATE - UNIX_EPOCH_JDATE) * SECS_PER_DAY));
#endif