2009-01-19 22:05:27 +00:00
|
|
|
/*
|
2009-08-06 11:01:44 +00:00
|
|
|
* COPYRIGHT: LGPL, See LGPL.txt in the top level directory
|
2009-01-19 22:05:27 +00:00
|
|
|
* PROJECT: ReactOS CRT library
|
|
|
|
* FILE: lib/sdk/crt/time/gmtime.c
|
|
|
|
* PURPOSE: Implementation of gmtime, _gmtime32, _gmtime64
|
|
|
|
* PROGRAMERS: Timo Kreuzer
|
|
|
|
*/
|
|
|
|
#include <precomp.h>
|
|
|
|
|
|
|
|
unsigned int g_monthdays[13] = {0, 31, 59, 90, 120, 151, 181, 212, 243, 273, 304, 334, 365};
|
|
|
|
unsigned int g_lpmonthdays[13] = {0, 31, 60, 91, 121, 152, 182, 213, 244, 274, 305, 335, 366};
|
|
|
|
|
|
|
|
struct tm *
|
|
|
|
_gmtime_worker(struct tm *ptm, __time64_t time, int do_dst)
|
|
|
|
{
|
|
|
|
unsigned int days, daystoyear, dayinyear, leapdays, leapyears, years, month;
|
|
|
|
unsigned int secondinday, secondinhour;
|
|
|
|
unsigned int *padays;
|
|
|
|
|
|
|
|
if (time < 0)
|
|
|
|
{
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Divide into date and time */
|
2011-09-15 17:11:53 +00:00
|
|
|
days = (unsigned int)(time / SECONDSPERDAY);
|
2009-01-19 22:05:27 +00:00
|
|
|
secondinday = time % SECONDSPERDAY;
|
|
|
|
|
|
|
|
/* Shift to days from 1.1.1601 */
|
|
|
|
days += DIFFDAYS;
|
|
|
|
|
|
|
|
/* Calculate leap days passed till today */
|
|
|
|
leapdays = leapdays_passed(days);
|
|
|
|
|
|
|
|
/* Calculate number of full leap years passed */
|
|
|
|
leapyears = leapyears_passed(days);
|
|
|
|
|
|
|
|
/* Are more leap days passed than leap years? */
|
|
|
|
if (leapdays > leapyears)
|
|
|
|
{
|
|
|
|
/* Yes, we're in a leap year */
|
|
|
|
padays = g_lpmonthdays;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
/* No, normal year */
|
|
|
|
padays = g_monthdays;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Calculate year */
|
|
|
|
years = (days - leapdays) / 365;
|
|
|
|
ptm->tm_year = years - 299;
|
|
|
|
|
|
|
|
/* Calculate number of days till 1.1. of this year */
|
|
|
|
daystoyear = years * 365 + leapyears;
|
|
|
|
|
|
|
|
/* Calculate the day in this year */
|
|
|
|
dayinyear = days - daystoyear;
|
|
|
|
|
|
|
|
/* Shall we do DST corrections? */
|
|
|
|
ptm->tm_isdst = 0;
|
|
|
|
if (do_dst)
|
|
|
|
{
|
2011-09-15 17:11:53 +00:00
|
|
|
int yeartime = dayinyear * SECONDSPERDAY + secondinday ;
|
2009-01-19 22:05:27 +00:00
|
|
|
if (yeartime >= dst_begin && yeartime <= dst_end) // FIXME! DST in winter
|
|
|
|
{
|
|
|
|
time -= _dstbias;
|
2011-09-15 17:11:53 +00:00
|
|
|
days = (unsigned int)(time / SECONDSPERDAY + DIFFDAYS);
|
2009-01-19 22:05:27 +00:00
|
|
|
dayinyear = days - daystoyear;
|
|
|
|
ptm->tm_isdst = 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
ptm->tm_yday = dayinyear;
|
|
|
|
|
|
|
|
/* dayinyear < 366 => terminates with i <= 11 */
|
|
|
|
for (month = 0; dayinyear >= padays[month+1]; month++)
|
|
|
|
;
|
|
|
|
|
|
|
|
/* Set month and day in month */
|
|
|
|
ptm->tm_mon = month;
|
|
|
|
ptm->tm_mday = 1 + dayinyear - padays[month];
|
|
|
|
|
|
|
|
/* Get weekday */
|
2009-08-06 00:26:23 +00:00
|
|
|
ptm->tm_wday = (days + 1) % 7;
|
2009-01-19 22:05:27 +00:00
|
|
|
|
|
|
|
/* Calculate hour and second in hour */
|
|
|
|
ptm->tm_hour = secondinday / SECONDSPERHOUR;
|
|
|
|
secondinhour = secondinday % SECONDSPERHOUR;
|
|
|
|
|
|
|
|
/* Calculate minute and second */
|
|
|
|
ptm->tm_min = secondinhour / 60;
|
|
|
|
ptm->tm_sec = secondinhour % 60;
|
|
|
|
|
|
|
|
return ptm;
|
|
|
|
}
|
|
|
|
|
|
|
|
/******************************************************************************
|
|
|
|
* \name _gmtime64
|
2011-09-15 17:11:53 +00:00
|
|
|
* \brief
|
2009-01-19 22:05:27 +00:00
|
|
|
* \param ptime Pointer to a variable of type __time64_t containing the time.
|
|
|
|
*/
|
|
|
|
struct tm *
|
|
|
|
_gmtime64(const __time64_t * ptime)
|
|
|
|
{
|
2011-12-02 21:18:42 +00:00
|
|
|
thread_data_t *data = msvcrt_get_thread_data();
|
2009-01-19 22:05:27 +00:00
|
|
|
|
|
|
|
/* Validate parameters */
|
2011-11-05 10:24:24 +00:00
|
|
|
if (!ptime || *ptime < 0)
|
2009-01-19 22:05:27 +00:00
|
|
|
{
|
2011-11-05 10:24:24 +00:00
|
|
|
return NULL;
|
2009-01-19 22:05:27 +00:00
|
|
|
}
|
|
|
|
|
2011-12-02 21:18:42 +00:00
|
|
|
if(!data->time_buffer)
|
|
|
|
data->time_buffer = malloc(sizeof(struct tm));
|
2009-01-19 22:05:27 +00:00
|
|
|
|
2011-11-05 10:24:24 +00:00
|
|
|
/* Use _gmtime_worker to do the real work */
|
2011-12-02 21:18:42 +00:00
|
|
|
return _gmtime_worker(data->time_buffer, *ptime, 0);
|
2009-01-19 22:05:27 +00:00
|
|
|
}
|
|
|
|
|
[CRT]
- Update file.c to recent wine. (now with locking!)
- implement/enable __wcserror, __wcserror_s, _access_s, _ctime32_s, _ctime64_s,
_cwprintf, _fseeki64, _ftelli64, _get_osplatform, _get_output_format,
_get_pgmptr, _get_wpgmptr, _get_terminate, _get_tzname, _get_unexpected,
_gmtime64_s, _i64toa_s, _i64tow_s, _initterm_e, _itoa_s, _itow_s,
_localtime32_s, _localtime64_s, _ltoa_s, _ltow_s, _putwch, _searchenv_s,
_sopen_s, _ui64toa_s, _ui64tow_s, _vcwprintf, _vsprintf_p, _waccess_s,
_wcserror, _wcserror_s, _wfopen_s, _wsopen_s, fopen_s, fprintf_s, fwprintf_s,
printf_s, strerror_s, strncpy_s, strtok_s, vfprintf_s, vfwprintf_s, vprintf_s,
vwprintf_s, wcscat_s, wcsncat_s, wcstok_s, wprintf_s. Most code comes from
wine.
- Fix __set_errno -> _set_errno and export it.
- Remove unneeded files.
[CRT_HEADERS]
- add threadmbcinfo struct.
- update some sec_api headers from mingw64 due to missing or incorrect
functions.
Patch by Samuel Serapion.
Changes to msvcrt spec by me due to winebuild.
CRLF/LF fixes.
svn path=/trunk/; revision=54651
2011-12-14 22:09:24 +00:00
|
|
|
errno_t
|
|
|
|
_gmtime64_s(
|
|
|
|
struct tm* ptm,
|
|
|
|
const __time64_t* ptime)
|
|
|
|
{
|
2015-09-02 10:20:21 +00:00
|
|
|
__time64_t time;
|
|
|
|
|
[CRT]
- Update file.c to recent wine. (now with locking!)
- implement/enable __wcserror, __wcserror_s, _access_s, _ctime32_s, _ctime64_s,
_cwprintf, _fseeki64, _ftelli64, _get_osplatform, _get_output_format,
_get_pgmptr, _get_wpgmptr, _get_terminate, _get_tzname, _get_unexpected,
_gmtime64_s, _i64toa_s, _i64tow_s, _initterm_e, _itoa_s, _itow_s,
_localtime32_s, _localtime64_s, _ltoa_s, _ltow_s, _putwch, _searchenv_s,
_sopen_s, _ui64toa_s, _ui64tow_s, _vcwprintf, _vsprintf_p, _waccess_s,
_wcserror, _wcserror_s, _wfopen_s, _wsopen_s, fopen_s, fprintf_s, fwprintf_s,
printf_s, strerror_s, strncpy_s, strtok_s, vfprintf_s, vfwprintf_s, vprintf_s,
vwprintf_s, wcscat_s, wcsncat_s, wcstok_s, wprintf_s. Most code comes from
wine.
- Fix __set_errno -> _set_errno and export it.
- Remove unneeded files.
[CRT_HEADERS]
- add threadmbcinfo struct.
- update some sec_api headers from mingw64 due to missing or incorrect
functions.
Patch by Samuel Serapion.
Changes to msvcrt spec by me due to winebuild.
CRLF/LF fixes.
svn path=/trunk/; revision=54651
2011-12-14 22:09:24 +00:00
|
|
|
if (!ptm)
|
|
|
|
{
|
2014-05-10 20:38:26 +00:00
|
|
|
MSVCRT_INVALID_PMT("ptm == NULL", ERROR_BAD_COMMAND);
|
[CRT]
- Update file.c to recent wine. (now with locking!)
- implement/enable __wcserror, __wcserror_s, _access_s, _ctime32_s, _ctime64_s,
_cwprintf, _fseeki64, _ftelli64, _get_osplatform, _get_output_format,
_get_pgmptr, _get_wpgmptr, _get_terminate, _get_tzname, _get_unexpected,
_gmtime64_s, _i64toa_s, _i64tow_s, _initterm_e, _itoa_s, _itow_s,
_localtime32_s, _localtime64_s, _ltoa_s, _ltow_s, _putwch, _searchenv_s,
_sopen_s, _ui64toa_s, _ui64tow_s, _vcwprintf, _vsprintf_p, _waccess_s,
_wcserror, _wcserror_s, _wfopen_s, _wsopen_s, fopen_s, fprintf_s, fwprintf_s,
printf_s, strerror_s, strncpy_s, strtok_s, vfprintf_s, vfwprintf_s, vprintf_s,
vwprintf_s, wcscat_s, wcsncat_s, wcstok_s, wprintf_s. Most code comes from
wine.
- Fix __set_errno -> _set_errno and export it.
- Remove unneeded files.
[CRT_HEADERS]
- add threadmbcinfo struct.
- update some sec_api headers from mingw64 due to missing or incorrect
functions.
Patch by Samuel Serapion.
Changes to msvcrt spec by me due to winebuild.
CRLF/LF fixes.
svn path=/trunk/; revision=54651
2011-12-14 22:09:24 +00:00
|
|
|
return ERROR_BAD_COMMAND;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!ptime)
|
|
|
|
{
|
2014-05-10 20:38:26 +00:00
|
|
|
MSVCRT_INVALID_PMT("ptime == NULL", ERROR_BAD_COMMAND);
|
[CRT]
- Update file.c to recent wine. (now with locking!)
- implement/enable __wcserror, __wcserror_s, _access_s, _ctime32_s, _ctime64_s,
_cwprintf, _fseeki64, _ftelli64, _get_osplatform, _get_output_format,
_get_pgmptr, _get_wpgmptr, _get_terminate, _get_tzname, _get_unexpected,
_gmtime64_s, _i64toa_s, _i64tow_s, _initterm_e, _itoa_s, _itow_s,
_localtime32_s, _localtime64_s, _ltoa_s, _ltow_s, _putwch, _searchenv_s,
_sopen_s, _ui64toa_s, _ui64tow_s, _vcwprintf, _vsprintf_p, _waccess_s,
_wcserror, _wcserror_s, _wfopen_s, _wsopen_s, fopen_s, fprintf_s, fwprintf_s,
printf_s, strerror_s, strncpy_s, strtok_s, vfprintf_s, vfwprintf_s, vprintf_s,
vwprintf_s, wcscat_s, wcsncat_s, wcstok_s, wprintf_s. Most code comes from
wine.
- Fix __set_errno -> _set_errno and export it.
- Remove unneeded files.
[CRT_HEADERS]
- add threadmbcinfo struct.
- update some sec_api headers from mingw64 due to missing or incorrect
functions.
Patch by Samuel Serapion.
Changes to msvcrt spec by me due to winebuild.
CRLF/LF fixes.
svn path=/trunk/; revision=54651
2011-12-14 22:09:24 +00:00
|
|
|
return ERROR_BAD_COMMAND;
|
|
|
|
}
|
|
|
|
|
2015-09-02 10:20:21 +00:00
|
|
|
time = *ptime;
|
|
|
|
|
[CRT]
- Update file.c to recent wine. (now with locking!)
- implement/enable __wcserror, __wcserror_s, _access_s, _ctime32_s, _ctime64_s,
_cwprintf, _fseeki64, _ftelli64, _get_osplatform, _get_output_format,
_get_pgmptr, _get_wpgmptr, _get_terminate, _get_tzname, _get_unexpected,
_gmtime64_s, _i64toa_s, _i64tow_s, _initterm_e, _itoa_s, _itow_s,
_localtime32_s, _localtime64_s, _ltoa_s, _ltow_s, _putwch, _searchenv_s,
_sopen_s, _ui64toa_s, _ui64tow_s, _vcwprintf, _vsprintf_p, _waccess_s,
_wcserror, _wcserror_s, _wfopen_s, _wsopen_s, fopen_s, fprintf_s, fwprintf_s,
printf_s, strerror_s, strncpy_s, strtok_s, vfprintf_s, vfwprintf_s, vprintf_s,
vwprintf_s, wcscat_s, wcsncat_s, wcstok_s, wprintf_s. Most code comes from
wine.
- Fix __set_errno -> _set_errno and export it.
- Remove unneeded files.
[CRT_HEADERS]
- add threadmbcinfo struct.
- update some sec_api headers from mingw64 due to missing or incorrect
functions.
Patch by Samuel Serapion.
Changes to msvcrt spec by me due to winebuild.
CRLF/LF fixes.
svn path=/trunk/; revision=54651
2011-12-14 22:09:24 +00:00
|
|
|
_gmtime_worker(ptm, time, 0);
|
|
|
|
|
|
|
|
return ERROR_SUCCESS;
|
|
|
|
}
|
|
|
|
|
2009-01-19 22:05:27 +00:00
|
|
|
/******************************************************************************
|
|
|
|
* \name _gmtime32
|
2011-09-15 17:11:53 +00:00
|
|
|
* \brief
|
2009-01-19 22:05:27 +00:00
|
|
|
* \param ptime Pointer to a variable of type __time32_t containing the time.
|
|
|
|
*/
|
|
|
|
struct tm *
|
|
|
|
_gmtime32(const __time32_t * ptime)
|
|
|
|
{
|
2011-11-05 10:24:24 +00:00
|
|
|
__time64_t time64;
|
|
|
|
|
|
|
|
if (!ptime)
|
|
|
|
return NULL;
|
|
|
|
time64 = *ptime;
|
2009-01-19 22:05:27 +00:00
|
|
|
return _gmtime64(&time64);
|
|
|
|
}
|
|
|
|
|
[CRT]
- Update file.c to recent wine. (now with locking!)
- implement/enable __wcserror, __wcserror_s, _access_s, _ctime32_s, _ctime64_s,
_cwprintf, _fseeki64, _ftelli64, _get_osplatform, _get_output_format,
_get_pgmptr, _get_wpgmptr, _get_terminate, _get_tzname, _get_unexpected,
_gmtime64_s, _i64toa_s, _i64tow_s, _initterm_e, _itoa_s, _itow_s,
_localtime32_s, _localtime64_s, _ltoa_s, _ltow_s, _putwch, _searchenv_s,
_sopen_s, _ui64toa_s, _ui64tow_s, _vcwprintf, _vsprintf_p, _waccess_s,
_wcserror, _wcserror_s, _wfopen_s, _wsopen_s, fopen_s, fprintf_s, fwprintf_s,
printf_s, strerror_s, strncpy_s, strtok_s, vfprintf_s, vfwprintf_s, vprintf_s,
vwprintf_s, wcscat_s, wcsncat_s, wcstok_s, wprintf_s. Most code comes from
wine.
- Fix __set_errno -> _set_errno and export it.
- Remove unneeded files.
[CRT_HEADERS]
- add threadmbcinfo struct.
- update some sec_api headers from mingw64 due to missing or incorrect
functions.
Patch by Samuel Serapion.
Changes to msvcrt spec by me due to winebuild.
CRLF/LF fixes.
svn path=/trunk/; revision=54651
2011-12-14 22:09:24 +00:00
|
|
|
errno_t
|
|
|
|
_gmtime32_s(
|
|
|
|
struct tm* ptm,
|
|
|
|
const __time32_t* ptime)
|
|
|
|
{
|
|
|
|
__time64_t time = *ptime;
|
|
|
|
if (!ptm)
|
|
|
|
{
|
2014-05-10 20:38:26 +00:00
|
|
|
MSVCRT_INVALID_PMT("ptm == NULL", ERROR_BAD_COMMAND);
|
[CRT]
- Update file.c to recent wine. (now with locking!)
- implement/enable __wcserror, __wcserror_s, _access_s, _ctime32_s, _ctime64_s,
_cwprintf, _fseeki64, _ftelli64, _get_osplatform, _get_output_format,
_get_pgmptr, _get_wpgmptr, _get_terminate, _get_tzname, _get_unexpected,
_gmtime64_s, _i64toa_s, _i64tow_s, _initterm_e, _itoa_s, _itow_s,
_localtime32_s, _localtime64_s, _ltoa_s, _ltow_s, _putwch, _searchenv_s,
_sopen_s, _ui64toa_s, _ui64tow_s, _vcwprintf, _vsprintf_p, _waccess_s,
_wcserror, _wcserror_s, _wfopen_s, _wsopen_s, fopen_s, fprintf_s, fwprintf_s,
printf_s, strerror_s, strncpy_s, strtok_s, vfprintf_s, vfwprintf_s, vprintf_s,
vwprintf_s, wcscat_s, wcsncat_s, wcstok_s, wprintf_s. Most code comes from
wine.
- Fix __set_errno -> _set_errno and export it.
- Remove unneeded files.
[CRT_HEADERS]
- add threadmbcinfo struct.
- update some sec_api headers from mingw64 due to missing or incorrect
functions.
Patch by Samuel Serapion.
Changes to msvcrt spec by me due to winebuild.
CRLF/LF fixes.
svn path=/trunk/; revision=54651
2011-12-14 22:09:24 +00:00
|
|
|
return ERROR_BAD_COMMAND;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!ptime)
|
|
|
|
{
|
2014-05-10 20:38:26 +00:00
|
|
|
MSVCRT_INVALID_PMT("ptime == NULL", ERROR_BAD_COMMAND);
|
[CRT]
- Update file.c to recent wine. (now with locking!)
- implement/enable __wcserror, __wcserror_s, _access_s, _ctime32_s, _ctime64_s,
_cwprintf, _fseeki64, _ftelli64, _get_osplatform, _get_output_format,
_get_pgmptr, _get_wpgmptr, _get_terminate, _get_tzname, _get_unexpected,
_gmtime64_s, _i64toa_s, _i64tow_s, _initterm_e, _itoa_s, _itow_s,
_localtime32_s, _localtime64_s, _ltoa_s, _ltow_s, _putwch, _searchenv_s,
_sopen_s, _ui64toa_s, _ui64tow_s, _vcwprintf, _vsprintf_p, _waccess_s,
_wcserror, _wcserror_s, _wfopen_s, _wsopen_s, fopen_s, fprintf_s, fwprintf_s,
printf_s, strerror_s, strncpy_s, strtok_s, vfprintf_s, vfwprintf_s, vprintf_s,
vwprintf_s, wcscat_s, wcsncat_s, wcstok_s, wprintf_s. Most code comes from
wine.
- Fix __set_errno -> _set_errno and export it.
- Remove unneeded files.
[CRT_HEADERS]
- add threadmbcinfo struct.
- update some sec_api headers from mingw64 due to missing or incorrect
functions.
Patch by Samuel Serapion.
Changes to msvcrt spec by me due to winebuild.
CRLF/LF fixes.
svn path=/trunk/; revision=54651
2011-12-14 22:09:24 +00:00
|
|
|
return ERROR_BAD_COMMAND;
|
|
|
|
}
|
|
|
|
|
|
|
|
_gmtime_worker(ptm, time, 0);
|
|
|
|
|
|
|
|
return ERROR_SUCCESS;
|
|
|
|
}
|
|
|
|
|
2009-01-19 22:05:27 +00:00
|
|
|
/******************************************************************************
|
|
|
|
* \name gmtime
|
2011-09-15 17:11:53 +00:00
|
|
|
* \brief
|
2009-01-19 22:05:27 +00:00
|
|
|
* \param ptime Pointer to a variable of type time_t containing the time.
|
|
|
|
*/
|
|
|
|
struct tm *
|
|
|
|
gmtime(const time_t * ptime)
|
|
|
|
{
|
2011-11-05 10:24:24 +00:00
|
|
|
__time64_t time64;
|
|
|
|
|
|
|
|
if (!ptime)
|
|
|
|
return NULL;
|
|
|
|
time64 = *ptime;
|
2009-01-19 22:05:27 +00:00
|
|
|
return _gmtime64(&time64);
|
|
|
|
}
|