Skip to content

Commit f9f4004

Browse files
author
Thomas G. Lockhart
committed
Switch around conditional code so that HAVE_TM_ZONE takes precedence
over HAVE_INT_TIMEZONE. This may help out linux/glibc2 and Dec Alpha. Included #error precompiler macros to catch cases where neither is defined but USE_POSIX_TIME is (shouldn't happen). Hopefully this isn't just a gcc-ism.
1 parent e791d86 commit f9f4004

File tree

1 file changed

+25
-15
lines changed

1 file changed

+25
-15
lines changed

src/backend/utils/adt/nabstime.c

+25-15
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
*
88
*
99
* IDENTIFICATION
10-
* $Header: /cvsroot/pgsql/src/backend/utils/adt/nabstime.c,v 1.46 1998/10/08 18:30:09 momjian Exp $
10+
* $Header: /cvsroot/pgsql/src/backend/utils/adt/nabstime.c,v 1.47 1998/12/13 23:34:17 thomas Exp $
1111
*
1212
*-------------------------------------------------------------------------
1313
*/
@@ -61,23 +61,31 @@ GetCurrentAbsoluteTime(void)
6161
if (!HasCTZSet)
6262
{
6363
#ifdef USE_POSIX_TIME
64-
#if defined(HAVE_TZSET) && defined(HAVE_INT_TIMEZONE)
65-
tm = localtime(&now);
66-
67-
CDayLight = tm->tm_isdst;
68-
CTimeZone = (tm->tm_isdst ? (timezone - 3600) : timezone);
69-
strcpy(CTZName, tzname[tm->tm_isdst]);
70-
#else /* !HAVE_TZSET */
64+
#ifdef HAVE_TM_ZONE
7165
tm = localtime(&now);
7266

7367
CTimeZone = -tm->tm_gmtoff; /* tm_gmtoff is Sun/DEC-ism */
7468
CDayLight = (tm->tm_isdst > 0);
7569

70+
#if 0
7671
/*
7772
* XXX is there a better way to get local timezone string w/o
7873
* tzname? - tgl 97/03/18
7974
*/
8075
strftime(CTZName, MAXTZLEN, "%Z", tm);
76+
#endif
77+
/* XXX FreeBSD man pages indicate that this should work - thomas 1998-12-12 */
78+
if (tzn != NULL)
79+
strcpy(tzn, tm->tm_zone);
80+
81+
#elif defined(HAVE_INT_TIMEZONE)
82+
tm = localtime(&now);
83+
84+
CDayLight = tm->tm_isdst;
85+
CTimeZone = (tm->tm_isdst ? (timezone - 3600) : timezone);
86+
strcpy(CTZName, tzname[tm->tm_isdst]);
87+
#else
88+
#error USE_POSIX_TIME defined but no time zone available
8189
#endif
8290
#else /* ! USE_POSIX_TIME */
8391
CTimeZone = tb.timezone * 60;
@@ -133,7 +141,7 @@ abstime2tm(AbsoluteTime time, int *tzp, struct tm * tm, char *tzn)
133141
#endif
134142

135143
#if defined(DATEDEBUG)
136-
#if defined(HAVE_INT_TIMEZONE)
144+
#if (! defined(HAVE_TM_ZONE)) && defined(HAVE_INT_TIMEZONE)
137145
printf("datetime2tm- (localtime) %d.%02d.%02d %02d:%02d:%02d %s %s dst=%d\n",
138146
tx->tm_year, tx->tm_mon, tx->tm_mday, tx->tm_hour, tx->tm_min, tx->tm_sec,
139147
tzname[0], tzname[1], tx->tm_isdst);
@@ -154,12 +162,7 @@ abstime2tm(AbsoluteTime time, int *tzp, struct tm * tm, char *tzn)
154162
tm->tm_sec = tx->tm_sec;
155163
tm->tm_isdst = tx->tm_isdst;
156164

157-
#ifdef HAVE_INT_TIMEZONE
158-
if (tzp != NULL)
159-
*tzp = (tm->tm_isdst ? (timezone - 3600) : timezone);
160-
if (tzn != NULL)
161-
strcpy(tzn, tzname[tm->tm_isdst]);
162-
#else /* !HAVE_INT_TIMEZONE */
165+
#ifdef HAVE_TM_ZONE
163166
tm->tm_gmtoff = tx->tm_gmtoff;
164167
tm->tm_zone = tx->tm_zone;
165168

@@ -168,6 +171,13 @@ abstime2tm(AbsoluteTime time, int *tzp, struct tm * tm, char *tzn)
168171
/* XXX FreeBSD man pages indicate that this should work - tgl 97/04/23 */
169172
if (tzn != NULL)
170173
strcpy(tzn, tm->tm_zone);
174+
#elif defined(HAVE_INT_TIMEZONE)
175+
if (tzp != NULL)
176+
*tzp = (tm->tm_isdst ? (timezone - 3600) : timezone);
177+
if (tzn != NULL)
178+
strcpy(tzn, tzname[tm->tm_isdst]);
179+
#else /* !HAVE_INT_TIMEZONE */
180+
#error POSIX time support is broken
171181
#endif
172182
#else /* ! USE_POSIX_TIME */
173183
if (tzp != NULL)

0 commit comments

Comments
 (0)