Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit b5e16b1

Browse files
committed
Resync the source tree, commit some things that were missing (pqcomprim.c) and
bring in Thomas's updates for the date/time code...
1 parent 7d02575 commit b5e16b1

File tree

6 files changed

+151
-69
lines changed

6 files changed

+151
-69
lines changed

src/backend/libpq/pqcomprim.c

Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
#include <stdlib.h>
2+
#include <stdio.h>
3+
4+
#include "postgres.h"
5+
#include "libpq/pqcomm.h"
6+
7+
/* --------------------------------------------------------------------- */
8+
/* Is the other way around than system ntoh/hton, so we roll our own
9+
here */
10+
11+
#if BYTE_ORDER == LITTLE_ENDIAN
12+
#define ntoh_s(n) n
13+
#define ntoh_l(n) n
14+
#define hton_s(n) n
15+
#define hton_l(n) n
16+
#endif
17+
#if BYTE_ORDER == BIG_ENDIAN
18+
#define ntoh_s(n) (u_short)(((u_char *) &n)[0] << 8 | ((u_char *) &n)[1]);
19+
#define ntoh_l(n) (u_long)(((u_char *)&n)[0] << 24 | ((u_char *)&n)[1] << 16 |\
20+
((u_char *)&n)[2] << 8 | ((u_char *)&n)[3]);
21+
#define hton_s(n) (ntoh_s(n))
22+
#define hton_l(n) (ntoh_l(n))
23+
#endif
24+
#if BYTE_ORDER == PDP_ENDIAN
25+
#endif
26+
#ifndef ntoh_s
27+
#error Please write byte order macros
28+
#endif
29+
30+
/* --------------------------------------------------------------------- */
31+
int pqPutShort(const int integer, FILE *f)
32+
{
33+
int retval = 0;
34+
u_short n;
35+
36+
n = hton_s(integer);
37+
if(fwrite(&n, sizeof(u_short), 1, f) != 1)
38+
retval = 1;
39+
40+
return retval;
41+
}
42+
43+
/* --------------------------------------------------------------------- */
44+
int pqPutLong(const int integer, FILE *f)
45+
{
46+
int retval = 0;
47+
u_long n;
48+
49+
n = hton_l(integer);
50+
if(fwrite(&n, sizeof(u_long), 1, f) != 1)
51+
retval = 1;
52+
53+
return retval;
54+
}
55+
56+
/* --------------------------------------------------------------------- */
57+
int pqGetShort(int *result, FILE *f)
58+
{
59+
int retval = 0;
60+
u_short n;
61+
62+
if(fread(&n, sizeof(u_short), 1, f) != 1)
63+
retval = 1;
64+
65+
*result = ntoh_s(n);
66+
return retval;
67+
}
68+
69+
/* --------------------------------------------------------------------- */
70+
int pqGetLong(int *result, FILE *f)
71+
{
72+
int retval = 0;
73+
u_long n;
74+
75+
if(fread(&n, sizeof(u_long), 1, f) != 1)
76+
retval = 1;
77+
78+
*result = ntoh_l(n);
79+
return retval;
80+
}
81+
82+
/* --------------------------------------------------------------------- */

src/backend/utils/adt/dt.c

Lines changed: 15 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
*
88
*
99
* IDENTIFICATION
10-
* $Header: /cvsroot/pgsql/src/backend/utils/adt/Attic/dt.c,v 1.6 1997/03/16 19:03:20 scrappy Exp $
10+
* $Header: /cvsroot/pgsql/src/backend/utils/adt/Attic/dt.c,v 1.7 1997/03/18 16:35:17 scrappy Exp $
1111
*
1212
*-------------------------------------------------------------------------
1313
*/
@@ -17,28 +17,16 @@
1717
#include <string.h>
1818
#include <sys/types.h>
1919
#include <errno.h>
20-
#ifdef HAVE_VALUES_H
21-
# include <values.h>
22-
#else
23-
# include <float.h>
24-
# ifndef MINDOUBLE
25-
# define MINDOUBLE DBL_MIN
26-
# endif
27-
#endif
2820

2921
#include "postgres.h"
22+
#include <miscadmin.h>
23+
#ifndef USE_POSIX_TIME
24+
#include <sys/timeb.h>
25+
#endif
3026
#include "utils/builtins.h"
3127

