diff --git a/reactos/lib/sdk/crt/crt.rbuild b/reactos/lib/sdk/crt/crt.rbuild
index b864632c337..70324067f7c 100644
--- a/reactos/lib/sdk/crt/crt.rbuild
+++ b/reactos/lib/sdk/crt/crt.rbuild
@@ -429,18 +429,46 @@
systime.c
+ asctime.c
clock.c
+ ctime32.c
+ ctime64.c
ctime.c
+ difftime32.c
+ difftime64.c
difftime.c
+ ftime32.c
+ ftime64.c
ftime.c
+ futime32.c
+ futime64.c
+ futime.c
+ gmtime.c
+ localtime32.c
+ localtime64.c
+ localtime.c
+ mktime.c
strdate.c
strftime.c
strtime.c
+ time32.c
+ time64.c
time.c
- tz_vars.c
+ timezone.c
+ tzname.c
+ utime32.c
+ utime64.c
+ utime.c
+ wasctime.c
+ wcsftime.c
+ wctime32.c
+ wctime64.c
wctime.c
wstrdate.c
wstrtime.c
+ wutime32.c
+ wutime64.c
+ wutime.c
wcscoll.c
diff --git a/reactos/lib/sdk/crt/include/internal/file.h b/reactos/lib/sdk/crt/include/internal/file.h
index 9a5c2440f3f..bb175fe42ea 100644
--- a/reactos/lib/sdk/crt/include/internal/file.h
+++ b/reactos/lib/sdk/crt/include/internal/file.h
@@ -49,8 +49,6 @@ int __fileno_setmode(int _fd, int _newmode);
void sigabort_handler(int sig);
void UnixTimeToFileTime(time_t unix_time, FILETIME* filetime, DWORD remainder);
-time_t FileTimeToUnixTime(const FILETIME* filetime, DWORD *remainder);
-
#define __FILE_REC_MAX 20
typedef struct __file_rec
diff --git a/reactos/lib/sdk/crt/include/internal/time.h b/reactos/lib/sdk/crt/include/internal/time.h
new file mode 100644
index 00000000000..1299da3f213
--- /dev/null
+++ b/reactos/lib/sdk/crt/include/internal/time.h
@@ -0,0 +1,55 @@
+#define DIFFTIME 0x19db1ded53e8000ULL
+#define DIFFDAYS (3 * DAYSPER100YEARS + 17 * DAYSPER4YEARS + 1 * DAYSPERYEAR)
+
+#define DAYSPERYEAR 365
+#define DAYSPER4YEARS (4*DAYSPERYEAR+1)
+#define DAYSPER100YEARS (25*DAYSPER4YEARS-1)
+#define DAYSPER400YEARS (4*DAYSPER100YEARS+1)
+#define SECONDSPERDAY (24*60*60)
+#define SECONDSPERHOUR (60*60)
+#define LEAPDAY 59
+
+static __inline
+__time64_t
+FileTimeToUnixTime(const FILETIME *FileTime, USHORT *millitm)
+{
+ ULARGE_INTEGER ULargeInt;
+ __time64_t time;
+
+ ULargeInt.LowPart = FileTime->dwLowDateTime;
+ ULargeInt.HighPart = FileTime->dwHighDateTime;
+ ULargeInt.QuadPart -= DIFFTIME;
+
+ time = ULargeInt.QuadPart / 10000;
+ if (millitm)
+ *millitm = (ULargeInt.QuadPart % 10000) / 10;
+
+ return time;
+}
+
+static __inline
+long leapyears_passed(long days)
+{
+ long quadcenturies, centuries, quadyears;
+ quadcenturies = days / DAYSPER400YEARS;
+ days -= quadcenturies;
+ centuries = days / DAYSPER100YEARS;
+ days += centuries;
+ quadyears = days / DAYSPER4YEARS;
+ return quadyears - centuries + quadcenturies;
+}
+
+static __inline
+long leapdays_passed(long days)
+{
+ return leapyears_passed(days + DAYSPERYEAR - LEAPDAY + 1);
+}
+
+static __inline
+long years_passed(long days)
+{
+ return (days - leapdays_passed(days)) / 365;
+}
+
+extern long dst_begin;
+extern long dst_end;
diff --git a/reactos/lib/sdk/crt/include/internal/tls.h b/reactos/lib/sdk/crt/include/internal/tls.h
index 9908260b91d..ee8c325f9b6 100644
--- a/reactos/lib/sdk/crt/include/internal/tls.h
+++ b/reactos/lib/sdk/crt/include/internal/tls.h
@@ -12,6 +12,7 @@
#include
#include
#include
+#include
#include
@@ -29,6 +30,10 @@ typedef struct _ThreadData
EXCEPTION_RECORD *exc_record; /* Head of exception record list */
+ struct tm tmbuf; /* Used by gmtime, mktime, mkgmtime, localtime */
+ char asctimebuf[26]; /* Buffer for asctime and ctime */
+ wchar_t wasctimebuf[26]; /* Buffer for wasctime and wctime */
+
} THREADDATA, *PTHREADDATA;
@@ -41,4 +46,3 @@ PTHREADDATA GetThreadData(void);
#endif /* __MSVCRT_INTERNAL_TLS_H */
/* EOF */
-
diff --git a/reactos/lib/sdk/crt/precomp.h b/reactos/lib/sdk/crt/precomp.h
index 19d08a56aa8..580f29d310c 100644
--- a/reactos/lib/sdk/crt/precomp.h
+++ b/reactos/lib/sdk/crt/precomp.h
@@ -58,6 +58,7 @@ WINE_DEFAULT_DEBUG_CHANNEL(msvcrt);
#include
#include
#include
+#include
#include
#include
diff --git a/reactos/lib/sdk/crt/time/clock.c b/reactos/lib/sdk/crt/time/clock.c
deleted file mode 100644
index 37ec011fbef..00000000000
--- a/reactos/lib/sdk/crt/time/clock.c
+++ /dev/null
@@ -1,28 +0,0 @@
-/*
- * COPYRIGHT: See COPYING in the top level directory
- * PROJECT: ReactOS system libraries
- * FILE: lib/msvcrt/time/clock.c
- * PURPOSE: Get elapsed time
- * PROGRAMER: Ariadne
- * UPDATE HISTORY:
- * 28/12/98: Created
- */
-
-#include
-
-/*
- * @implemented
- */
-clock_t clock ( void )
-{
- FILETIME CreationTime;
- FILETIME ExitTime;
- FILETIME KernelTime;
- FILETIME UserTime;
- DWORD Remainder;
-
- if (!GetProcessTimes(GetCurrentProcess(),&CreationTime,&ExitTime,&KernelTime,&UserTime))
- return -1;
-
- return FileTimeToUnixTime(&KernelTime,&Remainder) + FileTimeToUnixTime(&UserTime,&Remainder);
-}
diff --git a/reactos/lib/sdk/crt/time/ctime.c b/reactos/lib/sdk/crt/time/ctime.c
deleted file mode 100644
index 8727233d284..00000000000
--- a/reactos/lib/sdk/crt/time/ctime.c
+++ /dev/null
@@ -1,1472 +0,0 @@
-
-// fix djdir
-
-/* Copyright (C) 1995 DJ Delorie, see COPYING.DJ for details */
-/* This file has been modified by DJ Delorie. These modifications are
-** Copyright (C) 1995 DJ Delorie, 24 Kirsten Ave, Rochester NH,
-** 03867-2954, USA.
-*/
-
-/*
- * Copyright (c) 1987, 1989 Regents of the University of California.
- * All rights reserved.
- *
- * This code is derived from software contributed to Berkeley by
- * Arthur David Olson of the National Cancer Institute.
- *
- * Redistribution and use in source and binary forms are permitted provided
- * that: (1) source distributions retain this entire copyright notice and
- * comment, and (2) distributions including binaries display the following
- * acknowledgement: ``This product includes software developed by the
- * University of California, Berkeley and its contributors'' in the
- * documentation or other materials provided with the distribution and in
- * all advertising materials mentioning features or use of this software.
- * Neither the name of the University nor the names of its contributors may
- * be used to endorse or promote products derived from this software without
- * specific prior written permission.
- * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR IMPLIED
- * WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF
- * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
- */
-
-/*
-** 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
-
-#include "tzfile.h"
-#include "posixrul.h"
-
-#ifdef __cplusplus
-#define CPP_CONST const
-#else
-#define CPP_CONST
-#endif
-
-#undef P
-#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.
-** 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
-** string "tzname[0] used before set", and similarly for the other cases.
-** And another: initialize tzname[0] to "ERA", with an explanation in the
-** manual page of what this "time zone abbreviation" means (doing this so
-** that tzname[0] has the "normal" length of three characters).
-*/
-
-void _set_daylight_export(int);
-void _set_timezone_export(int);
-
-
-/* buffers must hold 64 characters! */
-static char TZ_NAME[64] = "PST";
-static char TZ_DST_NAME[64] = "PDT";
-
-#ifndef TRUE
-#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 lsinfo { /* leap second information */
- time_t ls_trans; /* transition time */
- long ls_corr; /* correction to apply */
-};
-
-struct state {
- int leapcnt;
- int timecnt;
- int typecnt;
- int charcnt;
- time_t ats[TZ_MAX_TIMES];
- unsigned char types[TZ_MAX_TIMES];
- struct ttinfo ttis[TZ_MAX_TYPES];
- char chars[(TZ_MAX_CHARS + 1 > sizeof GMT) ? TZ_MAX_CHARS + 1 : sizeof GMT];
- struct lsinfo lsis[TZ_MAX_LEAPS];
-};
-
-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 */
-};
-
-#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);
-
-#endif
-
-#ifdef ALL_STATE
-static struct state *lclptr;
-static struct state *gmtptr;
-#endif /* defined ALL_STATE */
-
-#ifndef ALL_STATE
-static struct state lclmem;
-static struct state gmtmem;
-#define lclptr (&lclmem)
-#define gmtptr (&gmtmem)
-#endif /* State Farm */
-
-static int lcl_is_set;
-static int gmt_is_set;
-
-char * _tzname[2] = {
- TZ_NAME,
- TZ_DST_NAME,
-};
-
-static long
-detzcode(const char * CPP_CONST codep)
-{
- long result;
- int i;
-
- result = 0;
- for (i = 0; i < 4; ++i)
- result = (result << 8) | (codep[i] & 0xff);
- return result;
-}
-
-static void
-settzname(void)
-{
- const struct state * CPP_CONST sp = lclptr;
- int i;
-
- _tzname[0] = TZ_NAME;
- _tzname[1] = TZ_DST_NAME;
-#ifdef ALL_STATE
- if (sp == NULL)
- {
- _tzname[0] = _tzname[1] = GMT;
- return;
- }
-#endif /* defined ALL_STATE */
- for (i = 0; i < sp->typecnt; ++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;
- _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
- }
- /*
- ** And to get the latest zone names into tzname. . .
- */
- for (i = 0; i < sp->timecnt; ++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 dir[80]={0}, *cp;
- if (dir[0] == 0)
- {
- if ((cp = getenv("TZDIR")))
- {
- strcpy(dir, cp);
- }
- else if ((cp = getenv("DJDIR")))
- {
- strcpy(dir, cp);
- strcat(dir, "/zoneinfo");
- }
- else
- strcpy(dir, "./");
- }
- return dir;
-}
-
-static int tzload(const char* name, struct state* CPP_CONST sp)
-{
- const char * p;
- int i;
- int fid;
- char fullname[FILENAME_MAX + 1];
- const struct tzhead * tzhp;
- char buf[sizeof *sp + sizeof *tzhp];
- int ttisstdcnt;
-
- if (name == NULL && (name = TZDEFAULT) == NULL)
- return -1;
-
- if (name[0] == ':')
- ++name;
- if (name[0] != '/')
- {
- if ((p = tzdir()) == NULL)
- return -1;
- if ((strlen(p) + strlen(name) + 1) >= sizeof fullname)
- return -1;
- strcpy(fullname, p);
- strcat(fullname, "/");
- strcat(fullname, name);
- name = fullname;
- }
-
- if ((fid = _open(name, OPEN_MODE)) == -1)
- {
- const char *base = strrchr(name, '/');
- if (base)
- base++;
- else
- base = name;
- if (strcmp(base, "posixrules"))
- return -1;
-
- /* We've got a built-in copy of posixrules just in case */
- memcpy(buf, _posixrules_data, sizeof(_posixrules_data));
- i = sizeof(_posixrules_data);
- }
- else
- {
- i = _read(fid, buf, sizeof buf);
- if (_close(fid) != 0 || i < (int)sizeof *tzhp)
- return -1;
- }
-
- tzhp = (struct tzhead *) buf;
- ttisstdcnt = (int) detzcode(tzhp->tzh_ttisstdcnt);
- sp->leapcnt = (int) detzcode(tzhp->tzh_leapcnt);
- sp->timecnt = (int) detzcode(tzhp->tzh_timecnt);
- sp->typecnt = (int) detzcode(tzhp->tzh_typecnt);
- sp->charcnt = (int) detzcode(tzhp->tzh_charcnt);
- if (sp->leapcnt < 0 || sp->leapcnt > TZ_MAX_LEAPS ||
- sp->typecnt <= 0 || sp->typecnt > TZ_MAX_TYPES ||
- sp->timecnt < 0 || sp->timecnt > TZ_MAX_TIMES ||
- sp->charcnt < 0 || sp->charcnt > TZ_MAX_CHARS ||
- (ttisstdcnt != sp->typecnt && ttisstdcnt != 0))
- return -1;
- if (i < (int)sizeof *tzhp +
- sp->timecnt * (4 + (int)sizeof (char)) +
- sp->typecnt * (4 + 2 * (int)sizeof (char)) +
- sp->charcnt * (int)sizeof (char) +
- sp->leapcnt * 2 * 4 +
- ttisstdcnt * (int)sizeof (char))
- return -1;
- p = buf + sizeof *tzhp;
- for (i = 0; i < sp->timecnt; ++i)
- {
- sp->ats[i] = detzcode(p);
- p += 4;
- }
- for (i = 0; i < sp->timecnt; ++i)
- {
- sp->types[i] = (unsigned char) *p++;
- if (sp->types[i] >= sp->typecnt)
- return -1;
- }
- for (i = 0; i < sp->typecnt; ++i)
- {
- struct ttinfo * ttisp;
-
- ttisp = &sp->ttis[i];
- ttisp->tt_gmtoff = detzcode(p);
- p += 4;
- ttisp->tt_isdst = (unsigned char) *p++;
- if (ttisp->tt_isdst != 0 && ttisp->tt_isdst != 1)
- return -1;
- ttisp->tt_abbrind = (unsigned char) *p++;
- if (ttisp->tt_abbrind < 0 ||
- 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 */
- for (i = 0; i < sp->leapcnt; ++i)
- {
- struct lsinfo * lsisp;
-
- lsisp = &sp->lsis[i];
- lsisp->ls_trans = detzcode(p);
- p += 4;
- lsisp->ls_corr = detzcode(p);
- p += 4;
- }
- for (i = 0; i < sp->typecnt; ++i)
- {
- struct ttinfo * ttisp;
-
- ttisp = &sp->ttis[i];
- if (ttisstdcnt == 0)
- ttisp->tt_ttisstd = FALSE;
- else
- {
- ttisp->tt_ttisstd = *p++;
- if (ttisp->tt_ttisstd != TRUE &&
- ttisp->tt_ttisstd != FALSE)
- return -1;
- }
- }
- return 0;
-}
-
-static const int mon_lengths[2][MONSPERYEAR] = {
-{ 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 },
-{ 31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 }
-};
-
-static const int year_lengths[2] = {
-DAYSPERNYEAR, DAYSPERLYEAR
-};
-
-/*
-** Given a pointer into a time zone string, scan until a character that is not
-** a valid character in a zone name is found. Return a pointer to that
-** character.
-*/
-
-static const char*
-getzname(const char* strp)
-{
- char c;
-
- while ((c = *strp) != '\0' && !isdigit(c) && c != ',' && c != '-' &&
- c != '+')
- ++strp;
- return strp;
-}
-
-/*
-** Given a pointer into a time zone string, extract a number from that string.
-** Check that the number is within a specified range; if it is not, return
-** NULL.
-** Otherwise, return a pointer to the first character not part of the number.
-*/
-
-static const char*
-getnum(const char* strp, int* CPP_CONST nump, const int min, const int max)
-{
- char c;
- int num;
-
- if (strp == NULL || !isdigit(*strp))
- return NULL;
- num = 0;
- while ((c = *strp) != '\0' && isdigit(c))
- {
- num = num * 10 + (c - '0');
- if (num > max)
- return NULL;
- ++strp;
- }
- if (num < min)
- return NULL;
- *nump = num;
- return strp;
-}
-
-/*
-** Given a pointer into a time zone string, extract a number of seconds,
-** in hh[:mm[:ss]] form, from the string.
-** If any error occurs, return NULL.
-** Otherwise, return a pointer to the first character not part of the number
-** of seconds.
-*/
-
-static const char *
-getsecs(const char *strp, long * CPP_CONST secsp)
-{
- int num;
-
- strp = getnum(strp, &num, 0, HOURSPERDAY);
- if (strp == NULL)
- return NULL;
- *secsp = num * SECSPERHOUR;
- if (*strp == ':')
- {
- ++strp;
- strp = getnum(strp, &num, 0, MINSPERHOUR - 1);
- if (strp == NULL)
- return NULL;
- *secsp += num * SECSPERMIN;
- if (*strp == ':')
- {
- ++strp;
- strp = getnum(strp, &num, 0, SECSPERMIN - 1);
- if (strp == NULL)
- return NULL;
- *secsp += num;
- }
- }
- return strp;
-}
-
-/*
-** Given a pointer into a time zone string, extract an offset, in
-** [+-]hh[:mm[:ss]] form, from the string.
-** If any error occurs, return NULL.
-** Otherwise, return a pointer to the first character not part of the time.
-*/
-
-static const char *
-getoffset(const char *strp, long * CPP_CONST offsetp)
-{
- int neg;
-
- if (*strp == '-')
- {
- neg = 1;
- ++strp;
- }
- else if (isdigit(*strp) || *strp++ == '+')
- neg = 0;
- else
- return NULL; /* illegal offset */
- strp = getsecs(strp, offsetp);
- if (strp == NULL)
- return NULL; /* illegal time */
- if (neg)
- *offsetp = -*offsetp;
- return strp;
-}
-
-/*
-** Given a pointer into a time zone string, extract a rule in the form
-** date[/time]. See POSIX section 8 for the format of "date" and "time".
-** If a valid rule is not found, return NULL.
-** Otherwise, return a pointer to the first character not part of the rule.
-*/
-
-static const char *
-getrule(const char *strp, struct rule * CPP_CONST rulep)
-{
- if (*strp == 'J')
- {
- /*
- ** Julian day.
- */
- rulep->r_type = JULIAN_DAY;
- ++strp;
- strp = getnum(strp, &rulep->r_day, 1, DAYSPERNYEAR);
- }
- else if (*strp == 'M')
- {
- /*
- ** Month, week, day.
- */
- rulep->r_type = MONTH_NTH_DAY_OF_WEEK;
- ++strp;
- strp = getnum(strp, &rulep->r_mon, 1, MONSPERYEAR);
- if (strp == NULL)
- return NULL;
- if (*strp++ != '.')
- return NULL;
- strp = getnum(strp, &rulep->r_week, 1, 5);
- if (strp == NULL)
- return NULL;
- if (*strp++ != '.')
- return NULL;
- strp = getnum(strp, &rulep->r_day, 0, DAYSPERWEEK - 1);
- }
- else if (isdigit(*strp))
- {
- /*
- ** Day of year.
- */
- rulep->r_type = DAY_OF_YEAR;
- strp = getnum(strp, &rulep->r_day, 0, DAYSPERLYEAR - 1);
- }
- else
- return NULL; /* invalid format */
- if (strp == NULL)
- return NULL;
- if (*strp == '/')
- {
- /*
- ** Time specified.
- */
- ++strp;
- strp = getsecs(strp, &rulep->r_time);
- }
- else
- rulep->r_time = 2 * SECSPERHOUR; /* default = 2:00:00 */
- return strp;
-}
-
-/*
-** Given the Epoch-relative time of January 1, 00:00:00 GMT, in a year, the
-** year, a rule, and the offset from GMT at the time that rule takes effect,
-** calculate the Epoch-relative time that rule takes effect.
-*/
-
-static time_t
-transtime(const time_t janfirst, const int year, const struct rule * CPP_CONST rulep, const long offset)
-{
- int leapyear;
- time_t value=0;
- int i;
- int d, m1, yy0, yy1, yy2, dow;
-
- leapyear = isleap(year);
- switch (rulep->r_type)
- {
-
- case JULIAN_DAY:
- /*
- ** Jn - Julian day, 1 == January 1, 60 == March 1 even in leap
- ** years.
- ** In non-leap years, or if the day number is 59 or less, just
- ** add SECSPERDAY times the day number-1 to the time of
- ** January 1, midnight, to get the day.
- */
- value = janfirst + (rulep->r_day - 1) * SECSPERDAY;
- if (leapyear && rulep->r_day >= 60)
- value += SECSPERDAY;
- break;
-
- case DAY_OF_YEAR:
- /*
- ** n - day of year.
- ** Just add SECSPERDAY times the day number to the time of
- ** January 1, midnight, to get the day.
- */
- value = janfirst + rulep->r_day * SECSPERDAY;
- break;
-
- case MONTH_NTH_DAY_OF_WEEK:
- /*
- ** Mm.n.d - nth "dth day" of month m.
- */
- value = janfirst;
- for (i = 0; i < rulep->r_mon - 1; ++i)
- value += mon_lengths[leapyear][i] * SECSPERDAY;
-
- /*
- ** Use Zeller's Congruence to get day-of-week of first day of
- ** month.
- */
- m1 = (rulep->r_mon + 9) % 12 + 1;
- yy0 = (rulep->r_mon <= 2) ? (year - 1) : year;
- yy1 = yy0 / 100;
- yy2 = yy0 % 100;
- dow = ((26 * m1 - 2) / 10 +
- 1 + yy2 + yy2 / 4 + yy1 / 4 - 2 * yy1) % 7;
- if (dow < 0)
- dow += DAYSPERWEEK;
-
- /*
- ** "dow" is the day-of-week of the first day of the month. Get
- ** the day-of-month (zero-origin) of the first "dow" day of the
- ** month.
- */
- d = rulep->r_day - dow;
- if (d < 0)
- d += DAYSPERWEEK;
- for (i = 1; i < rulep->r_week; ++i)
- {
- if (d + DAYSPERWEEK >=
- mon_lengths[leapyear][rulep->r_mon - 1])
- break;
- d += DAYSPERWEEK;
- }
-
- /*
- ** "d" is the day-of-month (zero-origin) of the day we want.
- */
- value += d * SECSPERDAY;
- break;
- }
-
- /*
- ** "value" is the Epoch-relative time of 00:00:00 GMT on the day in
- ** question. To get the Epoch-relative time of the specified local
- ** time on that day, add the transition time and the current offset
- ** from GMT.
- */
- return value + rulep->r_time + offset;
-}
-
-/*
-** Given a POSIX section 8-style TZ string, fill in the rule tables as
-** appropriate.
-*/
-
-static int
-tzparse(const char *name, struct state * CPP_CONST sp, const int lastditch)
-{
- const char * stdname;
- const char * dstname=0;
- int stdlen;
- int dstlen;
- long stdoffset;
- long dstoffset;
- time_t * atp;
- unsigned char * typep;
- char * cp;
- int load_result;
-
- stdname = name;
- if (lastditch)
- {
- stdlen = strlen(name); /* length of standard zone name */
- name += stdlen;
- if (stdlen >= (int)sizeof sp->chars)
- stdlen = (int)(sizeof sp->chars) - 1;
- }
- else
- {
- name = getzname(name);
- stdlen = name - stdname;
- if (stdlen < 3)
- return -1;
- }
- if (*name == '\0')
- return -1;
- else
- {
- name = getoffset(name, &stdoffset);
- if (name == NULL)
- return -1;
- }
- load_result = tzload(TZDEFRULES, sp);
- if (load_result != 0)
- 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 */
- if (dstlen < 3)
- return -1;
- if (*name != '\0' && *name != ',' && *name != ';')
- {
- name = getoffset(name, &dstoffset);
- if (name == NULL)
- return -1;
- }
- else
- dstoffset = stdoffset - SECSPERHOUR;
- if (*name == ',' || *name == ';')
- {
- struct rule start;
- struct rule end;
- int year;
- time_t janfirst;
- time_t starttime;
- time_t endtime;
-
- ++name;
- if ((name = getrule(name, &start)) == NULL)
- return -1;
- if (*name++ != ',')
- return -1;
- if ((name = getrule(name, &end)) == NULL)
- return -1;
- if (*name != '\0')
- 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;
- sp->ttis[0].tt_gmtoff = -dstoffset;
- sp->ttis[0].tt_isdst = 1;
- sp->ttis[0].tt_abbrind = stdlen + 1;
- sp->ttis[1].tt_gmtoff = -stdoffset;
- sp->ttis[1].tt_isdst = 0;
- sp->ttis[1].tt_abbrind = 0;
- atp = sp->ats;
- typep = sp->types;
- 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;
- }
- }
- else
- {
- int sawstd;
- int sawdst;
- long stdfix;
- long dstfix;
- long oldfix;
- int isdst;
- int i;
-
- if (*name != '\0')
- return -1;
- if (load_result != 0)
- return -1;
- /*
- ** Compute the difference between the real and
- ** prototype standard and summer time offsets
- ** from GMT, and put the real standard and summer
- ** time offsets into the rules in place of the
- ** prototype offsets.
- */
- sawstd = FALSE;
- sawdst = FALSE;
- stdfix = 0;
- 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;
- }
- }
- /*
- ** Make sure we have both standard and summer time.
- */
- if (!sawdst || !sawstd)
- return -1;
- /*
- ** Now correct the transition times by shifting
- ** them by the difference between the real and
- ** prototype offsets. Note that this difference
- ** can be different in standard and summer time;
- ** the prototype probably has a 1-hour difference
- ** between standard and summer time, but a different
- ** difference can be specified in TZ.
- */
- 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;
- }
- }
- }
- else
- {
- dstlen = 0;
- sp->typecnt = 1; /* only standard time */
- sp->timecnt = 0;
- sp->ttis[0].tt_gmtoff = -stdoffset;
- sp->ttis[0].tt_isdst = 0;
- sp->ttis[0].tt_abbrind = 0;
- }
- sp->charcnt = stdlen + 1;
- if (dstlen != 0)
- sp->charcnt += dstlen + 1;
- if (sp->charcnt > (int)sizeof sp->chars)
- return -1;
- cp = sp->chars;
- (void) strncpy(cp, stdname, stdlen);
- cp += stdlen;
- *cp++ = '\0';
- if (dstlen != 0)
- {
- (void) strncpy(cp, dstname, dstlen);
- *(cp + dstlen) = '\0';
- }
- return 0;
-}
-
-static void
-gmtload(struct state * CPP_CONST sp)
-{
- if (tzload(GMT, sp) != 0)
- (void) tzparse(GMT, sp, TRUE);
-}
-
-/*
- * @implemented
- */
-void
-_tzset(void)
-{
- const char * name;
-
- name = getenv("TZ");
- if (name == NULL)
- {
- tzsetwall();
- return;
- }
- lcl_is_set = TRUE;
-#ifdef ALL_STATE
- if (lclptr == NULL)
- {
- lclptr = (struct state *) malloc(sizeof *lclptr);
- if (lclptr == NULL)
- {
- settzname(); /* all we can do */
- return;
- }
- }
-#endif /* defined ALL_STATE */
- if (*name == '\0')
- {
- /*
- ** User wants it fast rather than right.
- */
- lclptr->leapcnt = 0; /* so, we're off a little */
- lclptr->timecnt = 0;
- lclptr->ttis[0].tt_gmtoff = 0;
- lclptr->ttis[0].tt_abbrind = 0;
- (void) strcpy(lclptr->chars, GMT);
- }
- else if (tzload(name, lclptr) != 0)
- if (name[0] == ':' || tzparse(name, lclptr, FALSE) != 0)
- gmtload(lclptr);
- settzname();
-}
-
-void
-tzsetwall(void)
-{
- lcl_is_set = TRUE;
-#ifdef ALL_STATE
- if (lclptr == NULL)
- {
- lclptr = (struct state *) malloc(sizeof *lclptr);
- if (lclptr == NULL)
- {
- settzname(); /* all we can do */
- return;
- }
- }
-#endif /* defined ALL_STATE */
- if (tzload((char *) NULL, lclptr) != 0)
- gmtload(lclptr);
- settzname();
-}
-
-/*
-** The easy way to behave "as if no library function calls" localtime
-** is to not call it--so we drop its guts into "localsub", which can be
-** freely called. (And no, the PANS doesn't require the above behavior--
-** but it *is* desirable.)
-**
-** The unused offset argument is for the benefit of mktime variants.
-*/
-
-/*ARGSUSED*/
-static void
-localsub(const time_t * CPP_CONST timep, const long offset, struct tm * CPP_CONST tmp)
-{
- const struct state * sp;
- const struct ttinfo * ttisp;
- int i;
- const time_t t = *timep;
-
- if (!lcl_is_set)
- _tzset();
- sp = lclptr;
-#ifdef ALL_STATE
- if (sp == NULL)
- {
- gmtsub(timep, offset, tmp);
- return;
- }
-#endif /* defined ALL_STATE */
- if (sp->timecnt == 0 || t < sp->ats[0])
- {
- i = 0;
- while (sp->ttis[i].tt_isdst)
- if (++i >= sp->typecnt)
- {
- i = 0;
- break;
- }
- }
- else
- {
- for (i = 1; i < sp->timecnt; ++i)
- if (t < sp->ats[i])
- break;
- i = sp->types[i - 1];
- }
- ttisp = &sp->ttis[i];
- /*
- ** To get (wrong) behavior that's compatible with System V Release 2.0
- ** you'd replace the statement below with
- ** t += ttisp->tt_gmtoff;
- ** timesub(&t, 0L, sp, tmp);
- */
- timesub(&t, ttisp->tt_gmtoff, sp, tmp);
- tmp->tm_isdst = ttisp->tt_isdst;
- _tzname[tmp->tm_isdst] = (char *)&sp->chars[ttisp->tt_abbrind];
-#if 0
-/* tm_zone doesnt exist in windows msvcrt -Gunnar */
- tmp->tm_zone = (char *)&sp->chars[ttisp->tt_abbrind];
-#endif
-}
-
-/*
- * @implemented
- */
-struct tm *
-localtime(const time_t * CPP_CONST timep)
-{
- static struct tm tm;
-
- localsub(timep, 0L, &tm);
- return &tm;
-}
-
-/*
-** gmtsub is to gmtime as localsub is to localtime.
-*/
-
-static void
-gmtsub(const time_t * CPP_CONST timep, const long offset, struct tm * CPP_CONST tmp)
-{
- if (!gmt_is_set)
- {
- gmt_is_set = TRUE;
-#ifdef ALL_STATE
- gmtptr = (struct state *) malloc(sizeof *gmtptr);
- if (gmtptr != NULL)
-#endif /* defined ALL_STATE */
- gmtload(gmtptr);
- }
- timesub(timep, offset, gmtptr, tmp);
- /*
- ** Could get fancy here and deliver something such as
- ** "GMT+xxxx" or "GMT-xxxx" if offset is non-zero,
- ** but this is no time for a treasure hunt.
- */
-#if 0
-/* tm_zone doesnt exist in windows msvcrt -Gunnar */
- if (offset != 0)
- tmp->tm_zone = TZ_NAME;
- else
- {
-#ifdef ALL_STATE
- if (gmtptr == NULL)
- tmp->TM_ZONE = GMT;
- else
- tmp->TM_ZONE = gmtptr->chars;
-#endif /* defined ALL_STATE */
-#ifndef ALL_STATE
- tmp->tm_zone = gmtptr->chars;
-#endif /* State Farm */
- }
-#endif /* if 0 */
-}
-
-/*
- * @implemented
- */
-struct tm *
-gmtime(const time_t * CPP_CONST timep)
-{
- static struct tm tm;
-
- gmtsub(timep, 0L, &tm);
- return &tm;
-}
-
-static void
-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;
- long rem;
- int y;
- int yleap;
- const int * ip;
- long corr;
- int hit;
- int i;
-
- corr = 0;
- hit = FALSE;
-#ifdef ALL_STATE
- i = (sp == NULL) ? 0 : sp->leapcnt;
-#endif /* defined ALL_STATE */
-#ifndef ALL_STATE
- i = sp->leapcnt;
-#endif /* State Farm */
- while (--i >= 0)
- {
- lp = &sp->lsis[i];
- 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);
- corr = lp->ls_corr;
- break;
- }
- }
- days = *timep / SECSPERDAY;
- rem = *timep % SECSPERDAY;
-#ifdef mc68k
- if (*timep == 0x80000000)
- {
- /*
- ** A 3B1 muffs the division on the most negative number.
- */
- days = -24855;
- rem = -11648;
- }
-#endif /* mc68k */
- rem += (offset - corr);
- while (rem < 0)
- {
- rem += SECSPERDAY;
- --days;
- }
- while (rem >= SECSPERDAY)
- {
- rem -= SECSPERDAY;
- ++days;
- }
- tmp->tm_hour = (int) (rem / SECSPERHOUR);
- rem = rem % SECSPERHOUR;
- tmp->tm_min = (int) (rem / SECSPERMIN);
- tmp->tm_sec = (int) (rem % SECSPERMIN);
- if (hit)
- /*
- ** A positive leap second requires a special
- ** representation. This uses "... ??:59:60".
- */
- ++(tmp->tm_sec);
- tmp->tm_wday = (int) ((EPOCH_WDAY + days) % DAYSPERWEEK);
- if (tmp->tm_wday < 0)
- tmp->tm_wday += DAYSPERWEEK;
- y = EPOCH_YEAR;
- if (days >= 0)
- for ( ; ; )
- {
- yleap = isleap(y);
- if (days < (long) year_lengths[yleap])
- break;
- ++y;
- days = days - (long) year_lengths[yleap];
- }
- else
- do {
- --y;
- yleap = isleap(y);
- days = days + (long) year_lengths[yleap];
- } while (days < 0);
- tmp->tm_year = y - TM_YEAR_BASE;
- tmp->tm_yday = (int) days;
- ip = mon_lengths[yleap];
- for (tmp->tm_mon = 0; days >= (long) ip[tmp->tm_mon]; ++(tmp->tm_mon))
- days = days - (long) ip[tmp->tm_mon];
- tmp->tm_mday = (int) (days + 1);
- tmp->tm_isdst = 0;
-#if 0
-/* tm_gmtoff doesnt exist in windows msvcrt -Gunnar */
- tmp->tm_gmtoff = offset;
-#endif
-}
-
-/*
-** A la X3J11
-*/
-
-/*
- * @implemented
- */
-char *
-asctime(const struct tm *timeptr)
-{
- static const char wday_name[DAYSPERWEEK][3] = {
- "Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"
- };
- static const char mon_name[MONSPERYEAR][3] = {
- "Jan", "Feb", "Mar", "Apr", "May", "Jun",
- "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"
- };
- static char result[26];
- char* res = result;
-
- /* Check for invalid input time */
- if (timeptr->tm_year <= 69)
- {
- res = NULL;
- }
- else
- {
- sprintf(res, "%.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 res;
-}
-
-/*
- * @implemented
- */
-char *
-ctime(const time_t * CPP_CONST timep)
-{
- return asctime(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).
-*/
-
-#ifndef WRONG
-#define WRONG (-1)
-#endif /* !defined WRONG */
-
-static void
-normalize(int * CPP_CONST tensptr, int * CPP_CONST unitsptr, const int base)
-{
- if (*unitsptr >= base)
- {
- *tensptr += *unitsptr / base;
- *unitsptr %= base;
- }
- else if (*unitsptr < 0)
- {
- --*tensptr;
- *unitsptr += base;
- if (*unitsptr < 0)
- {
- *tensptr -= 1 + (-*unitsptr) / base;
- *unitsptr = base - (-*unitsptr) % base;
- }
- }
-}
-
-static int
-tmcomp(const struct tm * CPP_CONST atmp, const struct tm * CPP_CONST btmp)
-{
- int result;
-
- if ((result = (atmp->tm_year - btmp->tm_year)) == 0 &&
- (result = (atmp->tm_mon - btmp->tm_mon)) == 0 &&
- (result = (atmp->tm_mday - btmp->tm_mday)) == 0 &&
- (result = (atmp->tm_hour - btmp->tm_hour)) == 0 &&
- (result = (atmp->tm_min - btmp->tm_min)) == 0)
- result = atmp->tm_sec - btmp->tm_sec;
- return result;
-}
-
-static time_t
-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;
- int bits;
- int i, j ;
- int saved_seconds;
- time_t newt;
- time_t t;
-
- /* GCC complaints that it may be used uninitialized */
- struct tm yourtm, mytm = { 0, 0, 0, 0, 0, 0, 0, 0, 0 };
-
- *okayp = FALSE;
- yourtm = *tmp;
- if (yourtm.tm_sec >= SECSPERMIN + 2 || yourtm.tm_sec < 0)
- normalize(&yourtm.tm_min, &yourtm.tm_sec, SECSPERMIN);
- normalize(&yourtm.tm_hour, &yourtm.tm_min, MINSPERHOUR);
- normalize(&yourtm.tm_mday, &yourtm.tm_hour, HOURSPERDAY);
- normalize(&yourtm.tm_year, &yourtm.tm_mon, MONSPERYEAR);
- while (yourtm.tm_mday <= 0)
- {
- --yourtm.tm_year;
- yourtm.tm_mday +=
- year_lengths[isleap(yourtm.tm_year + TM_YEAR_BASE)];
- }
- for ( ; ; )
- {
- i = mon_lengths[isleap(yourtm.tm_year +
- TM_YEAR_BASE)][yourtm.tm_mon];
- if (yourtm.tm_mday <= i)
- break;
- yourtm.tm_mday -= i;
- if (++yourtm.tm_mon >= MONSPERYEAR)
- {
- yourtm.tm_mon = 0;
- ++yourtm.tm_year;
- }
- }
- saved_seconds = yourtm.tm_sec;
- yourtm.tm_sec = 0;
- /*
- ** Calculate the number of magnitude bits in a time_t
- ** (this works regardless of whether time_t is
- ** signed or unsigned, though lint complains if unsigned).
- */
- for (bits = 0, t = 1; t > 0; ++bits, t <<= 1)
- ;
- /*
- ** 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);
- dir = tmcomp(&mytm, &yourtm);
- if (dir != 0)
- {
- if (bits-- < 0)
- return WRONG;
- if (bits < 0)
- --t;
- else if (dir > 0)
- t -= (time_t) 1 << bits;
- else t += (time_t) 1 << bits;
- continue;
- }
- if (yourtm.tm_isdst < 0 || mytm.tm_isdst == yourtm.tm_isdst)
- break;
- /*
- ** Right time, wrong type.
- ** Hunt for right time, right type.
- ** It's okay to guess wrong since the guess
- ** gets checked.
- */
- sp = (const struct state *)
- ((funcp == localsub) ? lclptr : gmtptr);
-#ifdef ALL_STATE
- if (sp == NULL)
- return WRONG;
-#endif /* defined ALL_STATE */
- for (i = 0; i < sp->typecnt; ++i)
- {
- if (sp->ttis[i].tt_isdst != yourtm.tm_isdst)
- 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;
- }
- }
- return WRONG;
- }
- label:
- t += saved_seconds;
- (*funcp)(&t, offset, tmp);
- *okayp = TRUE;
- return t;
-}
-
-static time_t
-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;
- int samei, otheri;
- int okay;
-
- if (tmp->tm_isdst > 1)
- tmp->tm_isdst = 1;
- t = time2(tmp, funcp, offset, &okay);
- if (okay || tmp->tm_isdst < 0)
- return t;
- /*
- ** We're supposed to assume that somebody took a time of one type
- ** and did some math on it that yielded a "struct tm" that's bad.
- ** We try to divine the type they started from and adjust to the
- ** type they need.
- */
- sp = (const struct state *) ((funcp == localsub) ? lclptr : gmtptr);
-#ifdef ALL_STATE
- if (sp == NULL)
- return WRONG;
-#endif /* defined ALL_STATE */
- for (samei = 0; samei < sp->typecnt; ++samei)
- {
- if (sp->ttis[samei].tt_isdst != tmp->tm_isdst)
- continue;
- for (otheri = 0; otheri < sp->typecnt; ++otheri)
- {
- if (sp->ttis[otheri].tt_isdst == tmp->tm_isdst)
- continue;
- tmp->tm_sec += sp->ttis[otheri].tt_gmtoff -
- sp->ttis[samei].tt_gmtoff;
- tmp->tm_isdst = !tmp->tm_isdst;
- t = time2(tmp, funcp, offset, &okay);
- if (okay)
- return t;
- tmp->tm_sec -= sp->ttis[otheri].tt_gmtoff -
- sp->ttis[samei].tt_gmtoff;
- tmp->tm_isdst = !tmp->tm_isdst;
- }
- }
- return WRONG;
-}
-
-/*
- * @implemented
- */
-time_t
-mktime(struct tm * tmp)
-{
- return time1(tmp, localsub, 0L);
-}
-
-/*
- * @implemented
- */
-char **
-__p__tzname(void)
-{
- return _tzname;
-}
-
-/*********************************************************************
- * _dstbias (MSVCRT.@)
- */
-long _dstbias = 0;
-
-/*********************************************************************
- * __p_dstbias (MSVCRT.@)
- */
-long * __p__dstbias(void)
-{
- return &_dstbias;
-}
diff --git a/reactos/lib/sdk/crt/time/difftime.c b/reactos/lib/sdk/crt/time/difftime.c
deleted file mode 100644
index 07889acd8c6..00000000000
--- a/reactos/lib/sdk/crt/time/difftime.c
+++ /dev/null
@@ -1,11 +0,0 @@
-/* Copyright (C) 1994 DJ Delorie, see COPYING.DJ for details */
-#include
-
-/*
- * @implemented
- */
-double
-difftime(time_t time1, time_t time2)
-{
- return (double)(time1 - time2);
-}
diff --git a/reactos/lib/sdk/crt/time/ftime.c b/reactos/lib/sdk/crt/time/ftime.c
deleted file mode 100644
index 02e3e01b95e..00000000000
--- a/reactos/lib/sdk/crt/time/ftime.c
+++ /dev/null
@@ -1,34 +0,0 @@
-/*
- * COPYRIGHT: See COPYING in the top level directory
- * PROJECT: ReactOS system libraries
- * FILE: lib/msvcrt/time/ftime.c
- * PURPOSE: Deprecated BSD library call
- * PROGRAMER: Art Yerkes
- * UPDATE HISTORY:
- * 07/15/03 -- Created
- */
-
-#include
-#include
-
-/* ftime (3) -- Obsolete BSD library function included in the SUS for copat.
- * Also present in msvcrt.dll as _ftime
- * See: http://www.opengroup.org/onlinepubs/007904957/functions/ftime.html */
-/*
- * @implemented
- */
-#undef _ftime
-void _ftime( struct _timeb *tm )
-{
- int ret = 0;
- SYSTEMTIME syst;
-
- GetSystemTime( &syst );
-
- if( ret == 0 ) {
- time( &tm->time );
- tm->millitm = syst.wMilliseconds;
-// tm->_timezone = 0; /* According to the open group, timezone and dstflag */
- tm->dstflag = 0; /* exist for compatibility, but are unspecified. */
- }
-}
diff --git a/reactos/lib/sdk/crt/time/posixrul.h b/reactos/lib/sdk/crt/time/posixrul.h
deleted file mode 100644
index 48c5ceeab0d..00000000000
--- a/reactos/lib/sdk/crt/time/posixrul.h
+++ /dev/null
@@ -1,49 +0,0 @@
-/* Copyright (C) 1995 DJ Delorie, see COPYING.DJ for details */
-/* generated with bin2h from DJGPP/zoneinfo/posixrules */
-
-unsigned char _posixrules_data[] = {
-0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,2,0,0,0,0,0,
-0,1,16,0,0,0,2,0,0,0,8,0,151,254,240,1,135,225,224,2,119,224,240,3,112,254,96,4,96,253,112,5,80,
-224,96,6,64,223,112,7,48,194,96,7,141,25,112,9,16,164,96,9,173,148,240,10,240,134,96,11,224,133,112,12,217,162,
-224,13,192,103,112,14,185,132,224,15,169,131,240,16,153,102,224,17,137,101,240,18,121,72,224,19,105,71,240,20,89,42,224,
-21,73,41,240,22,57,12,224,23,41,11,240,24,34,41,96,25,8,237,240,26,2,11,96,26,242,10,112,27,225,237,96,28,
-209,236,112,29,193,207,96,30,177,206,112,31,161,177,96,32,118,0,240,33,129,147,96,34,85,226,240,35,106,175,224,36,53,
-196,240,37,74,145,224,38,21,166,240,39,42,115,224,39,254,195,112,41,10,85,224,41,222,165,112,42,234,55,224,43,190,135,
-112,44,211,84,96,45,158,105,112,46,179,54,96,47,126,75,112,48,147,24,96,49,103,103,240,50,114,250,96,51,71,73,240,
-52,82,220,96,53,39,43,240,54,50,190,96,55,7,13,240,56,27,218,224,56,230,239,240,57,251,188,224,58,198,209,240,59,
-219,158,224,60,175,238,112,61,187,128,224,62,143,208,112,63,155,98,224,64,111,178,112,65,132,127,96,66,79,148,112,67,100,
-97,96,68,47,118,112,69,68,67,96,70,15,88,112,71,36,37,96,71,248,116,240,73,4,7,96,73,216,86,240,74,227,233,
-96,75,184,56,240,76,205,5,224,77,152,26,240,78,172,231,224,79,119,252,240,80,140,201,224,81,97,25,112,82,108,171,224,
-83,64,251,112,84,76,141,224,85,32,221,112,86,44,111,224,87,0,191,112,88,21,140,96,88,224,161,112,89,245,110,96,90,
-192,131,112,91,213,80,96,92,169,159,240,93,181,50,96,94,137,129,240,95,149,20,96,96,105,99,240,97,126,48,224,98,73,
-69,240,99,94,18,224,100,41,39,240,101,61,244,224,102,18,68,112,103,29,214,224,103,242,38,112,104,253,184,224,105,210,8,
-112,106,221,154,224,107,177,234,112,108,198,183,96,109,145,204,112,110,166,153,96,111,113,174,112,112,134,123,96,113,90,202,240,
-114,102,93,96,115,58,172,240,116,70,63,96,117,26,142,240,118,47,91,224,118,250,112,240,120,15,61,224,120,218,82,240,121,
-239,31,224,122,186,52,240,123,207,1,224,124,163,81,112,125,174,227,224,126,131,51,112,127,142,197,224,128,99,21,112,129,119,
-226,96,130,66,247,112,131,87,196,96,132,34,217,112,133,55,166,96,134,11,245,240,135,23,136,96,135,235,215,240,136,247,106,
-96,137,203,185,240,138,215,76,96,139,171,155,240,140,192,104,224,141,139,125,240,142,160,74,224,143,107,95,240,144,128,44,224,
-145,84,124,112,146,96,14,224,147,52,94,112,148,63,240,224,149,20,64,112,150,41,13,96,150,244,34,112,152,8,239,96,152,
-212,4,112,153,232,209,96,154,189,32,240,155,200,179,96,156,157,2,240,157,168,149,96,158,124,228,240,159,136,119,96,160,92,
-198,240,161,113,147,224,162,60,168,240,163,81,117,224,164,28,138,240,165,49,87,224,166,5,167,112,167,17,57,224,167,229,137,
-112,168,241,27,224,169,197,107,112,170,218,56,96,171,165,77,112,172,186,26,96,173,133,47,112,174,153,252,96,175,101,17,112,
-176,121,222,96,177,78,45,240,178,89,192,96,179,46,15,240,180,57,162,96,181,13,241,240,182,34,190,224,182,237,211,240,184,
-2,160,224,184,205,181,240,185,226,130,224,186,182,210,112,187,194,100,224,188,150,180,112,189,162,70,224,190,118,150,112,191,130,
-40,224,192,86,120,112,193,107,69,96,194,54,90,112,195,75,39,96,196,22,60,112,197,43,9,96,197,255,88,240,199,10,235,
-96,199,223,58,240,200,234,205,96,201,191,28,240,202,211,233,224,203,158,254,240,204,179,203,224,205,126,224,240,206,147,173,224,
-207,103,253,112,208,115,143,224,209,71,223,112,210,83,113,224,211,39,193,112,212,51,83,224,213,7,163,112,214,28,112,96,214,
-231,133,112,215,252,82,96,216,199,103,112,217,220,52,96,218,176,131,240,219,188,22,96,220,144,101,240,221,155,248,96,222,112,
-71,240,223,133,20,224,224,80,41,240,225,100,246,224,226,48,11,240,227,68,216,224,228,15,237,240,229,36,186,224,229,249,10,
-112,231,4,156,224,231,216,236,112,232,228,126,224,233,184,206,112,234,205,155,96,235,152,176,112,236,173,125,96,237,120,146,112,
-238,141,95,96,239,97,174,240,240,109,65,96,241,65,144,240,242,77,35,96,243,33,114,240,244,45,5,96,245,1,84,240,246,
-22,33,224,246,225,54,240,247,246,3,224,248,193,24,240,249,213,229,224,250,160,250,240,251,181,199,224,252,138,23,112,253,149,
-169,224,254,105,249,112,255,117,139,224,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,
-1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,
-0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,
-1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,
-0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,
-1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,
-0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,
-1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,
-0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,255,255,199,192,1,0,255,255,185,176,0,4,69,68,84,
-0,69,83,84,0,0,0
-};
diff --git a/reactos/lib/sdk/crt/time/strdate.c b/reactos/lib/sdk/crt/time/strdate.c
deleted file mode 100644
index 22c188f9ccf..00000000000
--- a/reactos/lib/sdk/crt/time/strdate.c
+++ /dev/null
@@ -1,23 +0,0 @@
-/*
- * COPYRIGHT: See COPYING in the top level directory
- * PROJECT: ReactOS system libraries
- * FILE: lib/msvcrt/time/strtime.c
- * PURPOSE: Fills a buffer with a formatted date representation
- * PROGRAMER: Ariadne
- * UPDATE HISTORY:
- * 28/12/98: Created
- */
-#include
-
-/*
- * @implemented
- */
-char* _strdate(char* date)
-{
- static const char format[] = "MM'/'dd'/'yy";
-
- GetDateFormatA(LOCALE_NEUTRAL, 0, NULL, format, date, 9);
-
- return date;
-
-}
diff --git a/reactos/lib/sdk/crt/time/strftime.c b/reactos/lib/sdk/crt/time/strftime.c
deleted file mode 100644
index 6321928f66a..00000000000
--- a/reactos/lib/sdk/crt/time/strftime.c
+++ /dev/null
@@ -1,260 +0,0 @@
-/* Copyright (C) 1994 DJ Delorie, see COPYING.DJ for details */
-
-#include
-
-#define TM_YEAR_BASE 1900
-
-static const char *afmt[] = {
- "Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat",
-};
-static const char *Afmt[] = {
- "Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday",
- "Saturday",
-};
-static const char *bfmt[] = {
- "Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep",
- "Oct", "Nov", "Dec",
-};
-static const char *Bfmt[] = {
- "January", "February", "March", "April", "May", "June", "July",
- "August", "September", "October", "November", "December",
-};
-
-static size_t gsize;
-static char *pt;
-
-
-static int _add(const char* str)
-{
- for (;; ++pt, --gsize)
- {
- if (!gsize)
- return 0;
- if (!(*pt = *str++))
- return 1;
- }
-}
-
-static int _conv(int n, int digits, char pad)
-{
- static char buf[10];
- char *p;
-
- for (p = buf + sizeof(buf) - 2; n > 0 && p > buf; n /= 10, --digits)
- *p-- = n % 10 + '0';
- while (p > buf && digits-- > 0)
- *p-- = pad;
- return _add(++p);
-}
-
-static size_t _fmt(const char* format, const struct tm* t)
-{
- for (; *format; ++format)
- {
- if (*format == '%') {
- if (*(format+1) == '#' ) {format++;}
-
- switch(*++format) {
- case '\0':
- --format;
- break;
- case 'A':
- if (t->tm_wday < 0 || t->tm_wday > 6)
- return 0;
- if (!_add(Afmt[t->tm_wday]))
- return 0;
- continue;
- case 'a':
- if (t->tm_wday < 0 || t->tm_wday > 6)
- return 0;
- if (!_add(afmt[t->tm_wday]))
- return 0;
- continue;
- case 'B':
- if (t->tm_mon < 0 || t->tm_mon > 11)
- return 0;
- if (!_add(Bfmt[t->tm_mon]))
- return 0;
- continue;
- case 'b':
- case 'h':
- if (t->tm_mon < 0 || t->tm_mon > 11)
- return 0;
- if (!_add(bfmt[t->tm_mon]))
- return 0;
- continue;
- case 'C':
- if (!_fmt("%a %b %e %H:%M:%S %Y", t))
- return 0;
- continue;
- case 'c':
- if (!_fmt("%m/%d/%y %H:%M:%S", t))
- return 0;
- continue;
- case 'e':
- if (!_conv(t->tm_mday, 2, ' '))
- return 0;
- continue;
- case 'D':
- if (!_fmt("%m/%d/%y", t))
- return 0;
- continue;
- case 'd':
- if (!_conv(t->tm_mday, 2, '0'))
- return 0;
- continue;
- case 'H':
- if (!_conv(t->tm_hour, 2, '0'))
- return 0;
- continue;
- case 'I':
- if (!_conv(t->tm_hour % 12 ? t->tm_hour % 12 : 12, 2, '0'))
- return 0;
- continue;
- case 'j':
- if (!_conv(t->tm_yday + 1, 3, '0'))
- return 0;
- continue;
- case 'k':
- if (!_conv(t->tm_hour, 2, ' '))
- return 0;
- continue;
- case 'l':
- if (!_conv(t->tm_hour % 12 ? t->tm_hour % 12 : 12, 2, ' '))
- return 0;
- continue;
- case 'M':
- if (!_conv(t->tm_min, 2, '0'))
- return 0;
- continue;
- case 'm':
- if (!_conv(t->tm_mon + 1, 2, '0'))
- return 0;
- continue;
- case 'n':
- if (!_add("\n"))
- return 0;
- continue;
- case 'p':
- if (!_add(t->tm_hour >= 12 ? "PM" : "AM"))
- return 0;
- continue;
- case 'R':
- if (!_fmt("%H:%M", t))
- return 0;
- continue;
- case 'r':
- if (!_fmt("%I:%M:%S %p", t))
- return 0;
- continue;
- case 'S':
- if (!_conv(t->tm_sec, 2, '0'))
- return 0;
- continue;
- case 'T':
- case 'X':
- if (!_fmt("%H:%M:%S", t))
- return 0;
- continue;
- case 't':
- if (!_add("\t"))
- return 0;
- continue;
- case 'U':
- if (!_conv((t->tm_yday + 7 - t->tm_wday) / 7, 2, '0'))
- return 0;
- continue;
- case 'W':
- if (!_conv((t->tm_yday + 7 - (t->tm_wday ? (t->tm_wday - 1) : 6)) / 7, 2, '0'))
- return 0;
- continue;
- case 'w':
- if (!_conv(t->tm_wday, 1, '0'))
- return 0;
- continue;
- case 'x':
- if (!_fmt("%m/%d/%y", t))
- return 0;
- continue;
- case 'y':
- if (!_conv((t->tm_year + TM_YEAR_BASE) % 100, 2, '0'))
- return 0;
- continue;
- case 'Y':
- if (!_conv(t->tm_year + TM_YEAR_BASE, 4, '0'))
- return 0;
- continue;
- case 'Z':
-#if 0
- /* FIXME: tm_zone doesnt exist in windows */
- if (!t->tm_zone || !_add(t->tm_zone))
-#endif
- return 0;
- continue;
- case '%':
- /*
- * X311J/88-090 (4.12.3.5): if conversion char is
- * undefined, behavior is undefined. Print out the
- * character itself as printf(3) does.
- */
- default:
- break;
- }
- }
- if (!gsize--)
- return 0;
- *pt++ = *format;
- }
- return gsize;
-}
-
-/*
- * @implemented
- */
-size_t
-strftime(char *s, size_t maxsize, const char *format, const struct tm *t)
-{
- pt = s;
- if ((gsize = maxsize) < 1)
- return 0;
- if (_fmt(format, t))
- {
- *pt = '\0';
- return maxsize - gsize;
- }
- return 0;
-}
-
-/*
- * @implemented
- */
-size_t wcsftime(wchar_t* s, size_t maxsize, const wchar_t* format, const struct tm* t)
-{
- char *x;
- char *f;
- size_t i,j;
- if ((gsize = maxsize) < 1)
- return 0;
- x = malloc(maxsize);
- j = wcslen(format);
- f = malloc(j+1);
- for(i=0;i
-
-/*
- * @implemented
- */
-char* _strtime(char* time)
-{
- static const char format[] = "HH':'mm':'ss";
-
- GetTimeFormatA(LOCALE_NEUTRAL, 0, NULL, format, time, 9);
-
- return time;
-}
diff --git a/reactos/lib/sdk/crt/time/time.c b/reactos/lib/sdk/crt/time/time.c
deleted file mode 100644
index 93d9ee10231..00000000000
--- a/reactos/lib/sdk/crt/time/time.c
+++ /dev/null
@@ -1,222 +0,0 @@
-/*
- * COPYRIGHT: See COPYING in the top level directory
- * PROJECT: ReactOS system libraries
- * FILE: lib/msvcrt/time/time.c
- * PURPOSE: Get system time
- * PROGRAMER: Ariadne
- * UPDATE HISTORY:
- * 28/12/98: Created
- */
-/*
- * DOS file system functions
- *
- * Copyright 1993 Erik Bos
- * Copyright 1996 Alexandre Julliard
- */
-
-#include
-
-VOID WINAPI GetSystemTimeAsFileTime(LPFILETIME lpSystemTimeAsFileTime);
-
-/*
- * @implemented
- */
-time_t time(time_t* t)
-{
- FILETIME SystemTime;
- DWORD Remainder;
- time_t tt;
- GetSystemTimeAsFileTime(&SystemTime);
- tt = FileTimeToUnixTime(&SystemTime,&Remainder);
- if (t)
- *t = tt;
- return tt;
-}
-
-/***********************************************************************
- * DOSFS_UnixTimeToFileTime
- *
- * Convert a Unix time to FILETIME format.
- * The FILETIME structure is a 64-bit value representing the number of
- * 100-nanosecond intervals since January 1, 1601, 0:00.
- * 'remainder' is the nonnegative number of 100-ns intervals
- * corresponding to the time fraction smaller than 1 second that
- * couldn't be stored in the time_t value.
- */
-void UnixTimeToFileTime( time_t unix_time, FILETIME *filetime,
- DWORD remainder )
-{
- /* NOTES:
-
- CONSTANTS:
- The time difference between 1 January 1601, 00:00:00 and
- 1 January 1970, 00:00:00 is 369 years, plus the leap years
- from 1604 to 1968, excluding 1700, 1800, 1900.
- This makes (1968 - 1600) / 4 - 3 = 89 leap days, and a total
- of 134774 days.
-
- Any day in that period had 24 * 60 * 60 = 86400 seconds.
-
- The time difference is 134774 * 86400 * 10000000, which can be written
- 116444736000000000
- 27111902 * 2^32 + 3577643008
- 413 * 2^48 + 45534 * 2^32 + 54590 * 2^16 + 32768
-
- If you find that these constants are buggy, please change them in all
- instances in both conversion functions.
-
- VERSIONS:
- There are two versions, one of them uses long long variables and
- is presumably faster but not ISO C. The other one uses standard C
- data types and operations but relies on the assumption that negative
- numbers are stored as 2's complement (-1 is 0xffff....). If this
- assumption is violated, dates before 1970 will not convert correctly.
- This should however work on any reasonable architecture where WINE
- will run.
-
- DETAILS:
-
- Take care not to remove the casts. I have tested these functions
- (in both versions) for a lot of numbers. I would be interested in
- results on other compilers than GCC.
-
- The operations have been designed to account for the possibility
- of 64-bit time_t in future UNICES. Even the versions without
- internal long long numbers will work if time_t only is 64 bit.
- A 32-bit shift, which was necessary for that operation, turned out
- not to work correctly in GCC, besides giving the warning. So I
- used a double 16-bit shift instead. Numbers are in the ISO version
- represented by three limbs, the most significant with 32 bit, the
- other two with 16 bit each.
-
- As the modulo-operator % is not well-defined for negative numbers,
- negative divisors have been avoided in DOSFS_FileTimeToUnixTime.
-
- There might be quicker ways to do this in C. Certainly so in
- assembler.
-
- Claus Fischer, fischer@iue.tuwien.ac.at
- */
-
-
-
-
- unsigned long a0; /* 16 bit, low bits */
- unsigned long a1; /* 16 bit, medium bits */
- unsigned long a2; /* 32 bit, high bits */
-
- /* Copy the unix time to a2/a1/a0 */
- a0 = unix_time & 0xffff;
- a1 = (unix_time >> 16) & 0xffff;
- /* This is obsolete if unix_time is only 32 bits, but it does not hurt.
- Do not replace this by >> 32, it gives a compiler warning and it does
- not work. */
- a2 = (unix_time >= 0 ? (unix_time >> 16) >> 16 :
- ~((~unix_time >> 16) >> 16));
-
- /* Multiply a by 10000000 (a = a2/a1/a0)
- Split the factor into 10000 * 1000 which are both less than 0xffff. */
- a0 *= 10000;
- a1 = a1 * 10000 + (a0 >> 16);
- a2 = a2 * 10000 + (a1 >> 16);
- a0 &= 0xffff;
- a1 &= 0xffff;
-
- a0 *= 1000;
- a1 = a1 * 1000 + (a0 >> 16);
- a2 = a2 * 1000 + (a1 >> 16);
- a0 &= 0xffff;
- a1 &= 0xffff;
-
- /* Add the time difference and the remainder */
- a0 += 32768 + (remainder & 0xffff);
- a1 += 54590 + (remainder >> 16 ) + (a0 >> 16);
- a2 += 27111902 + (a1 >> 16);
- a0 &= 0xffff;
- a1 &= 0xffff;
-
- /* Set filetime */
- filetime->dwLowDateTime = (a1 << 16) + a0;
- filetime->dwHighDateTime = a2;
-}
-
-
-/***********************************************************************
- * DOSFS_FileTimeToUnixTime
- *
- * Convert a FILETIME format to Unix time.
- * If not NULL, 'remainder' contains the fractional part of the filetime,
- * in the range of [0..9999999] (even if time_t is negative).
- */
-time_t FileTimeToUnixTime( const FILETIME *filetime, DWORD *remainder )
-{
- /* Read the comment in the function DOSFS_UnixTimeToFileTime. */
-
- unsigned long a0; /* 16 bit, low bits */
- unsigned long a1; /* 16 bit, medium bits */
- unsigned long a2; /* 32 bit, high bits */
- unsigned long r; /* remainder of division */
- unsigned int carry; /* carry bit for subtraction */
- int negative; /* whether a represents a negative value */
-
- /* Copy the time values to a2/a1/a0 */
- a2 = (unsigned long)filetime->dwHighDateTime;
- a1 = ((unsigned long)filetime->dwLowDateTime ) >> 16;
- a0 = ((unsigned long)filetime->dwLowDateTime ) & 0xffff;
-
- /* Subtract the time difference */
- if (a0 >= 32768 ) a0 -= 32768 , carry = 0;
- else a0 += (1 << 16) - 32768 , carry = 1;
-
- if (a1 >= 54590 + carry) a1 -= 54590 + carry, carry = 0;
- else a1 += (1 << 16) - 54590 - carry, carry = 1;
-
- a2 -= 27111902 + carry;
-
- /* If a is negative, replace a by (-1-a) */
- negative = (a2 >= ((unsigned long)1) << 31);
- if (negative)
- {
- /* Set a to -a - 1 (a is a2/a1/a0) */
- a0 = 0xffff - a0;
- a1 = 0xffff - a1;
- a2 = ~a2;
- }
-
- /* Divide a by 10000000 (a = a2/a1/a0), put the rest into r.
- Split the divisor into 10000 * 1000 which are both less than 0xffff. */
- a1 += (a2 % 10000) << 16;
- a2 /= 10000;
- a0 += (a1 % 10000) << 16;
- a1 /= 10000;
- r = a0 % 10000;
- a0 /= 10000;
-
- a1 += (a2 % 1000) << 16;
- a2 /= 1000;
- a0 += (a1 % 1000) << 16;
- a1 /= 1000;
- r += (a0 % 1000) * 10000;
- a0 /= 1000;
-
- /* If a was negative, replace a by (-1-a) and r by (9999999 - r) */
- if (negative)
- {
- /* Set a to -a - 1 (a is a2/a1/a0) */
- a0 = 0xffff - a0;
- a1 = 0xffff - a1;
- a2 = ~a2;
-
- r = 9999999 - r;
- }
-
- if (remainder) *remainder = r;
-
- /* Do not replace this by << 32, it gives a compiler warning and it does
- not work. */
- return ((((time_t)a2) << 16) << 16) + (a1 << 16) + a0;
-
-}
-
-
-
diff --git a/reactos/lib/sdk/crt/time/tz_vars.c b/reactos/lib/sdk/crt/time/tz_vars.c
deleted file mode 100644
index 05af8a4d1f4..00000000000
--- a/reactos/lib/sdk/crt/time/tz_vars.c
+++ /dev/null
@@ -1,35 +0,0 @@
-#include
-#include
-#include
-
-
-int _daylight;
-int _timezone;
-
-
-void _set_daylight_export(int value)
-{
- _daylight = value;
-}
-
-void _set_timezone_export(int value)
-{
- _timezone = value;
-}
-
-
-/*********************************************************************
- * __p_daylight (MSVCRT.@)
- */
-void* __p__daylight(void)
-{
- return &_daylight;
-}
-
-/*********************************************************************
- * __p__timezone (MSVCRT.@)
- */
-int* __p__timezone(void)
-{
- return &_timezone;
-}
diff --git a/reactos/lib/sdk/crt/time/tzfile.h b/reactos/lib/sdk/crt/time/tzfile.h
deleted file mode 100644
index 3999029adb9..00000000000
--- a/reactos/lib/sdk/crt/time/tzfile.h
+++ /dev/null
@@ -1,160 +0,0 @@
-/* Copyright (C) 1995 DJ Delorie, see COPYING.DJ for details */
-#ifndef __dj_include_tzfile_h__
-#define __dj_include_tzfile_h__
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-#ifndef __dj_ENFORCE_ANSI_FREESTANDING
-
-#ifndef __STRICT_ANSI__
-
-#ifndef _POSIX_SOURCE
-
-/*
- * Copyright (c) 1988 Regents of the University of California.
- * All rights reserved.
- *
- * This code is derived from software contributed to Berkeley by
- * Arthur David Olson of the National Cancer Institute.
- *
- * Redistribution and use in source and binary forms are permitted provided
- * that: (1) source distributions retain this entire copyright notice and
- * comment, and (2) distributions including binaries display the following
- * acknowledgement: ``This product includes software developed by the
- * University of California, Berkeley and its contributors'' in the
- * documentation or other materials provided with the distribution and in
- * all advertising materials mentioning features or use of this software.
- * Neither the name of the University nor the names of its contributors may
- * be used to endorse or promote products derived from this software without
- * specific prior written permission.
- * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR IMPLIED
- * WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF
- * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
- *
- * @(#)tzfile.h 5.9 (Berkeley) 6/11/90
- */
-
-/*
-** Information about time zone files.
-*/
-
- /* Time zone object file directory */
-#define TZDIR "/usr/share/zoneinfo"
-#define TZDEFAULT "/etc/localtime"
-#define TZDEFRULES "posixrules"
-
-/*
-** Each file begins with. . .
-*/
-
-struct tzhead {
- char tzh_reserved[24]; /* reserved for future use */
- 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 */
-};
-
-/*
-** . . .followed by. . .
-**
-** tzh_timecnt (char [4])s coded transition times a la time(2)
-** tzh_timecnt (unsigned char)s types of local time starting at above
-** tzh_typecnt repetitions of
-** one (char [4]) coded GMT offset in seconds
-** 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
-** one (char [4]) total correction after above
-** tzh_ttisstdcnt (char)s indexed by type; if TRUE, transition
-** time is standard time, if FALSE,
-** transition time is wall clock time
-** if absent, transition times are
-** assumed to be wall clock time
-*/
-
-/*
-** In the current implementation, "tzset()" refuses to deal with files that
-** exceed any of the limits below.
-*/
-
-/*
-** The TZ_MAX_TIMES value below is enough to handle a bit more than a
-** year's worth of solar time (corrected daily to the nearest second) or
-** 138 years of Pacific Presidential Election time
-** (where there are three time zone transitions every fourth year).
-*/
-#define TZ_MAX_TIMES 370
-
-#define NOSOLAR /* 4BSD doesn't currently handle solar time */
-
-#ifndef NOSOLAR
-#define TZ_MAX_TYPES 256 /* Limited by what (unsigned char)'s can hold */
-#else
-#define TZ_MAX_TYPES 10 /* Maximum number of local time types */
-#endif
-
-#define TZ_MAX_CHARS 50 /* Maximum number of abbreviation characters */
-
-#define TZ_MAX_LEAPS 50 /* Maximum number of leap second corrections */
-
-#define SECSPERMIN 60
-#define MINSPERHOUR 60
-#define HOURSPERDAY 24
-#define DAYSPERWEEK 7
-#define DAYSPERNYEAR 365
-#define DAYSPERLYEAR 366
-#define SECSPERHOUR (SECSPERMIN * MINSPERHOUR)
-#define SECSPERDAY ((long) SECSPERHOUR * HOURSPERDAY)
-#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_FRIDAY 5
-#define TM_SATURDAY 6
-
-#define TM_JANUARY 0
-#define TM_FEBRUARY 1
-#define TM_MARCH 2
-#define TM_APRIL 3
-#define TM_MAY 4
-#define TM_JUNE 5
-#define TM_JULY 6
-#define TM_AUGUST 7
-#define TM_SEPTEMBER 8
-#define TM_OCTOBER 9
-#define TM_NOVEMBER 10
-#define TM_DECEMBER 11
-
-#define TM_YEAR_BASE 1900
-
-#define EPOCH_YEAR 1970
-#define EPOCH_WDAY TM_THURSDAY
-
-/*
-** Accurate only for the past couple of centuries;
-** that will probably do.
-*/
-
-#define isleap(y) ((((y) % 4) == 0 && ((y) % 100) != 0) || ((y) % 400) == 0)
-
-#endif /* !_POSIX_SOURCE */
-#endif /* !__STRICT_ANSI__ */
-#endif /* !__dj_ENFORCE_ANSI_FREESTANDING */
-
-#ifndef __dj_ENFORCE_FUNCTION_CALLS
-#endif /* !__dj_ENFORCE_FUNCTION_CALLS */
-
-#ifdef __cplusplus
-}
-#endif
-
-#endif /* __dj_include_tzfile_h__ */
diff --git a/reactos/lib/sdk/crt/time/wctime.c b/reactos/lib/sdk/crt/time/wctime.c
deleted file mode 100644
index bb843508b31..00000000000
--- a/reactos/lib/sdk/crt/time/wctime.c
+++ /dev/null
@@ -1,72 +0,0 @@
-/* Copyright (C) 1995 DJ Delorie, see COPYING.DJ for details */
-/* This file has been modified by DJ Delorie. These modifications are
-** Copyright (C) 1995 DJ Delorie, 24 Kirsten Ave, Rochester NH,
-** 03867-2954, USA.
-*/
-
-/*
- * Copyright (c) 1987, 1989 Regents of the University of California.
- * All rights reserved.
- *
- * This code is derived from software contributed to Berkeley by
- * Arthur David Olson of the National Cancer Institute.
- *
- * Redistribution and use in source and binary forms are permitted provided
- * that: (1) source distributions retain this entire copyright notice and
- * comment, and (2) distributions including binaries display the following
- * acknowledgement: ``This product includes software developed by the
- * University of California, Berkeley and its contributors'' in the
- * documentation or other materials provided with the distribution and in
- * all advertising materials mentioning features or use of this software.
- * Neither the name of the University nor the names of its contributors may
- * be used to endorse or promote products derived from this software without
- * specific prior written permission.
- * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR IMPLIED
- * WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF
- * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
- */
-
-#include
-#include "tzfile.h"
-
-/*
- * @implemented
- */
-wchar_t* _wasctime(const struct tm* timeptr)
-{
-#ifdef __GNUC__
- 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"
- };
-#else
- static const wchar_t wday_name[DAYSPERWEEK][4] = {
- L"Sun", L"Mon", L"Tue", L"Wed", L"Thu", L"Fri", L"Sat"
- };
- static const wchar_t mon_name[MONSPERYEAR][4] = {
- L"Jan", L"Feb", L"Mar", L"Apr", L"May", L"Jun",
- L"Jul", L"Aug", L"Sep", L"Oct", L"Nov", L"Dec"
- };
-#endif
- 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);
- return result;
-}
-
-
-/*
- * @implemented
- */
-wchar_t* _wctime(const time_t* const timep)
-{
- return _wasctime(localtime(timep));
-}
diff --git a/reactos/lib/sdk/crt/time/wstrdate.c b/reactos/lib/sdk/crt/time/wstrdate.c
deleted file mode 100644
index a19e3b9d5d2..00000000000
--- a/reactos/lib/sdk/crt/time/wstrdate.c
+++ /dev/null
@@ -1,23 +0,0 @@
-/*
- * COPYRIGHT: See COPYING in the top level directory
- * PROJECT: ReactOS system libraries
- * FILE: lib/msvcrt/time/strtime.c
- * PURPOSE: Fills a buffer with a formatted date representation
- * PROGRAMER: Ariadne
- * UPDATE HISTORY:
- * 28/12/98: Created
- */
-#include
-
-/*
- * @implemented
- */
-wchar_t* _wstrdate(wchar_t* date)
-{
- static const WCHAR format[] = { 'M','M','\'','/','\'','d','d','\'','/','\'','y','y',0 };
-
- GetDateFormatW(LOCALE_NEUTRAL, 0, NULL, format, (LPWSTR)date, 9);
-
- return date;
-
-}
diff --git a/reactos/lib/sdk/crt/time/wstrtime.c b/reactos/lib/sdk/crt/time/wstrtime.c
deleted file mode 100644
index bc8f5bb3d50..00000000000
--- a/reactos/lib/sdk/crt/time/wstrtime.c
+++ /dev/null
@@ -1,22 +0,0 @@
-/*
- * COPYRIGHT: See COPYING in the top level directory
- * PROJECT: ReactOS system libraries
- * FILE: lib/msvcrt/time/strtime.c
- * PURPOSE: Fills a buffer with a formatted time representation
- * PROGRAMER: Ariadne
- * UPDATE HISTORY:
- * 28/12/98: Created
- */
-#include
-
-/*
- * @implemented
- */
-wchar_t* _wstrtime(wchar_t* time)
-{
- static const WCHAR format[] = { 'H','H','\'',':','\'','m','m','\'',':','\'','s','s',0 };
-
- GetTimeFormatW(LOCALE_NEUTRAL, 0, NULL, format, (LPWSTR)time, 9);
-
- return time;
-}