* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
*/
-#if defined(LIBC_SCCS) && !defined(lint)
-static char sccsid[] = "@(#)ctime.c 5.23 (Berkeley) 6/22/90";
-#endif /* LIBC_SCCS and not lint */
-
/*
** Leap second handling from Bradley White (bww@k.gp.cs.cmu.edu).
** POSIX-style TZ environment variable handling from Guy Harris
** (guy@auspex.com).
*/
-
-
-
#include <msvcrt/fcntl.h>
#include <msvcrt/time.h>
#include <msvcrt/string.h>
#include "posixrul.h"
-#define P(s) s
-#define alloc_size_t size_t
-#define qsort_size_t size_t
-#define fread_size_t size_t
-#define fwrite_size_t size_t
-#define ACCESS_MODE O_RDONLY|O_BINARY
-#define OPEN_MODE O_RDONLY|O_BINARY
+#ifdef __cplusplus
+#define CPP_CONST const
+#else
+#define CPP_CONST
+#endif
+
+#define P(s) s
+#define alloc_size_t size_t
+#define qsort_size_t size_t
+#define fread_size_t size_t
+#define fwrite_size_t size_t
+
+#define ACCESS_MODE O_RDONLY|O_BINARY
+#define OPEN_MODE O_RDONLY|O_BINARY
/*
** Someone might make incorrect use of a time zone abbreviation:
-** 1. They might reference tzname[0] before calling tzset (explicitly
-** or implicitly).
-** 2. They might reference tzname[1] before calling tzset (explicitly
-** or implicitly).
-** 3. They might reference tzname[1] after setting to a time zone
-** in which Daylight Saving Time is never observed.
-** 4. They might reference tzname[0] after setting to a time zone
-** in which Standard Time is never observed.
-** 5. They might reference tm.TM_ZONE after calling offtime.
+** 1. They might reference tzname[0] before calling tzset (explicitly
+** or implicitly).
+** 2. They might reference tzname[1] before calling tzset (explicitly
+** or implicitly).
+** 3. They might reference tzname[1] after setting to a time zone
+** in which Daylight Saving Time is never observed.
+** 4. They might reference tzname[0] after setting to a time zone
+** in which Standard Time is never observed.
+** 5. They might reference tm.TM_ZONE after calling offtime.
** What's best to do in the above cases is open to debate;
** for now, we just set things up so that in any of the five cases
** WILDABBR is used. Another possibility: initialize tzname[0] to the
** manual page of what this "time zone abbreviation" means (doing this so
** that tzname[0] has the "normal" length of three characters).
*/
-int _daylight;
-int _timezone;
+
+void _set_daylight_export(int);
+void _set_timezone_export(int);
+
static char WILDABBR[] = " ";
#ifndef TRUE
-#define TRUE 1
-#define FALSE 0
+#define TRUE 1
+#define FALSE 0
#endif /* !defined TRUE */
static const char GMT[] = "GMT";
-struct ttinfo { /* time type information */
- long tt_gmtoff; /* GMT offset in seconds */
- int tt_isdst; /* used to set tm_isdst */
- int tt_abbrind; /* abbreviation list index */
- int tt_ttisstd; /* TRUE if transition is std time */
+struct ttinfo { /* time type information */
+ long tt_gmtoff; /* GMT offset in seconds */
+ int tt_isdst; /* used to set tm_isdst */
+ int tt_abbrind; /* abbreviation list index */
+ int tt_ttisstd; /* TRUE if transition is std time */
};
-struct lsinfo { /* leap second information */
- time_t ls_trans; /* transition time */
- long ls_corr; /* correction to apply */
+struct lsinfo { /* leap second information */
+ time_t ls_trans; /* transition time */
+ long ls_corr; /* correction to apply */
};
struct state {
};
struct rule {
- int r_type; /* type of rule--see below */
- int r_day; /* day number of rule */
- int r_week; /* week number of rule */
- int r_mon; /* month number of rule */
- long r_time; /* transition time of rule */
+ int r_type; /* type of rule--see below */
+ int r_day; /* day number of rule */
+ int r_week; /* week number of rule */
+ int r_mon; /* month number of rule */
+ long r_time; /* transition time of rule */
};
-#define JULIAN_DAY 0 /* Jn - Julian day */
-#define DAY_OF_YEAR 1 /* n - day of year */
-#define MONTH_NTH_DAY_OF_WEEK 2 /* Mm.n.d - month, week, day of week */
+#define JULIAN_DAY 0 /* Jn - Julian day */
+#define DAY_OF_YEAR 1 /* n - day of year */
+#define MONTH_NTH_DAY_OF_WEEK 2 /* Mm.n.d - month, week, day of week */
/*
** Prototypes for static functions.
*/
+#if 0
+static long detzcode P((const char * codep));
+static const char * getzname P((const char * strp));
+static const char * getnum P((const char * strp, int * nump, int min, int max));
+static const char * getsecs P((const char * strp, long * secsp));
+static const char * getoffset P((const char * strp, long * offsetp));
+static const char * getrule P((const char * strp, struct rule * rulep));
+static void gmtload P((struct state * sp));
+static void gmtsub P((const time_t * timep, long offset, struct tm * tmp));
+static void localsub P((const time_t * timep, long offset, struct tm * tmp));
+static void normalize P((int * tensptr, int * unitsptr, int base));
+static void settzname P((void));
+static time_t time1 P((struct tm * tmp, void (* funcp)(const time_t * CPP_CONST, const long, struct tm * CPP_CONST), long offset));
+static time_t time2 P((struct tm *tmp, void (* funcp)(const time_t * CPP_CONST, const long, struct tm * CPP_CONST), long offset, int * okayp));
+static void timesub P((const time_t * timep, long offset, const struct state * sp, struct tm * tmp));
+static int tmcomp P((const struct tm * atmp, const struct tm * btmp));
+static time_t transtime P((time_t janfirst, int year, const struct rule * rulep, long offset));
+static int tzload P((const char * name, struct state * sp));
+static int tzparse P((const char * name, struct state * sp, int lastditch));
+static void tzsetwall(void);
+
+#else
+
+static const char * getnum(const char * strp, int * CPP_CONST nump, const int min, const int max);
+static void timesub(const time_t * CPP_CONST timep, const long offset, const struct state * CPP_CONST sp, struct tm * CPP_CONST tmp);
+static time_t transtime(const time_t janfirst, const int year, const struct rule * CPP_CONST rulep, const long offset);
+static void tzsetwall(void);
-static long detzcode P((const char * codep));
-static const char * getzname P((const char * strp));
-static const char * getnum P((const char * strp, int * nump, int min,
- int max));
-static const char * getsecs P((const char * strp, long * secsp));
-static const char * getoffset P((const char * strp, long * offsetp));
-static const char * getrule P((const char * strp, struct rule * rulep));
-static void gmtload P((struct state * sp));
-static void gmtsub P((const time_t * timep, long offset,
- struct tm * tmp));
-static void localsub P((const time_t * timep, long offset,
- struct tm * tmp));
-static void normalize P((int * tensptr, int * unitsptr, int base));
-static void settzname P((void));
-static time_t time1 P((struct tm * tmp, void (* funcp)(const time_t * const, const long, struct tm * const),
- long offset));
-static time_t time2 P((struct tm *tmp, void (* funcp)(const time_t * const, const long, struct tm * const),
- long offset, int * okayp));
-static void timesub P((const time_t * timep, long offset,
- const struct state * sp, struct tm * tmp));
-static int tmcomp P((const struct tm * atmp,
- const struct tm * btmp));
-static time_t transtime P((time_t janfirst, int year,
- const struct rule * rulep, long offset));
-static int tzload P((const char * name, struct state * sp));
-static int tzparse P((const char * name, struct state * sp,
- int lastditch));
-static void tzsetwall(void);
+#endif
#ifdef ALL_STATE
static struct state *lclptr;
};
static long
-detzcode(const char * const codep)
+detzcode(const char * CPP_CONST codep)
{
long result;
int i;
static void
settzname(void)
{
- const struct state * const sp = lclptr;
+ const struct state * CPP_CONST sp = lclptr;
int i;
_tzname[0] = WILDABBR;
#endif /* defined ALL_STATE */
for (i = 0; i < sp->typecnt; ++i)
{
- register const struct ttinfo * const ttisp = &sp->ttis[i];
+ register const struct ttinfo * CPP_CONST ttisp = &sp->ttis[i];
_tzname[ttisp->tt_isdst] =
(char *)&sp->chars[ttisp->tt_abbrind];
#if 0
- if (ttisp->tt_isdst)
- _daylight = 1;
- if (i == 0 || !ttisp->tt_isdst)
- _timezone_dll = -(ttisp->tt_gmtoff);
- if (i == 0 || ttisp->tt_isdst)
+ if (ttisp->tt_isdst) {
+ //_daylight = 1;
+ _set_daylight_export(1);
+ }
+ if (i == 0 || !ttisp->tt_isdst) {
+ //_timezone_dll = -(ttisp->tt_gmtoff);
+ _set_timezone_export(-(ttisp->tt_gmtoff));
+ }
+ if (i == 0 || ttisp->tt_isdst) {
_altzone = -(ttisp->tt_gmtoff);
+ }
#endif
}
/*
*/
for (i = 0; i < sp->timecnt; ++i)
{
- const struct ttinfo * const ttisp = &sp->ttis[sp->types[i]];
+ const struct ttinfo * CPP_CONST ttisp = &sp->ttis[sp->types[i]];
_tzname[ttisp->tt_isdst] = (char *)&sp->chars[ttisp->tt_abbrind];
}
}
-static char *
-tzdir(void)
+static char* tzdir(void)
{
static char dir[80]={0}, *cp;
if (dir[0] == 0)
return dir;
}
-static int
-tzload(const char *name, struct state * const sp)
+static int tzload(const char* name, struct state* CPP_CONST sp)
{
const char * p;
int i;
return -1;
ttisp->tt_abbrind = (unsigned char) *p++;
if (ttisp->tt_abbrind < 0 ||
- ttisp->tt_abbrind > sp->charcnt)
+ ttisp->tt_abbrind > sp->charcnt)
return -1;
}
for (i = 0; i < sp->charcnt; ++i)
sp->chars[i] = *p++;
- sp->chars[i] = '\0'; /* ensure '\0' at end */
+ sp->chars[i] = '\0'; /* ensure '\0' at end */
for (i = 0; i < sp->leapcnt; ++i)
{
struct lsinfo * lsisp;
{
ttisp->tt_ttisstd = *p++;
if (ttisp->tt_ttisstd != TRUE &&
- ttisp->tt_ttisstd != FALSE)
- return -1;
+ ttisp->tt_ttisstd != FALSE)
+ return -1;
}
}
return 0;
** character.
*/
-static const char *
-getzname(const char *strp)
+static const char*
+getzname(const char* strp)
{
char c;
while ((c = *strp) != '\0' && !isdigit(c) && c != ',' && c != '-' &&
- c != '+')
+ c != '+')
++strp;
return strp;
}
** Otherwise, return a pointer to the first character not part of the number.
*/
-static const char *
-getnum(const char *strp, int * const nump, const int min, const int max)
+static const char*
+getnum(const char* strp, int* CPP_CONST nump, const int min, const int max)
{
char c;
int num;
*/
static const char *
-getsecs(const char *strp, long * const secsp)
+getsecs(const char *strp, long * CPP_CONST secsp)
{
int num;
++strp;
strp = getnum(strp, &num, 0, SECSPERMIN - 1);
if (strp == NULL)
- return NULL;
+ return NULL;
*secsp += num;
}
}
*/
static const char *
-getoffset(const char *strp, long * const offsetp)
+getoffset(const char *strp, long * CPP_CONST offsetp)
{
int neg;
*/
static const char *
-getrule(const char *strp, struct rule * const rulep)
+getrule(const char *strp, struct rule * CPP_CONST rulep)
{
if (*strp == 'J')
{
strp = getnum(strp, &rulep->r_day, 0, DAYSPERLYEAR - 1);
}
else
- return NULL; /* invalid format */
+ return NULL; /* invalid format */
if (strp == NULL)
return NULL;
if (*strp == '/')
*/
static time_t
-transtime(const time_t janfirst, const int year, const struct rule * const rulep, const long offset)
+transtime(const time_t janfirst, const int year, const struct rule * CPP_CONST rulep, const long offset)
{
int leapyear;
time_t value=0;
yy1 = yy0 / 100;
yy2 = yy0 % 100;
dow = ((26 * m1 - 2) / 10 +
- 1 + yy2 + yy2 / 4 + yy1 / 4 - 2 * yy1) % 7;
+ 1 + yy2 + yy2 / 4 + yy1 / 4 - 2 * yy1) % 7;
if (dow < 0)
dow += DAYSPERWEEK;
for (i = 1; i < rulep->r_week; ++i)
{
if (d + DAYSPERWEEK >=
- mon_lengths[leapyear][rulep->r_mon - 1])
- break;
+ mon_lengths[leapyear][rulep->r_mon - 1])
+ break;
d += DAYSPERWEEK;
}
*/
static int
-tzparse(const char *name, struct state * const sp, const int lastditch)
+tzparse(const char *name, struct state * CPP_CONST sp, const int lastditch)
{
const char * stdname;
const char * dstname=0;
stdname = name;
if (lastditch)
{
- stdlen = strlen(name); /* length of standard zone name */
+ stdlen = strlen(name); /* length of standard zone name */
name += stdlen;
if (stdlen >= sizeof sp->chars)
stdlen = (sizeof sp->chars) - 1;
}
load_result = tzload(TZDEFRULES, sp);
if (load_result != 0)
- sp->leapcnt = 0; /* so, we're off a little */
+ sp->leapcnt = 0; /* so, we're off a little */
if (*name != '\0')
{
dstname = name;
name = getzname(name);
- dstlen = name - dstname; /* length of DST zone name */
+ dstlen = name - dstname; /* length of DST zone name */
if (dstlen < 3)
return -1;
if (*name != '\0' && *name != ',' && *name != ';')
{
name = getoffset(name, &dstoffset);
if (name == NULL)
- return -1;
+ return -1;
}
else
dstoffset = stdoffset - SECSPERHOUR;
++name;
if ((name = getrule(name, &start)) == NULL)
- return -1;
+ return -1;
if (*name++ != ',')
- return -1;
+ return -1;
if ((name = getrule(name, &end)) == NULL)
- return -1;
+ return -1;
if (*name != '\0')
- return -1;
- sp->typecnt = 2; /* standard time and DST */
+ return -1;
+ sp->typecnt = 2; /* standard time and DST */
/*
** Two transitions per year, from EPOCH_YEAR to 2037.
*/
sp->timecnt = 2 * (2037 - EPOCH_YEAR + 1);
if (sp->timecnt > TZ_MAX_TIMES)
- return -1;
+ return -1;
sp->ttis[0].tt_gmtoff = -dstoffset;
sp->ttis[0].tt_isdst = 1;
sp->ttis[0].tt_abbrind = stdlen + 1;
janfirst = 0;
for (year = EPOCH_YEAR; year <= 2037; ++year)
{
- starttime = transtime(janfirst, year, &start,
- stdoffset);
- endtime = transtime(janfirst, year, &end,
- dstoffset);
- if (starttime > endtime)
- {
- *atp++ = endtime;
- *typep++ = 1; /* DST ends */
- *atp++ = starttime;
- *typep++ = 0; /* DST begins */
- }
- else
- {
- *atp++ = starttime;
- *typep++ = 0; /* DST begins */
- *atp++ = endtime;
- *typep++ = 1; /* DST ends */
- }
- janfirst +=
- year_lengths[isleap(year)] * SECSPERDAY;
+ starttime = transtime(janfirst, year, &start,
+ stdoffset);
+ endtime = transtime(janfirst, year, &end,
+ dstoffset);
+ if (starttime > endtime)
+ {
+ *atp++ = endtime;
+ *typep++ = 1; /* DST ends */
+ *atp++ = starttime;
+ *typep++ = 0; /* DST begins */
+ }
+ else
+ {
+ *atp++ = starttime;
+ *typep++ = 0; /* DST begins */
+ *atp++ = endtime;
+ *typep++ = 1; /* DST ends */
+ }
+ janfirst +=
+ year_lengths[isleap(year)] * SECSPERDAY;
}
}
else
int i;
if (*name != '\0')
- return -1;
+ return -1;
if (load_result != 0)
- return -1;
+ return -1;
/*
** Compute the difference between the real and
** prototype standard and summer time offsets
dstfix = 0;
for (i = 0; i < sp->typecnt; ++i)
{
- if (sp->ttis[i].tt_isdst)
- {
- oldfix = dstfix;
- dstfix =
- sp->ttis[i].tt_gmtoff + dstoffset;
- if (sawdst && (oldfix != dstfix))
- return -1;
- sp->ttis[i].tt_gmtoff = -dstoffset;
- sp->ttis[i].tt_abbrind = stdlen + 1;
- sawdst = TRUE;
- }
- else
- {
- oldfix = stdfix;
- stdfix =
- sp->ttis[i].tt_gmtoff + stdoffset;
- if (sawstd && (oldfix != stdfix))
- return -1;
- sp->ttis[i].tt_gmtoff = -stdoffset;
- sp->ttis[i].tt_abbrind = 0;
- sawstd = TRUE;
- }
+ if (sp->ttis[i].tt_isdst)
+ {
+ oldfix = dstfix;
+ dstfix =
+ sp->ttis[i].tt_gmtoff + dstoffset;
+ if (sawdst && (oldfix != dstfix))
+ return -1;
+ sp->ttis[i].tt_gmtoff = -dstoffset;
+ sp->ttis[i].tt_abbrind = stdlen + 1;
+ sawdst = TRUE;
+ }
+ else
+ {
+ oldfix = stdfix;
+ stdfix =
+ sp->ttis[i].tt_gmtoff + stdoffset;
+ if (sawstd && (oldfix != stdfix))
+ return -1;
+ sp->ttis[i].tt_gmtoff = -stdoffset;
+ sp->ttis[i].tt_abbrind = 0;
+ sawstd = TRUE;
+ }
}
/*
** Make sure we have both standard and summer time.
*/
if (!sawdst || !sawstd)
- return -1;
+ return -1;
/*
** Now correct the transition times by shifting
** them by the difference between the real and
isdst = FALSE; /* we start in standard time */
for (i = 0; i < sp->timecnt; ++i)
{
- const struct ttinfo * ttisp;
-
- /*
- ** If summer time is in effect, and the
- ** transition time was not specified as
- ** standard time, add the summer time
- ** offset to the transition time;
- ** otherwise, add the standard time offset
- ** to the transition time.
- */
- ttisp = &sp->ttis[sp->types[i]];
- sp->ats[i] +=
- (isdst && !ttisp->tt_ttisstd) ?
- dstfix : stdfix;
- isdst = ttisp->tt_isdst;
+ const struct ttinfo * ttisp;
+
+ /*
+ ** If summer time is in effect, and the
+ ** transition time was not specified as
+ ** standard time, add the summer time
+ ** offset to the transition time;
+ ** otherwise, add the standard time offset
+ ** to the transition time.
+ */
+ ttisp = &sp->ttis[sp->types[i]];
+ sp->ats[i] +=
+ (isdst && !ttisp->tt_ttisstd) ?
+ dstfix : stdfix;
+ isdst = ttisp->tt_isdst;
}
}
}
else
{
dstlen = 0;
- sp->typecnt = 1; /* only standard time */
+ sp->typecnt = 1; /* only standard time */
sp->timecnt = 0;
sp->ttis[0].tt_gmtoff = -stdoffset;
sp->ttis[0].tt_isdst = 0;
}
static void
-gmtload(struct state * const sp)
+gmtload(struct state * CPP_CONST sp)
{
if (tzload(GMT, sp) != 0)
(void) tzparse(GMT, sp, TRUE);
lclptr = (struct state *) malloc(sizeof *lclptr);
if (lclptr == NULL)
{
- settzname(); /* all we can do */
+ settzname(); /* all we can do */
return;
}
}
/*
** User wants it fast rather than right.
*/
- lclptr->leapcnt = 0; /* so, we're off a little */
+ lclptr->leapcnt = 0; /* so, we're off a little */
lclptr->timecnt = 0;
lclptr->ttis[0].tt_gmtoff = 0;
lclptr->ttis[0].tt_abbrind = 0;
lclptr = (struct state *) malloc(sizeof *lclptr);
if (lclptr == NULL)
{
- settzname(); /* all we can do */
+ settzname(); /* all we can do */
return;
}
}
/*ARGSUSED*/
static void
-localsub(const time_t * const timep, const long offset, struct tm * const tmp)
+localsub(const time_t * CPP_CONST timep, const long offset, struct tm * CPP_CONST tmp)
{
const struct state * sp;
const struct ttinfo * ttisp;
while (sp->ttis[i].tt_isdst)
if (++i >= sp->typecnt)
{
- i = 0;
- break;
+ i = 0;
+ break;
}
}
else
{
for (i = 1; i < sp->timecnt; ++i)
if (t < sp->ats[i])
- break;
+ break;
i = sp->types[i - 1];
}
ttisp = &sp->ttis[i];
}
struct tm *
-localtime(const time_t * const timep)
+localtime(const time_t * CPP_CONST timep)
{
static struct tm tm;
*/
static void
-gmtsub(const time_t * const timep, const long offset, struct tm * const tmp)
+gmtsub(const time_t * CPP_CONST timep, const long offset, struct tm * CPP_CONST tmp)
{
if (!gmt_is_set)
{
}
struct tm *
-gmtime(const time_t * const timep)
+gmtime(const time_t * CPP_CONST timep)
{
static struct tm tm;
}
static void
-timesub(const time_t * const timep, const long offset, const struct state * const sp, struct tm * const tmp)
+timesub(const time_t * CPP_CONST timep, const long offset, const struct state * CPP_CONST sp, struct tm * CPP_CONST tmp)
{
const struct lsinfo * lp;
long days;
if (*timep >= lp->ls_trans)
{
if (*timep == lp->ls_trans)
- hit = ((i == 0 && lp->ls_corr > 0) ||
- lp->ls_corr > sp->lsis[i - 1].ls_corr);
+ hit = ((i == 0 && lp->ls_corr > 0) ||
+ lp->ls_corr > sp->lsis[i - 1].ls_corr);
corr = lp->ls_corr;
break;
}
{
yleap = isleap(y);
if (days < (long) year_lengths[yleap])
- break;
+ break;
++y;
days = days - (long) year_lengths[yleap];
}
static char result[26];
(void) sprintf(result, "%.3s %.3s%3d %02d:%02d:%02d %d\n",
- wday_name[timeptr->tm_wday],
- mon_name[timeptr->tm_mon],
- timeptr->tm_mday, timeptr->tm_hour,
- timeptr->tm_min, timeptr->tm_sec,
- TM_YEAR_BASE + timeptr->tm_year);
- return result;
-}
-
-wchar_t *
-_wasctime(const struct tm *timeptr)
-{
- static const wchar_t wday_name[DAYSPERWEEK][3] = {
- L"Sun", L"Mon", L"Tue", L"Wed", L"Thu", L"Fri", L"Sat"
- };
- static const wchar_t mon_name[MONSPERYEAR][3] = {
- L"Jan", L"Feb", L"Mar", L"Apr", L"May", L"Jun",
- L"Jul", L"Aug", L"Sep", L"Oct", L"Nov", L"Dec"
- };
- static wchar_t result[26];
-
- (void)swprintf(result, L"%.3s %.3s%3d %02d:%02d:%02d %d\n",
- wday_name[timeptr->tm_wday],
- mon_name[timeptr->tm_mon],
- timeptr->tm_mday, timeptr->tm_hour,
- timeptr->tm_min, timeptr->tm_sec,
- TM_YEAR_BASE + timeptr->tm_year);
+ wday_name[timeptr->tm_wday],
+ mon_name[timeptr->tm_mon],
+ timeptr->tm_mday, timeptr->tm_hour,
+ timeptr->tm_min, timeptr->tm_sec,
+ TM_YEAR_BASE + timeptr->tm_year);
return result;
}
-
char *
-ctime(const time_t * const timep)
+ctime(const time_t * CPP_CONST timep)
{
return asctime(localtime(timep));
}
-wchar_t *
-_wctime(const time_t * const timep)
-{
- return _wasctime(localtime(timep));
-}
-
/*
** Adapted from code provided by Robert Elz, who writes:
-** The "best" way to do mktime I think is based on an idea of Bob
-** Kridle's (so its said...) from a long time ago. (mtxinu!kridle now).
-** It does a binary search of the time_t space. Since time_t's are
-** just 32 bits, its a max of 32 iterations (even at 64 bits it
-** would still be very reasonable).
+** The "best" way to do mktime I think is based on an idea of Bob
+** Kridle's (so its said...) from a long time ago. (mtxinu!kridle now).
+** It does a binary search of the time_t space. Since time_t's are
+** just 32 bits, its a max of 32 iterations (even at 64 bits it
+** would still be very reasonable).
*/
#ifndef WRONG
-#define WRONG (-1)
+#define WRONG (-1)
#endif /* !defined WRONG */
static void
-normalize(int * const tensptr, int * const unitsptr, const int base)
+normalize(int * CPP_CONST tensptr, int * CPP_CONST unitsptr, const int base)
{
if (*unitsptr >= base)
{
}
static int
-tmcomp(const struct tm * const atmp, const struct tm * const btmp)
+tmcomp(const struct tm * CPP_CONST atmp, const struct tm * CPP_CONST btmp)
{
int result;
}
static time_t
-time2(struct tm *tmp, void (*const funcp)(const time_t *const,const long,struct tm *), const long offset, int * const okayp)
+time2(struct tm *tmp, void (*const funcp)(const time_t * CPP_CONST, const long, struct tm *), const long offset, int * CPP_CONST okayp)
{
const struct state * sp;
int dir;
for ( ; ; )
{
i = mon_lengths[isleap(yourtm.tm_year +
- TM_YEAR_BASE)][yourtm.tm_mon];
+ TM_YEAR_BASE)][yourtm.tm_mon];
if (yourtm.tm_mday <= i)
break;
yourtm.tm_mday -= i;
** If time_t is signed, then 0 is the median value,
** if time_t is unsigned, then 1 << bits is median.
*/
+#ifdef _MSVCRT_LIB_
t = (time_t) ((1 << bits) - 1);
+#else // TODO: FIXME: review which is correct
+ t = (time_t) 1 << bits;
+#endif /*_MSVCRT_LIB_*/
+
for ( ; ; )
{
(*funcp)(&t, offset, &mytm);
if (dir != 0)
{
if (bits-- < 0)
- return WRONG;
+ return WRONG;
if (bits < 0)
- --t;
+ --t;
else if (dir > 0)
- t -= (time_t) 1 << bits;
+ t -= (time_t) 1 << bits;
else t += (time_t) 1 << bits;
continue;
}
for (i = 0; i < sp->typecnt; ++i)
{
if (sp->ttis[i].tt_isdst != yourtm.tm_isdst)
- continue;
+ continue;
for (j = 0; j < sp->typecnt; ++j)
{
- if (sp->ttis[j].tt_isdst == yourtm.tm_isdst)
- continue;
- newt = t + sp->ttis[j].tt_gmtoff -
- sp->ttis[i].tt_gmtoff;
- (*funcp)(&newt, offset, &mytm);
- if (tmcomp(&mytm, &yourtm) != 0)
- continue;
- if (mytm.tm_isdst != yourtm.tm_isdst)
- continue;
- /*
- ** We have a match.
- */
- t = newt;
- goto label;
+ if (sp->ttis[j].tt_isdst == yourtm.tm_isdst)
+ continue;
+ newt = t + sp->ttis[j].tt_gmtoff -
+ sp->ttis[i].tt_gmtoff;
+ (*funcp)(&newt, offset, &mytm);
+ if (tmcomp(&mytm, &yourtm) != 0)
+ continue;
+ if (mytm.tm_isdst != yourtm.tm_isdst)
+ continue;
+ /*
+ ** We have a match.
+ */
+ t = newt;
+ goto label;
}
}
return WRONG;
}
static time_t
-time1(struct tm * const tmp, void (*const funcp)(const time_t * const, const long, struct tm *), const long offset)
+time1(struct tm * CPP_CONST tmp, void (*const funcp)(const time_t * CPP_CONST, const long, struct tm *), const long offset)
{
time_t t;
const struct state * sp;
for (otheri = 0; otheri < sp->typecnt; ++otheri)
{
if (sp->ttis[otheri].tt_isdst == tmp->tm_isdst)
- continue;
+ continue;
tmp->tm_sec += sp->ttis[otheri].tt_gmtoff -
- sp->ttis[samei].tt_gmtoff;
+ sp->ttis[samei].tt_gmtoff;
tmp->tm_isdst = !tmp->tm_isdst;
t = time2(tmp, funcp, offset, &okay);
if (okay)
- return t;
+ return t;
tmp->tm_sec -= sp->ttis[otheri].tt_gmtoff -
- sp->ttis[samei].tt_gmtoff;
+ sp->ttis[samei].tt_gmtoff;
tmp->tm_isdst = !tmp->tm_isdst;
}
}
{
return time1(tmp, localsub, 0L);
}
-
-
-
-