32-
extern int EuroDates;
33-
34-
#define MAXDATEFIELDS 25
35-
3628
#define USE_DATE_CACHE 1
3729

38-
extern char *tzname[2];
39-
extern long int timezone;
40-
extern int daylight;
41-
4230
#define JTIME_INVALID (NAN)
4331
#define DATETIME_INVALID(j) {*j = JTIME_INVALID;}
4432
#define DATETIME_IS_INVALID(j) (isnan(*j))
@@ -114,7 +102,7 @@ printf( "datetime_in- time is %f %02d:%02d:%02d %f\n", time, tm->tm_hour, tm->tm
114102
if (tzp != 0) {
115103
*result = dt2local(*result, -tzp);
116104
} else {
117-
*result = dt2local(*result, -timezone);
105+
*result = dt2local(*result, -CTimeZone);
118106
};
119107
#ifdef DATEDEBUG
120108
printf( "datetime_in- date is %f\n", *result);
@@ -168,7 +156,7 @@ datetime_out(DateTime *dt)
168156

169157
} else {
170158

171-
time = (modf( dt2local( *dt, timezone)/86400, &date)*86400);
159+
time = (modf( dt2local( *dt, CTimeZone)/86400, &date)*86400);
172160
date += date2j(2000,1,1);
173161
if (time < 0) {
174162
time += 86400;
@@ -197,8 +185,8 @@ printf( "datetime_out- time is %02d:%02d:%02d %.7f\n", tm->tm_hour, tm->tm_min,
197185
tm->tm_isdst = -1;
198186

199187
#ifdef DATEDEBUG
200-
printf( "datetime_out- timezone is %s/%s; offset is %ld; daylight is %d\n",
201-
tzname[0], tzname[1], timezone, daylight);
188+
printf( "datetime_out- timezone is %s; offset is %ld; daylight is %d\n",
189+
CTZName, CTimeZone, CDayLight);
202190
#endif
203191

204192
EncodePostgresDate(tm, fsec, buf);
@@ -705,12 +693,6 @@ void dt2time(DateTime jd, int *hour, int *min, double *sec)
705693
* Returns the number of seconds since epoch (J2000)
706694
*/
707695

708-
#ifndef USE_POSIX_TIME
709-
long int timezone;
710-
long int daylight;
711-
#endif
712-
713-
714696
/* ParseDateTime()
715697
* Break string into tokens based on a date/time context.
716698
*/
@@ -845,7 +827,7 @@ DecodeDateTime( char *field[], int ftype[], int nf,
845827
tm->tm_min = 0;
846828
tm->tm_sec = 0;
847829
tm->tm_isdst = -1; /* don't know daylight savings time status apriori */
848-
if (tzp != NULL) *tzp = timezone;
830+
if (tzp != NULL) *tzp = CTimeZone;
849831

850832
for (i = 0; i < nf; i++) {
851833
#ifdef DATEDEBUG
@@ -1828,8 +1810,8 @@ int EncodePostgresDate(struct tm *tm, double fsec, char *str)
18281810
tm->tm_isdst = -1;
18291811

18301812
#ifdef DATEDEBUG
1831-
printf( "EncodePostgresDate- timezone is %s/%s; offset is %ld; daylight is %d\n",
1832-
tzname[0], tzname[1], timezone, daylight);
1813+
printf( "EncodePostgresDate- timezone is %s; offset is %ld; daylight is %d\n",
1814+
CTZName, CTimeZone, CDayLight);
18331815
#endif
18341816

18351817
day = date2j( tm->tm_year, tm->tm_mon, tm->tm_mday);
@@ -1848,15 +1830,15 @@ printf( "EncodePostgresDate- day is %d\n", day);
18481830

18491831
if (EuroDates) {
18501832
sprintf( str, "%3s %02d/%02d/%04d %02d:%02d:%02d %s", dabbrev,
1851-
tm->tm_mday, tm->tm_mon, tm->tm_year, tm->tm_hour, tm->tm_min, (int) rint(sec), tzname[0]);
1833+
tm->tm_mday, tm->tm_mon, tm->tm_year, tm->tm_hour, tm->tm_min, (int) rint(sec), CTZName);
18521834

18531835
} else if (tm->tm_year > 0) {
18541836
#if FALSE
18551837
sprintf( str, "%3s %3s %02d %02d:%02d:%02d %04d %s", dabbrev,
1856-
mabbrev, tm->tm_mday, tm->tm_hour, tm->tm_min, (int) rint(sec), tm->tm_year, tzname[0]);
1838+
mabbrev, tm->tm_mday, tm->tm_hour, tm->tm_min, (int) rint(sec), tm->tm_year, CTZName);
18571839
#endif
18581840
sprintf( str, "%3s %3s %02d %02d:%02d:%5.2f %04d %s", dabbrev,
1859-
mabbrev, tm->tm_mday, tm->tm_hour, tm->tm_min, sec, tm->tm_year, tzname[0]);
1841+
mabbrev, tm->tm_mday, tm->tm_hour, tm->tm_min, sec, tm->tm_year, CTZName);
18601842
/* XXX brute-force fill in leading zero on seconds */
18611843
if (*(str+17) == ' ') *(str+17) = '0';
18621844

src/backend/utils/adt/nabstime.c

Lines changed: 34 additions & 29 deletions
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.14 1997/03/14 23:20:31 scrappy Exp $
10+
* $Header: /cvsroot/pgsql/src/backend/utils/adt/nabstime.c,v 1.15 1997/03/18 16:35:20 scrappy Exp $
1111
*
1212
*-------------------------------------------------------------------------
1313
*/
@@ -17,60 +17,65 @@
1717
#include <sys/types.h>
1818

1919
#include "postgres.h"
20+
#include <miscadmin.h>
2021
#ifndef USE_POSIX_TIME
2122
#include <sys/timeb.h>
2223
#endif
2324
#include "access/xact.h"
2425

25-
#if USE_EURODATES
26-
extern int EuroDates;
27-
#endif
28-
29-
#if FALSE
30-
#define MAXDATELEN 47
31-
#define MAXDATEFIELDS 25
32-
#endif
3326

3427
#define MIN_DAYNUM -24856 /* December 13, 1901 */
3528
#define MAX_DAYNUM 24854 /* January 18, 2038 */
3629

3730

38-
/*
39-
* parse and convert absolute date in timestr (the normal interface)
31+
/* GetCurrentAbsoluteTime()
32+
* Get the current system time. Set timezone parameters if not specified elsewhere.
33+
* Define HasTZSet to allow clients to specify the default timezone.
4034
*
4135
* Returns the number of seconds since epoch (January 1 1970 GMT)
4236
*/
4337

44-
#ifndef USE_POSIX_TIME
45-
long int timezone;
46-
long int daylight;
47-
#endif
48-
4938
AbsoluteTime
5039
GetCurrentAbsoluteTime(void)
5140
{
5241
time_t now;
5342

5443
#ifdef USE_POSIX_TIME
5544
now = time(NULL);
45+
#else /* ! USE_POSIX_TIME */
46+
struct timeb tbnow; /* the old V7-ism */
47+
48+
(void) ftime(&tbnow);
49+
now = tbnow.time;
50+
#endif
5651

52+
if (! HasCTZSet) {
53+
#ifdef USE_POSIX_TIME
5754
#if defined(HAVE_TZSET) && defined(HAVE_INT_TIMEZONE)
58-
tzset();
55+
tzset();
56+
CTimeZone = timezone;
57+
CDayLight = daylight;
58+
strcpy( CTZName, tzname[0]);
5959
#else /* !HAVE_TZSET */
60-
struct tm *tmnow = localtime(&now);
60+
struct tm *tmnow = localtime(&now);
6161

62-
timezone = - tmnow->tm_gmtoff; /* tm_gmtoff is Sun/DEC-ism */
63-
daylight = (tmnow->tm_isdst > 0);
62+
CTimeZone = - tmnow->tm_gmtoff; /* tm_gmtoff is Sun/DEC-ism */
63+
CDayLight = (tmnow->tm_isdst > 0);
64+
/* XXX is there a better way to get local timezone string in V7? - tgl 97/03/18 */
65+
strftime( CTZName, "%Z", localtime(&now));
6466
#endif
65-
6667
#else /* ! USE_POSIX_TIME */
67-
struct timeb tbnow; /* the old V7-ism */
68-
69-
(void) ftime(&tbnow);
70-
now = tbnow.time;
71-
timezone = tbnow.timezone * 60;
72-
daylight = (tbnow.dstflag != 0);
68+
CTimeZone = tbnow.timezone * 60;
69+
CDayLight = (tbnow.dstflag != 0);
70+
/* XXX does this work to get the local timezone string in V7? - tgl 97/03/18 */
71+
strftime( CTZName, "%Z", localtime(&now));
7372
#endif
73+
};
74+
75+
#ifdef DATEDEBUG
76+
printf( "GetCurrentAbsoluteTime- timezone is %s -> %d seconds from UTC\n",
77+
CTZName, CTimeZone);
78+
#endif
7479

7580
return((AbsoluteTime) now);
7681
} /* GetCurrentAbsoluteTime() */
@@ -157,7 +162,7 @@ printf( "nabstimein- %d fields are type %d (DTK_DATE=%d)\n", nf, dtype, DTK_DATE
157162

158163
/* daylight correction */
159164
if (tm->tm_isdst < 0) { /* unknown; find out */
160-
tm->tm_isdst = (daylight > 0);
165+
tm->tm_isdst = (CDayLight > 0);
161166
};
162167
if (tm->tm_isdst > 0)
163168
sec -= 60*60;
@@ -298,7 +303,7 @@ qmktime(struct tm *tm)
298303

299304
/* daylight correction */
300305
if (tm->tm_isdst < 0) { /* unknown; find out */
301-
tm->tm_isdst = (daylight > 0);
306+
tm->tm_isdst = (CDayLight > 0);
302307
};
303308
if (tm->tm_isdst > 0)
304309
sec -= 60*60;

src/backend/utils/init/globals.c

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
*
88
*
99
* IDENTIFICATION
10-
* $Header: /cvsroot/pgsql/src/backend/utils/init/globals.c,v 1.5 1997/01/26 15:31:29 scrappy Exp $
10+
* $Header: /cvsroot/pgsql/src/backend/utils/init/globals.c,v 1.6 1997/03/18 16:35:46 scrappy Exp $
1111
*
1212
* NOTES
1313
* Globals used all over the place should be declared here and not
@@ -65,7 +65,11 @@ bool IsPostmaster = false;
6565

6666
short DebugLvl = 0;
6767

68-
int EuroDates = 0;
68+
bool EuroDates = false;
69+
bool HasCTZSet = false;
70+
bool CDayLight = false;
71+
int CTimeZone = 0;
72+
char CTZName[8] = "";
6973

7074
char *IndexedCatalogNames[] = {
7175
AttributeRelationName,

src/include/miscadmin.h

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
*
1212
* Copyright (c) 1994, Regents of the University of California
1313
*
14-
* $Id: miscadmin.h,v 1.5 1997/01/26 15:32:06 scrappy Exp $
14+
* $Id: miscadmin.h,v 1.6 1997/03/18 16:36:23 scrappy Exp $
1515
*
1616
* NOTES
1717
* some of the information in this file will be moved to
@@ -57,7 +57,18 @@ extern bool IsPostmaster;
5757

5858
extern short DebugLvl;
5959

60-
extern int EuroDates;
60+
/* Date/Time Configuration
61+
* HasCTZSet if client timezone is specified by client.
62+
* EuroDates if client prefers dates interpreted and written w/European conventions.
63+
* CTimeZone is the timezone offset in seconds.
64+
* CTZName is the timezone label.
65+
*/
66+
67+
extern bool EuroDates;
68+
extern bool HasCTZSet;
69+
extern bool CDayLight;
70+
extern int CTimeZone;
71+
extern char CTZName[];
6172

6273
extern Oid LastOidProcessed; /* for query rewrite */
6374

src/include/utils/dt.h

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
*
99
* Copyright (c) 1994, Regents of the University of California
1010
*
11-
* $Id: dt.h,v 1.1 1997/03/14 23:33:23 scrappy Exp $
11+
* $Id: dt.h,v 1.2 1997/03/18 16:36:50 scrappy Exp $
1212
*
1313
*-------------------------------------------------------------------------
1414
*/
@@ -174,8 +174,6 @@ typedef struct {
174174
char value; /* this may be unsigned, alas */
175175
} datetkn;
176176

177-
178-
extern int EuroDates;
179177
extern void GetCurrentTime(struct tm *tm);
180178

181179
/*

0 commit comments

Comments
 (0)