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

Pgindent timezone file, per request from Tom.

parent 63bd0db1
...@@ -5,54 +5,63 @@ ...@@ -5,54 +5,63 @@
#define nonzero(n) (((n) == 0) ? 1 : (n)) #define nonzero(n) (((n) == 0) ? 1 : (n))
char *imalloc(const int n) char *
imalloc(const int n)
{ {
return malloc((size_t) nonzero(n)); return malloc((size_t) nonzero(n));
} }
char *icalloc(int nelem, int elsize) char *
icalloc(int nelem, int elsize)
{ {
if (nelem == 0 || elsize == 0) if (nelem == 0 || elsize == 0)
nelem = elsize = 1; nelem = elsize = 1;
return calloc((size_t) nelem, (size_t) elsize); 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) if (pointer == NULL)
return imalloc(size); return imalloc(size);
return realloc((void *) pointer, (size_t) nonzero(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 char *result;
register int oldsize, newsize; register int oldsize,
newsize;
newsize = (new == NULL) ? 0 : strlen(new); newsize = (new == NULL) ? 0 : strlen(new);
if (old == NULL) if (old == NULL)
oldsize = 0; oldsize = 0;
else if (newsize == 0) else if (newsize == 0)
return old; return old;
else oldsize = strlen(old); else
oldsize = strlen(old);
if ((result = irealloc(old, oldsize + newsize + 1)) != NULL) if ((result = irealloc(old, oldsize + newsize + 1)) != NULL)
if (new != NULL) if (new != NULL)
(void) strcpy(result + oldsize, new); (void) strcpy(result + oldsize, new);
return result; return result;
} }
char *icpyalloc(const char *string) char *
icpyalloc(const char *string)
{ {
return icatalloc((char *) NULL, string); return icatalloc((char *) NULL, string);
} }
void ifree(char *p) void
ifree(char *p)
{ {
if (p != NULL) if (p != NULL)
(void) free(p); (void) free(p);
} }
void icfree(char *p) void
icfree(char *p)
{ {
if (p != NULL) if (p != NULL)
(void) free(p); (void) free(p);
......
This diff is collapsed.
...@@ -6,7 +6,7 @@ ...@@ -6,7 +6,7 @@
* Portions Copyright (c) 1996-2003, PostgreSQL Global Development Group * Portions Copyright (c) 1996-2003, PostgreSQL Global Development Group
* *
* IDENTIFICATION * 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 $
* *
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
*/ */
...@@ -47,15 +47,22 @@ pg_TZDIR(void) ...@@ -47,15 +47,22 @@ pg_TZDIR(void)
#define T_YEAR (60*60*24*365) #define T_YEAR (60*60*24*365)
#define T_MONTH (60*60*24*30) #define T_MONTH (60*60*24*30)
struct tztry { struct tztry
time_t std_t,dst_t; {
char std_time[TZ_STRLEN_MAX+1],dst_time[TZ_STRLEN_MAX+1]; time_t std_t,
int std_ofs,dst_ofs; dst_t;
struct tm std_tm, dst_tm; 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) { static bool
compare_tm(struct tm * s, struct pg_tm * p)
{
if (s->tm_sec != p->tm_sec || if (s->tm_sec != p->tm_sec ||
s->tm_min != p->tm_min || s->tm_min != p->tm_min ||
s->tm_hour != p->tm_hour || s->tm_hour != p->tm_hour ||
...@@ -69,11 +76,14 @@ static bool compare_tm(struct tm *s, struct pg_tm *p) { ...@@ -69,11 +76,14 @@ static bool compare_tm(struct tm *s, struct pg_tm *p) {
return true; 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; struct pg_tm *pgtm;
if (!pg_tzset(tzname)) 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 */ /* Verify standard time */
pgtm = pg_localtime(&(tt->std_t)); pgtm = pg_localtime(&(tt->std_t));
...@@ -95,7 +105,9 @@ static bool try_timezone(char *tzname, struct tztry *tt, bool checkdst) { ...@@ -95,7 +105,9 @@ static bool try_timezone(char *tzname, struct tztry *tt, bool checkdst) {
return true; 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) #if defined(HAVE_STRUCT_TM_TM_ZONE)
return tm->tm_gmtoff; return tm->tm_gmtoff;
#elif defined(HAVE_INT_TIMEZONE) #elif defined(HAVE_INT_TIMEZONE)
...@@ -113,12 +125,15 @@ static int get_timezone_offset(struct tm *tm) { ...@@ -113,12 +125,15 @@ static int get_timezone_offset(struct tm *tm) {
#ifdef WIN32 #ifdef WIN32
#define TZABBREV(tz) win32_get_timezone_abbrev(tz) #define TZABBREV(tz) win32_get_timezone_abbrev(tz)
static char *win32_get_timezone_abbrev(char *tz) { static char *
static char w32tzabbr[TZ_STRLEN_MAX+1]; win32_get_timezone_abbrev(char *tz)
{
static char w32tzabbr[TZ_STRLEN_MAX + 1];
int l = 0; int l = 0;
char *c; char *c;
for (c = tz; *c; c++) { for (c = tz; *c; c++)
{
if (isupper(*c)) if (isupper(*c))
w32tzabbr[l++] = *c; w32tzabbr[l++] = *c;
} }
...@@ -140,37 +155,40 @@ static char *win32_get_timezone_abbrev(char *tz) { ...@@ -140,37 +155,40 @@ static char *win32_get_timezone_abbrev(char *tz) {
static char * static char *
identify_system_timezone(void) identify_system_timezone(void)
{ {
static char __tzbuf[TZ_STRLEN_MAX+1]; static char __tzbuf[TZ_STRLEN_MAX + 1];
bool std_found=false, bool std_found = false,
dst_found=false; dst_found = false;
time_t tnow = time(NULL); time_t tnow = time(NULL);
time_t t; time_t t;
struct tztry tt; struct tztry tt;
char cbuf[TZ_STRLEN_MAX+1]; char cbuf[TZ_STRLEN_MAX + 1];
/* Initialize OS timezone library */ /* Initialize OS timezone library */
tzset(); tzset();
memset(&tt, 0, sizeof(tt)); memset(&tt, 0, sizeof(tt));
for (t = tnow; t < tnow+T_YEAR; t += T_MONTH) { for (t = tnow; t < tnow + T_YEAR; t += T_MONTH)
{
struct tm *tm = localtime(&t); struct tm *tm = localtime(&t);
if (tm->tm_isdst == 0 && !std_found) { if (tm->tm_isdst == 0 && !std_found)
{
/* Standard time */ /* Standard time */
memcpy(&tt.std_tm, tm, sizeof(struct tm)); memcpy(&tt.std_tm, tm, sizeof(struct tm));
memset(cbuf,0,sizeof(cbuf)); memset(cbuf, 0, sizeof(cbuf));
strftime(cbuf, sizeof(cbuf)-1, "%Z", tm); /* zone abbr */ strftime(cbuf, sizeof(cbuf) - 1, "%Z", tm); /* zone abbr */
strcpy(tt.std_time, TZABBREV(cbuf)); strcpy(tt.std_time, TZABBREV(cbuf));
tt.std_ofs = get_timezone_offset(tm); tt.std_ofs = get_timezone_offset(tm);
tt.std_t = t; tt.std_t = t;
std_found = true; std_found = true;
} }
else if (tm->tm_isdst == 1 && !dst_found) { else if (tm->tm_isdst == 1 && !dst_found)
{
/* Daylight time */ /* Daylight time */
memcpy(&tt.dst_tm, tm, sizeof(struct tm)); memcpy(&tt.dst_tm, tm, sizeof(struct tm));
memset(cbuf,0,sizeof(cbuf)); memset(cbuf, 0, sizeof(cbuf));
strftime(cbuf, sizeof(cbuf)-1, "%Z", tm); /* zone abbr */ strftime(cbuf, sizeof(cbuf) - 1, "%Z", tm); /* zone abbr */
strcpy(tt.dst_time, TZABBREV(cbuf)); strcpy(tt.dst_time, TZABBREV(cbuf));
tt.dst_ofs = get_timezone_offset(tm); tt.dst_ofs = get_timezone_offset(tm);
tt.dst_t = t; tt.dst_t = t;
...@@ -189,20 +207,21 @@ identify_system_timezone(void) ...@@ -189,20 +207,21 @@ identify_system_timezone(void)
return NULL; /* go to GMT */ return NULL; /* go to GMT */
} }
if (dst_found) { if (dst_found)
{
/* Try STD<ofs>DST */ /* 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)) if (try_timezone(__tzbuf, &tt, dst_found))
return __tzbuf; return __tzbuf;
} }
/* Try just the STD timezone */ /* Try just the STD timezone */
strcpy(__tzbuf,tt.std_time); strcpy(__tzbuf, tt.std_time);
if (try_timezone(__tzbuf, &tt, dst_found)) if (try_timezone(__tzbuf, &tt, dst_found))
return __tzbuf; return __tzbuf;
/* Did not find the timezone. Fallback to try a GMT zone. */ /* Did not find the timezone. Fallback to try a GMT zone. */
sprintf(__tzbuf,"Etc/GMT%s%d", sprintf(__tzbuf, "Etc/GMT%s%d",
(-tt.std_ofs<0)?"+":"",tt.std_ofs/3600); (-tt.std_ofs < 0) ? "+" : "", tt.std_ofs / 3600);
ereport(LOG, ereport(LOG,
(errmsg("could not recognize system timezone, defaulting to \"%s\"", (errmsg("could not recognize system timezone, defaulting to \"%s\"",
__tzbuf), __tzbuf),
...@@ -280,9 +299,12 @@ select_default_timezone(void) ...@@ -280,9 +299,12 @@ select_default_timezone(void)
* This is called after initial loading of postgresql.conf. If no TimeZone * This is called after initial loading of postgresql.conf. If no TimeZone
* setting was found therein, we try to derive one from the environment. * 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? */ /* 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; const char *def_tz;
/* Select setting */ /* Select setting */
......
...@@ -9,7 +9,7 @@ ...@@ -9,7 +9,7 @@
* Portions Copyright (c) 1996-2003, PostgreSQL Global Development Group * Portions Copyright (c) 1996-2003, PostgreSQL Global Development Group
* *
* IDENTIFICATION * 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 $
* *
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
*/ */
......
...@@ -52,21 +52,22 @@ ...@@ -52,21 +52,22 @@
*/ */
#ifndef remove #ifndef remove
extern int unlink (const char * filename); extern int unlink(const char *filename);
#define remove unlink #define remove unlink
#endif /* !defined remove */ #endif /* !defined remove */
/* /*
* Private function declarations. * Private function declarations.
*/ */
extern char *icalloc (int nelem, int elsize); extern char *icalloc(int nelem, int elsize);
extern char *icatalloc (char *old, const char *new); extern char *icatalloc(char *old, const char *new);
extern char *icpyalloc (const char *string); extern char *icpyalloc(const char *string);
extern char *imalloc (int n); extern char *imalloc(int n);
extern void *irealloc (void *pointer, int size); extern void *irealloc(void *pointer, int size);
extern void icfree (char *pointer); extern void icfree(char *pointer);
extern void ifree (char *pointer); extern void ifree(char *pointer);
extern char *scheck (const char *string, const char *format); extern char *scheck(const char *string, const char *format);
/* /*
......
...@@ -3,13 +3,14 @@ ...@@ -3,13 +3,14 @@
#include "private.h" #include "private.h"
char *scheck(const char *string, const char *format) char *
scheck(const char *string, const char *format)
{ {
register char * fbuf; register char *fbuf;
register const char * fp; register const char *fp;
register char * tp; register char *tp;
register int c; register int c;
register char * result; register char *result;
char dummy; char dummy;
static char nada; static char nada;
...@@ -21,10 +22,12 @@ char *scheck(const char *string, const char *format) ...@@ -21,10 +22,12 @@ char *scheck(const char *string, const char *format)
return result; return result;
fp = format; fp = format;
tp = fbuf; tp = fbuf;
while ((*tp++ = c = *fp++) != '\0') { while ((*tp++ = c = *fp++) != '\0')
{
if (c != '%') if (c != '%')
continue; continue;
if (*fp == '%') { if (*fp == '%')
{
*tp++ = *fp++; *tp++ = *fp++;
continue; continue;
} }
...@@ -36,7 +39,8 @@ char *scheck(const char *string, const char *format) ...@@ -36,7 +39,8 @@ char *scheck(const char *string, const char *format)
if (*fp == 'l' || *fp == 'h') if (*fp == 'l' || *fp == 'h')
*tp++ = *fp++; *tp++ = *fp++;
else if (*fp == '[') else if (*fp == '[')
do *tp++ = *fp++; do
*tp++ = *fp++;
while (*fp != '\0' && *fp != ']'); while (*fp != '\0' && *fp != ']');
if ((*tp++ = *fp++) == '\0') if ((*tp++ = *fp++) == '\0')
break; break;
......
...@@ -25,17 +25,18 @@ ...@@ -25,17 +25,18 @@
#include "tzfile.h" #include "tzfile.h"
struct lc_time_T { struct lc_time_T
const char * mon[MONSPERYEAR]; {
const char * month[MONSPERYEAR]; const char *mon[MONSPERYEAR];
const char * wday[DAYSPERWEEK]; const char *month[MONSPERYEAR];
const char * weekday[DAYSPERWEEK]; const char *wday[DAYSPERWEEK];
const char * X_fmt; const char *weekday[DAYSPERWEEK];
const char * x_fmt; const char *X_fmt;
const char * c_fmt; const char *x_fmt;
const char * am; const char *c_fmt;
const char * pm; const char *am;
const char * date_fmt; const char *pm;
const char *date_fmt;
}; };
#define Locale (&C_time_locale) #define Locale (&C_time_locale)
...@@ -59,20 +60,15 @@ static const struct lc_time_T C_time_locale = { ...@@ -59,20 +60,15 @@ static const struct lc_time_T C_time_locale = {
"%H:%M:%S", "%H:%M:%S",
/* /*
** x_fmt * * x_fmt * C99 requires this format. * Using just numbers (as here)
** C99 requires this format. * makes Quakers happier; * it's also compatible with SVR4.
** Using just numbers (as here) makes Quakers happier;
** it's also compatible with SVR4.
*/ */
"%m/%d/%y", "%m/%d/%y",
/* /*
** c_fmt * * c_fmt * C99 requires this format. * Previously this code used "%D
** C99 requires this format. * %X", but we now conform to C99. * Note that * "%a %b %d
** Previously this code used "%D %X", but we now conform to C99. * %H:%M:%S %Y" * is used by Solaris 2.3.
** Note that
** "%a %b %d %H:%M:%S %Y"
** is used by Solaris 2.3.
*/ */
"%a %b %e %T %Y", "%a %b %e %T %Y",
...@@ -86,9 +82,9 @@ static const struct lc_time_T C_time_locale = { ...@@ -86,9 +82,9 @@ static const struct lc_time_T C_time_locale = {
"%a %b %e %H:%M:%S %Z %Y" "%a %b %e %H:%M:%S %Z %Y"
}; };
static char * _add (const char *, char *, const char *); static char *_add(const char *, char *, const char *);
static char * _conv (int, const char *, char *, const char *); static char *_conv(int, const char *, char *, const char *);
static char * _fmt (const char *, const struct pg_tm *, char *, const char *, int *); static char *_fmt(const char *, const struct pg_tm *, char *, const char *, int *);
#define IN_NONE 0 #define IN_NONE 0
#define IN_SOME 1 #define IN_SOME 1
...@@ -96,9 +92,10 @@ static char * _fmt (const char *, const struct pg_tm *, char *, const char *, in ...@@ -96,9 +92,10 @@ static char * _fmt (const char *, const struct pg_tm *, char *, const char *, in
#define IN_ALL 3 #define IN_ALL 3
size_t pg_strftime(char *s, size_t maxsize, const char *format, const struct pg_tm *t) size_t
pg_strftime(char *s, size_t maxsize, const char *format, const struct pg_tm * t)
{ {
char * p; char *p;
int warn; int warn;
warn = IN_NONE; warn = IN_NONE;
...@@ -109,12 +106,16 @@ size_t pg_strftime(char *s, size_t maxsize, const char *format, const struct pg_ ...@@ -109,12 +106,16 @@ size_t pg_strftime(char *s, size_t maxsize, const char *format, const struct pg_
return p - s; return p - s;
} }
static char * _fmt(const char *format, const struct pg_tm *t, char *pt, const char *ptlim, int *warnp) static char *
_fmt(const char *format, const struct pg_tm * t, char *pt, const char *ptlim, int *warnp)
{ {
for ( ; *format; ++format) { for (; *format; ++format)
if (*format == '%') { {
label: if (*format == '%')
switch (*++format) { {
label:
switch (*++format)
{
case '\0': case '\0':
--format; --format;
break; break;
...@@ -144,12 +145,11 @@ label: ...@@ -144,12 +145,11 @@ label:
pt, ptlim); pt, ptlim);
continue; continue;
case 'C': case 'C':
/* /*
** %C used to do a... * * %C used to do a... * _fmt("%a %b %e %X %Y", t); *
** _fmt("%a %b %e %X %Y", t); * ...whereas now POSIX 1003.2 calls for * something
** ...whereas now POSIX 1003.2 calls for * completely different. * (ado, 1993-05-24)
** something completely different.
** (ado, 1993-05-24)
*/ */
pt = _conv((t->tm_year + TM_YEAR_BASE) / 100, pt = _conv((t->tm_year + TM_YEAR_BASE) / 100,
"%02d", pt, ptlim); "%02d", pt, ptlim);
...@@ -173,14 +173,12 @@ label: ...@@ -173,14 +173,12 @@ label:
continue; continue;
case 'E': case 'E':
case 'O': case 'O':
/* /*
** C99 locale modifiers. * * C99 locale modifiers. * The sequences * %Ec %EC
** The sequences * %Ex %EX %Ey %EY * %Od %oe %OH %OI %Om %OM * %OS
** %Ec %EC %Ex %EX %Ey %EY * %Ou %OU %OV %Ow %OW %Oy * are supposed to provide
** %Od %oe %OH %OI %Om %OM * alternate * representations.
** %OS %Ou %OU %OV %Ow %OW %Oy
** are supposed to provide alternate
** representations.
*/ */
goto label; goto label;
case 'e': case 'e':
...@@ -201,35 +199,34 @@ label: ...@@ -201,35 +199,34 @@ label:
pt = _conv(t->tm_yday + 1, "%03d", pt, ptlim); pt = _conv(t->tm_yday + 1, "%03d", pt, ptlim);
continue; continue;
case 'k': case 'k':
/* /*
** This used to be... * * This used to be... * _conv(t->tm_hour % 12 ? *
** _conv(t->tm_hour % 12 ? * t->tm_hour % 12 : 12, 2, ' '); * ...and has been
** t->tm_hour % 12 : 12, 2, ' '); * changed to the below to * match SunOS 4.1.1 and
** ...and has been changed to the below to * Arnold Robbins' * strftime version 3.0. That is,
** match SunOS 4.1.1 and Arnold Robbins' * "%k" and * "%l" have been swapped. * (ado,
** strftime version 3.0. That is, "%k" and * 1993-05-24)
** "%l" have been swapped.
** (ado, 1993-05-24)
*/ */
pt = _conv(t->tm_hour, "%2d", pt, ptlim); pt = _conv(t->tm_hour, "%2d", pt, ptlim);
continue; continue;
#ifdef KITCHEN_SINK #ifdef KITCHEN_SINK
case 'K': case 'K':
/* /*
** After all this time, still unclaimed! * * After all this time, still unclaimed!
*/ */
pt = _add("kitchen sink", pt, ptlim); pt = _add("kitchen sink", pt, ptlim);
continue; continue;
#endif /* defined KITCHEN_SINK */ #endif /* defined KITCHEN_SINK */
case 'l': case 'l':
/* /*
** This used to be... * * This used to be... * _conv(t->tm_hour, 2, ' '); *
** _conv(t->tm_hour, 2, ' '); * ...and has been changed to the below to * match
** ...and has been changed to the below to * SunOS 4.1.1 and Arnold Robbin's * strftime version
** match SunOS 4.1.1 and Arnold Robbin's * 3.0. That is, "%k" and * "%l" have been swapped. *
** strftime version 3.0. That is, "%k" and * (ado, 1993-05-24)
** "%l" have been swapped.
** (ado, 1993-05-24)
*/ */
pt = _conv((t->tm_hour % 12) ? pt = _conv((t->tm_hour % 12) ?
(t->tm_hour % 12) : 12, (t->tm_hour % 12) : 12,
...@@ -262,7 +259,7 @@ label: ...@@ -262,7 +259,7 @@ label:
case 's': case 's':
{ {
struct pg_tm tm; struct pg_tm tm;
char buf[INT_STRLEN_MAXIMUM(time_t) + 1]; char buf[INT_STRLEN_MAXIMUM(time_t) +1];
time_t mkt; time_t mkt;
tm = *t; tm = *t;
...@@ -286,11 +283,11 @@ label: ...@@ -286,11 +283,11 @@ label:
"%02d", pt, ptlim); "%02d", pt, ptlim);
continue; continue;
case 'u': case 'u':
/* /*
** From Arnold Robbins' strftime version 3.0: * * From Arnold Robbins' strftime version 3.0: * "ISO
** "ISO 8601: Weekday as a decimal number * 8601: Weekday as a decimal number * [1 (Monday) -
** [1 (Monday) - 7]" * 7]" * (ado, 1993-05-24)
** (ado, 1993-05-24)
*/ */
pt = _conv((t->tm_wday == 0) ? pt = _conv((t->tm_wday == 0) ?
DAYSPERWEEK : t->tm_wday, DAYSPERWEEK : t->tm_wday,
...@@ -326,7 +323,8 @@ label: ...@@ -326,7 +323,8 @@ label:
year = t->tm_year + TM_YEAR_BASE; year = t->tm_year + TM_YEAR_BASE;
yday = t->tm_yday; yday = t->tm_yday;
wday = t->tm_wday; wday = t->tm_wday;
for ( ; ; ) { for (;;)
{
int len; int len;
int bot; int bot;
int top; int top;
...@@ -334,27 +332,31 @@ label: ...@@ -334,27 +332,31 @@ label:
len = isleap(year) ? len = isleap(year) ?
DAYSPERLYEAR : DAYSPERLYEAR :
DAYSPERNYEAR; DAYSPERNYEAR;
/* /*
** What yday (-3 ... 3) does * * What yday (-3 ... 3) does * the ISO year
** the ISO year begin on? * begin on?
*/ */
bot = ((yday + 11 - wday) % bot = ((yday + 11 - wday) %
DAYSPERWEEK) - 3; DAYSPERWEEK) - 3;
/* /*
** What yday does the NEXT * * What yday does the NEXT * ISO year begin
** ISO year begin on? * on?
*/ */
top = bot - top = bot -
(len % DAYSPERWEEK); (len % DAYSPERWEEK);
if (top < -3) if (top < -3)
top += DAYSPERWEEK; top += DAYSPERWEEK;
top += len; top += len;
if (yday >= top) { if (yday >= top)
{
++year; ++year;
w = 1; w = 1;
break; break;
} }
if (yday >= bot) { if (yday >= bot)
{
w = 1 + ((yday - bot) / w = 1 + ((yday - bot) /
DAYSPERWEEK); DAYSPERWEEK);
break; break;
...@@ -367,19 +369,22 @@ label: ...@@ -367,19 +369,22 @@ label:
if (*format == 'V') if (*format == 'V')
pt = _conv(w, "%02d", pt = _conv(w, "%02d",
pt, ptlim); pt, ptlim);
else if (*format == 'g') { else if (*format == 'g')
{
*warnp = IN_ALL; *warnp = IN_ALL;
pt = _conv(year % 100, "%02d", pt = _conv(year % 100, "%02d",
pt, ptlim); pt, ptlim);
} else pt = _conv(year, "%04d", }
else
pt = _conv(year, "%04d",
pt, ptlim); pt, ptlim);
} }
continue; continue;
case 'v': case 'v':
/* /*
** From Arnold Robbins' strftime version 3.0: * * From Arnold Robbins' strftime version 3.0: *
** "date as dd-bbb-YYYY" * "date as dd-bbb-YYYY" * (ado, 1993-05-24)
** (ado, 1993-05-24)
*/ */
pt = _fmt("%e-%b-%Y", t, pt, ptlim, warnp); pt = _fmt("%e-%b-%Y", t, pt, ptlim, warnp);
continue; continue;
...@@ -419,27 +424,30 @@ label: ...@@ -419,27 +424,30 @@ label:
case 'Z': case 'Z':
if (t->tm_zone != NULL) if (t->tm_zone != NULL)
pt = _add(t->tm_zone, pt, ptlim); pt = _add(t->tm_zone, pt, ptlim);
/* /*
** C99 says that %Z must be replaced by the * * C99 says that %Z must be replaced by the * empty
** empty string if the time zone is not * string if the time zone is not * determinable.
** determinable.
*/ */
continue; continue;
case 'z': case 'z':
{ {
int diff; int diff;
char const * sign; char const *sign;
if (t->tm_isdst < 0) if (t->tm_isdst < 0)
continue; continue;
diff = t->tm_gmtoff; diff = t->tm_gmtoff;
if (diff < 0) { if (diff < 0)
{
sign = "-"; sign = "-";
diff = -diff; diff = -diff;
} else sign = "+"; }
else
sign = "+";
pt = _add(sign, pt, ptlim); pt = _add(sign, pt, ptlim);
diff /= 60; diff /= 60;
pt = _conv((diff/60)*100 + diff%60, pt = _conv((diff / 60) * 100 + diff % 60,
"%04d", pt, ptlim); "%04d", pt, ptlim);
} }
continue; continue;
...@@ -448,10 +456,11 @@ label: ...@@ -448,10 +456,11 @@ label:
warnp); warnp);
continue; continue;
case '%': case '%':
/* /*
** X311J/88-090 (4.12.3.5): if conversion char is * * X311J/88-090 (4.12.3.5): if conversion char is *
** undefined, behavior is undefined. Print out the * undefined, behavior is undefined. Print out the *
** character itself as printf(3) also does. * character itself as printf(3) also does.
*/ */
default: default:
break; break;
...@@ -464,15 +473,17 @@ label: ...@@ -464,15 +473,17 @@ label:
return pt; return pt;
} }
static char * _conv(const int n, const char *format, char *pt, const char *ptlim) static char *
_conv(const int n, const char *format, char *pt, const char *ptlim)
{ {
char buf[INT_STRLEN_MAXIMUM(int) + 1]; char buf[INT_STRLEN_MAXIMUM(int) +1];
(void) sprintf(buf, format, n); (void) sprintf(buf, format, n);
return _add(buf, pt, ptlim); return _add(buf, pt, ptlim);
} }
static char *_add(const char *str, char *pt, const char *ptlim) static char *
_add(const char *str, char *pt, const char *ptlim)
{ {
while (pt < ptlim && (*pt = *str++) != '\0') while (pt < ptlim && (*pt = *str++) != '\0')
++pt; ++pt;
......
...@@ -28,11 +28,14 @@ ...@@ -28,11 +28,14 @@
#define TZ_MAGIC "TZif" #define TZ_MAGIC "TZif"
struct tzhead { struct tzhead
{
char tzh_magic[4]; /* TZ_MAGIC */ char tzh_magic[4]; /* TZ_MAGIC */
char tzh_reserved[16]; /* reserved for future use */ char tzh_reserved[16]; /* reserved for future use */
char tzh_ttisgmtcnt[4]; /* coded number of trans. time flags */ char tzh_ttisgmtcnt[4]; /* coded number of trans. time
char tzh_ttisstdcnt[4]; /* coded number of trans. time flags */ * flags */
char tzh_ttisstdcnt[4]; /* coded number of trans. time
* flags */
char tzh_leapcnt[4]; /* coded number of leap seconds */ char tzh_leapcnt[4]; /* coded number of leap seconds */
char tzh_timecnt[4]; /* coded number of transition times */ char tzh_timecnt[4]; /* coded number of transition times */
char tzh_typecnt[4]; /* coded number of local time types */ char tzh_typecnt[4]; /* coded number of local time types */
...@@ -77,12 +80,15 @@ struct tzhead { ...@@ -77,12 +80,15 @@ struct tzhead {
*/ */
#define TZ_MAX_TIMES 370 #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 */ #define TZ_MAX_CHARS 50 /* Maximum number of abbreviation
* characters */
/* (limited by what unsigned chars can hold) */ /* (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 SECSPERMIN 60
#define MINSPERHOUR 60 #define MINSPERHOUR 60
......
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