Commit 0a19fb42 authored by Bruce Momjian's avatar Bruce Momjian

Pgindent timezone file, per request from Tom.

parent 63bd0db1
......@@ -5,54 +5,63 @@
#define nonzero(n) (((n) == 0) ? 1 : (n))
char *imalloc(const int n)
char *
imalloc(const int n)
{
return malloc((size_t) nonzero(n));
}
char *icalloc(int nelem, int elsize)
char *
icalloc(int nelem, int elsize)
{
if (nelem == 0 || elsize == 0)
nelem = elsize = 1;
return calloc((size_t) nelem, (size_t) elsize);
}
void *irealloc(void *pointer, const int size)
void *
irealloc(void *pointer, const int size)
{
if (pointer == NULL)
return imalloc(size);
return realloc((void *) pointer, (size_t) nonzero(size));
}
char *icatalloc(char *old, const char *new)
char *
icatalloc(char *old, const char *new)
{
register char * result;
register int oldsize, newsize;
register char *result;
register int oldsize,
newsize;
newsize = (new == NULL) ? 0 : strlen(new);
if (old == NULL)
oldsize = 0;
else if (newsize == 0)
return old;
else oldsize = strlen(old);
else
oldsize = strlen(old);
if ((result = irealloc(old, oldsize + newsize + 1)) != NULL)
if (new != NULL)
(void) strcpy(result + oldsize, new);
return result;
}
char *icpyalloc(const char *string)
char *
icpyalloc(const char *string)
{
return icatalloc((char *) NULL, string);
}
void ifree(char *p)
void
ifree(char *p)
{
if (p != NULL)
(void) free(p);
}
void icfree(char *p)
void
icfree(char *p)
{
if (p != NULL)
(void) free(p);
......
This diff is collapsed.
......@@ -6,7 +6,7 @@
* Portions Copyright (c) 1996-2003, PostgreSQL Global Development Group
*
* IDENTIFICATION
* $PostgreSQL: pgsql/src/timezone/pgtz.c,v 1.10 2004/05/21 05:08:06 tgl Exp $
* $PostgreSQL: pgsql/src/timezone/pgtz.c,v 1.11 2004/05/21 12:30:25 momjian Exp $
*
*-------------------------------------------------------------------------
*/
......@@ -45,36 +45,46 @@ pg_TZDIR(void)
* set in our own library).
*/
#define T_YEAR (60*60*24*365)
#define T_MONTH (60*60*24*30)
#define T_MONTH (60*60*24*30)
struct tztry {
time_t std_t,dst_t;
char std_time[TZ_STRLEN_MAX+1],dst_time[TZ_STRLEN_MAX+1];
int std_ofs,dst_ofs;
struct tm std_tm, dst_tm;
struct tztry
{
time_t std_t,
dst_t;
char std_time[TZ_STRLEN_MAX + 1],
dst_time[TZ_STRLEN_MAX + 1];
int std_ofs,
dst_ofs;
struct tm std_tm,
dst_tm;
};
static bool compare_tm(struct tm *s, struct pg_tm *p) {
if (s->tm_sec != p->tm_sec ||
s->tm_min != p->tm_min ||
s->tm_hour != p->tm_hour ||
s->tm_mday != p->tm_mday ||
s->tm_mon != p->tm_mon ||
s->tm_year != p->tm_year ||
s->tm_wday != p->tm_wday ||
s->tm_yday != p->tm_yday ||
static bool
compare_tm(struct tm * s, struct pg_tm * p)
{
if (s->tm_sec != p->tm_sec ||
s->tm_min != p->tm_min ||
s->tm_hour != p->tm_hour ||
s->tm_mday != p->tm_mday ||
s->tm_mon != p->tm_mon ||
s->tm_year != p->tm_year ||
s->tm_wday != p->tm_wday ||
s->tm_yday != p->tm_yday ||
s->tm_isdst != p->tm_isdst)
return false;
return true;
}
static bool try_timezone(char *tzname, struct tztry *tt, bool checkdst) {
static bool
try_timezone(char *tzname, struct tztry * tt, bool checkdst)
{
struct pg_tm *pgtm;
if (!pg_tzset(tzname))
return false; /* If this timezone couldn't be picked at all */
return false; /* If this timezone couldn't be picked at
* all */
/* Verify standard time */
pgtm = pg_localtime(&(tt->std_t));
if (!pgtm)
......@@ -95,7 +105,9 @@ static bool try_timezone(char *tzname, struct tztry *tt, bool checkdst) {
return true;
}
static int get_timezone_offset(struct tm *tm) {
static int
get_timezone_offset(struct tm * tm)
{
#if defined(HAVE_STRUCT_TM_TM_ZONE)
return tm->tm_gmtoff;
#elif defined(HAVE_INT_TIMEZONE)
......@@ -113,12 +125,15 @@ static int get_timezone_offset(struct tm *tm) {
#ifdef WIN32
#define TZABBREV(tz) win32_get_timezone_abbrev(tz)
static char *win32_get_timezone_abbrev(char *tz) {
static char w32tzabbr[TZ_STRLEN_MAX+1];
int l = 0;
char *c;
static char *
win32_get_timezone_abbrev(char *tz)
{
static char w32tzabbr[TZ_STRLEN_MAX + 1];
int l = 0;
char *c;
for (c = tz; *c; c++) {
for (c = tz; *c; c++)
{
if (isupper(*c))
w32tzabbr[l++] = *c;
}
......@@ -140,47 +155,50 @@ static char *win32_get_timezone_abbrev(char *tz) {
static char *
identify_system_timezone(void)
{
static char __tzbuf[TZ_STRLEN_MAX+1];
bool std_found=false,
dst_found=false;
time_t tnow = time(NULL);
time_t t;
static char __tzbuf[TZ_STRLEN_MAX + 1];
bool std_found = false,
dst_found = false;
time_t tnow = time(NULL);
time_t t;
struct tztry tt;
char cbuf[TZ_STRLEN_MAX+1];
char cbuf[TZ_STRLEN_MAX + 1];
/* Initialize OS timezone library */
tzset();
memset(&tt, 0, sizeof(tt));
for (t = tnow; t < tnow+T_YEAR; t += T_MONTH) {
struct tm *tm = localtime(&t);
if (tm->tm_isdst == 0 && !std_found) {
for (t = tnow; t < tnow + T_YEAR; t += T_MONTH)
{
struct tm *tm = localtime(&t);
if (tm->tm_isdst == 0 && !std_found)
{
/* Standard time */
memcpy(&tt.std_tm, tm, sizeof(struct tm));
memset(cbuf,0,sizeof(cbuf));
strftime(cbuf, sizeof(cbuf)-1, "%Z", tm); /* zone abbr */
memset(cbuf, 0, sizeof(cbuf));
strftime(cbuf, sizeof(cbuf) - 1, "%Z", tm); /* zone abbr */
strcpy(tt.std_time, TZABBREV(cbuf));
tt.std_ofs = get_timezone_offset(tm);
tt.std_t = t;
std_found = true;
}
else if (tm->tm_isdst == 1 && !dst_found) {
else if (tm->tm_isdst == 1 && !dst_found)
{
/* Daylight time */
memcpy(&tt.dst_tm, tm, sizeof(struct tm));
memset(cbuf,0,sizeof(cbuf));
strftime(cbuf, sizeof(cbuf)-1, "%Z", tm); /* zone abbr */
memset(cbuf, 0, sizeof(cbuf));
strftime(cbuf, sizeof(cbuf) - 1, "%Z", tm); /* zone abbr */
strcpy(tt.dst_time, TZABBREV(cbuf));
tt.dst_ofs = get_timezone_offset(tm);
tt.dst_t = t;
dst_found = true;
}
if (std_found && dst_found)
break; /* Got both standard and daylight */
break; /* Got both standard and daylight */
}
if (!std_found)
if (!std_found)
{
/* Failed to determine TZ! */
ereport(LOG,
......@@ -189,24 +207,25 @@ identify_system_timezone(void)
return NULL; /* go to GMT */
}
if (dst_found) {
if (dst_found)
{
/* Try STD<ofs>DST */
sprintf(__tzbuf,"%s%d%s",tt.std_time,-tt.std_ofs/3600,tt.dst_time);
sprintf(__tzbuf, "%s%d%s", tt.std_time, -tt.std_ofs / 3600, tt.dst_time);
if (try_timezone(__tzbuf, &tt, dst_found))
return __tzbuf;
}
/* Try just the STD timezone */
strcpy(__tzbuf,tt.std_time);
if (try_timezone(__tzbuf, &tt, dst_found))
strcpy(__tzbuf, tt.std_time);
if (try_timezone(__tzbuf, &tt, dst_found))
return __tzbuf;
/* Did not find the timezone. Fallback to try a GMT zone. */
sprintf(__tzbuf,"Etc/GMT%s%d",
(-tt.std_ofs<0)?"+":"",tt.std_ofs/3600);
sprintf(__tzbuf, "Etc/GMT%s%d",
(-tt.std_ofs < 0) ? "+" : "", tt.std_ofs / 3600);
ereport(LOG,
(errmsg("could not recognize system timezone, defaulting to \"%s\"",
__tzbuf),
errhint("You can specify the correct timezone in postgresql.conf.")));
(errmsg("could not recognize system timezone, defaulting to \"%s\"",
__tzbuf),
errhint("You can specify the correct timezone in postgresql.conf.")));
return __tzbuf;
}
......@@ -223,7 +242,7 @@ identify_system_timezone(void)
bool
tz_acceptable(void)
{
struct pg_tm tt;
struct pg_tm tt;
time_t time2000;
/*
......@@ -255,7 +274,7 @@ tz_acceptable(void)
const char *
select_default_timezone(void)
{
char *def_tz;
char *def_tz;
def_tz = getenv("TZ");
if (def_tz && pg_tzset(def_tz) && tz_acceptable())
......@@ -280,9 +299,12 @@ select_default_timezone(void)
* This is called after initial loading of postgresql.conf. If no TimeZone
* setting was found therein, we try to derive one from the environment.
*/
void pg_timezone_initialize(void) {
void
pg_timezone_initialize(void)
{
/* Do we need to try to figure the timezone? */
if (strcmp(GetConfigOption("timezone"), "UNKNOWN") == 0) {
if (strcmp(GetConfigOption("timezone"), "UNKNOWN") == 0)
{
const char *def_tz;
/* Select setting */
......
......@@ -9,7 +9,7 @@
* Portions Copyright (c) 1996-2003, PostgreSQL Global Development Group
*
* IDENTIFICATION
* $PostgreSQL: pgsql/src/timezone/pgtz.h,v 1.7 2004/05/21 05:08:06 tgl Exp $
* $PostgreSQL: pgsql/src/timezone/pgtz.h,v 1.8 2004/05/21 12:30:25 momjian Exp $
*
*-------------------------------------------------------------------------
*/
......@@ -18,6 +18,6 @@
#define TZ_STRLEN_MAX 255
extern char *pg_TZDIR(void);
extern char *pg_TZDIR(void);
#endif /* _PGTZ_H */
#endif /* _PGTZ_H */
......@@ -14,19 +14,19 @@
** Thank you!
*/
#include <limits.h> /* for CHAR_BIT */
#include <sys/wait.h> /* for WIFEXITED and WEXITSTATUS */
#include <unistd.h> /* for F_OK and R_OK */
#include <limits.h> /* for CHAR_BIT */
#include <sys/wait.h> /* for WIFEXITED and WEXITSTATUS */
#include <unistd.h> /* for F_OK and R_OK */
#include "pgtime.h"
#ifndef WIFEXITED
#define WIFEXITED(status) (((status) & 0xff) == 0)
#endif /* !defined WIFEXITED */
#endif /* !defined WIFEXITED */
#ifndef WEXITSTATUS
#define WEXITSTATUS(status) (((status) >> 8) & 0xff)
#endif /* !defined WEXITSTATUS */
#define WEXITSTATUS(status) (((status) >> 8) & 0xff)
#endif /* !defined WEXITSTATUS */
/* Unlike <ctype.h>'s isdigit, this also works if c < 0 | c > UCHAR_MAX. */
#define is_digit(c) ((unsigned)(c) - '0' <= 9)
......@@ -37,7 +37,7 @@
#ifndef EXIT_SUCCESS
#define EXIT_SUCCESS 0
#endif /* !defined EXIT_SUCCESS */
#endif /* !defined EXIT_SUCCESS */
/*
** SunOS 4.1.1 headers lack EXIT_FAILURE.
......@@ -45,28 +45,29 @@
#ifndef EXIT_FAILURE
#define EXIT_FAILURE 1
#endif /* !defined EXIT_FAILURE */
#endif /* !defined EXIT_FAILURE */
/*
** SunOS 4.1.1 libraries lack remove.
*/
#ifndef remove
extern int unlink (const char * filename);
extern int unlink(const char *filename);
#define remove unlink
#endif /* !defined remove */
#endif /* !defined remove */
/*
* Private function declarations.
*/
extern char *icalloc (int nelem, int elsize);
extern char *icatalloc (char *old, const char *new);
extern char *icpyalloc (const char *string);
extern char *imalloc (int n);
extern void *irealloc (void *pointer, int size);
extern void icfree (char *pointer);
extern void ifree (char *pointer);
extern char *scheck (const char *string, const char *format);
extern char *icalloc(int nelem, int elsize);
extern char *icatalloc(char *old, const char *new);
extern char *icpyalloc(const char *string);
extern char *imalloc(int n);
extern void *irealloc(void *pointer, int size);
extern void icfree(char *pointer);
extern void ifree(char *pointer);
extern char *scheck(const char *string, const char *format);
/*
......@@ -75,19 +76,19 @@ extern char *scheck (const char *string, const char *format);
#ifndef TRUE
#define TRUE 1
#endif /* !defined TRUE */
#endif /* !defined TRUE */
#ifndef FALSE
#define FALSE 0
#endif /* !defined FALSE */
#endif /* !defined FALSE */
#ifndef TYPE_BIT
#define TYPE_BIT(type) (sizeof (type) * CHAR_BIT)
#endif /* !defined TYPE_BIT */
#endif /* !defined TYPE_BIT */
#ifndef TYPE_SIGNED
#define TYPE_SIGNED(type) (((type) -1) < 0)
#endif /* !defined TYPE_SIGNED */
#endif /* !defined TYPE_SIGNED */
#ifndef INT_STRLEN_MAXIMUM
/*
......@@ -97,8 +98,8 @@ extern char *scheck (const char *string, const char *format);
** add one more for a minus sign if the type is signed.
*/
#define INT_STRLEN_MAXIMUM(type) \
((TYPE_BIT(type) - TYPE_SIGNED(type)) * 302 / 1000 + 1 + TYPE_SIGNED(type))
#endif /* !defined INT_STRLEN_MAXIMUM */
((TYPE_BIT(type) - TYPE_SIGNED(type)) * 302 / 1000 + 1 + TYPE_SIGNED(type))
#endif /* !defined INT_STRLEN_MAXIMUM */
#define _(msgid) (msgid)
......@@ -106,4 +107,4 @@ extern char *scheck (const char *string, const char *format);
** UNIX was a registered trademark of The Open Group in 2003.
*/
#endif /* !defined PRIVATE_H */
#endif /* !defined PRIVATE_H */
......@@ -3,15 +3,16 @@
#include "private.h"
char *scheck(const char *string, const char *format)
char *
scheck(const char *string, const char *format)
{
register char * fbuf;
register const char * fp;
register char * tp;
register int c;
register char * result;
char dummy;
static char nada;
register char *fbuf;
register const char *fp;
register char *tp;
register int c;
register char *result;
char dummy;
static char nada;
result = &nada;
if (string == NULL || format == NULL)
......@@ -21,10 +22,12 @@ char *scheck(const char *string, const char *format)
return result;
fp = format;
tp = fbuf;
while ((*tp++ = c = *fp++) != '\0') {
while ((*tp++ = c = *fp++) != '\0')
{
if (c != '%')
continue;
if (*fp == '%') {
if (*fp == '%')
{
*tp++ = *fp++;
continue;
}
......@@ -36,8 +39,9 @@ char *scheck(const char *string, const char *format)
if (*fp == 'l' || *fp == 'h')
*tp++ = *fp++;
else if (*fp == '[')
do *tp++ = *fp++;
while (*fp != '\0' && *fp != ']');
do
*tp++ = *fp++;
while (*fp != '\0' && *fp != ']');
if ((*tp++ = *fp++) == '\0')
break;
}
......
This diff is collapsed.
......@@ -26,17 +26,20 @@
** Each file begins with. . .
*/
#define TZ_MAGIC "TZif"
struct tzhead {
char tzh_magic[4]; /* TZ_MAGIC */
char tzh_reserved[16]; /* reserved for future use */
char tzh_ttisgmtcnt[4]; /* coded number of trans. time flags */
char tzh_ttisstdcnt[4]; /* coded number of trans. time flags */
char tzh_leapcnt[4]; /* coded number of leap seconds */
char tzh_timecnt[4]; /* coded number of transition times */
char tzh_typecnt[4]; /* coded number of local time types */
char tzh_charcnt[4]; /* coded number of abbr. chars */
#define TZ_MAGIC "TZif"
struct tzhead
{
char tzh_magic[4]; /* TZ_MAGIC */
char tzh_reserved[16]; /* reserved for future use */
char tzh_ttisgmtcnt[4]; /* coded number of trans. time
* flags */
char tzh_ttisstdcnt[4]; /* coded number of trans. time
* flags */
char tzh_leapcnt[4]; /* coded number of leap seconds */
char tzh_timecnt[4]; /* coded number of transition times */
char tzh_typecnt[4]; /* coded number of local time types */
char tzh_charcnt[4]; /* coded number of abbr. chars */
};
/*
......@@ -46,8 +49,8 @@ struct tzhead {
** tzh_timecnt (unsigned char)s types of local time starting at above
** tzh_typecnt repetitions of
** one (char [4]) coded UTC offset in seconds
** one (unsigned char) used to set tm_isdst
** one (unsigned char) that's an abbreviation list index
** one (unsigned char) used to set tm_isdst
** one (unsigned char) that's an abbreviation list index
** tzh_charcnt (char)s '\0'-terminated zone abbreviations
** tzh_leapcnt repetitions of
** one (char [4]) coded leap second transition times
......@@ -77,33 +80,36 @@ struct tzhead {
*/
#define TZ_MAX_TIMES 370
#define TZ_MAX_TYPES 256 /* Limited by what (unsigned char)'s can hold */
#define TZ_MAX_TYPES 256 /* Limited by what (unsigned char)'s can
* hold */
#define TZ_MAX_CHARS 50 /* Maximum number of abbreviation characters */
/* (limited by what unsigned chars can hold) */
#define TZ_MAX_CHARS 50 /* Maximum number of abbreviation
* characters */
/* (limited by what unsigned chars can hold) */
#define TZ_MAX_LEAPS 50 /* Maximum number of leap second corrections */
#define TZ_MAX_LEAPS 50 /* Maximum number of leap second
* corrections */
#define SECSPERMIN 60
#define MINSPERHOUR 60
#define HOURSPERDAY 24
#define DAYSPERWEEK 7
#define MINSPERHOUR 60
#define HOURSPERDAY 24
#define DAYSPERWEEK 7
#define DAYSPERNYEAR 365
#define DAYSPERLYEAR 366
#define SECSPERHOUR (SECSPERMIN * MINSPERHOUR)
#define SECSPERHOUR (SECSPERMIN * MINSPERHOUR)
#define SECSPERDAY ((long) SECSPERHOUR * HOURSPERDAY)
#define MONSPERYEAR 12
#define MONSPERYEAR 12
#define TM_SUNDAY 0
#define TM_MONDAY 1
#define TM_TUESDAY 2
#define TM_WEDNESDAY 3
#define TM_THURSDAY 4
#define TM_THURSDAY 4
#define TM_FRIDAY 5
#define TM_SATURDAY 6
#define TM_SATURDAY 6
#define TM_JANUARY 0
#define TM_FEBRUARY 1
#define TM_FEBRUARY 1
#define TM_MARCH 2
#define TM_APRIL 3
#define TM_MAY 4
......@@ -112,8 +118,8 @@ struct tzhead {
#define TM_AUGUST 7
#define TM_SEPTEMBER 8
#define TM_OCTOBER 9
#define TM_NOVEMBER 10
#define TM_DECEMBER 11
#define TM_NOVEMBER 10
#define TM_DECEMBER 11
#define TM_YEAR_BASE 1900
......@@ -127,4 +133,4 @@ struct tzhead {
#define isleap(y) (((y) % 4) == 0 && (((y) % 100) != 0 || ((y) % 400) == 0))
#endif /* !defined TZFILE_H */
#endif /* !defined TZFILE_H */
This diff is collapsed.
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment