2001-01-10 23:59:25 +00:00
|
|
|
/*
|
|
|
|
* msvcrt.dll date/time functions
|
|
|
|
*
|
|
|
|
* Copyright 1996,1998 Marcus Meissner
|
|
|
|
* Copyright 1996 Jukka Iivonen
|
|
|
|
* Copyright 1997,2000 Uwe Bonnes
|
|
|
|
* Copyright 2000 Jon Griffiths
|
|
|
|
*/
|
|
|
|
#include <time.h>
|
|
|
|
#include <sys/times.h>
|
|
|
|
#include "msvcrt.h"
|
|
|
|
|
2001-04-10 23:25:25 +00:00
|
|
|
#include "msvcrt/stdlib.h"
|
|
|
|
#include "msvcrt/sys/timeb.h"
|
|
|
|
#include "msvcrt/time.h"
|
2001-01-10 23:59:25 +00:00
|
|
|
|
2001-04-10 23:25:25 +00:00
|
|
|
|
|
|
|
DEFAULT_DEBUG_CHANNEL(msvcrt);
|
2001-01-10 23:59:25 +00:00
|
|
|
|
|
|
|
|
|
|
|
/* INTERNAL: Return formatted current time/date */
|
2001-04-10 21:16:07 +00:00
|
|
|
char* msvcrt_get_current_time(char* out, const char* format)
|
2001-01-10 23:59:25 +00:00
|
|
|
{
|
2001-04-10 23:25:25 +00:00
|
|
|
static const MSVCRT_time_t bad_time = (MSVCRT_time_t)-1;
|
2001-01-10 23:59:25 +00:00
|
|
|
time_t t;
|
|
|
|
struct tm *_tm = NULL;
|
|
|
|
char *retval = NULL;
|
|
|
|
|
|
|
|
if (time(&t) != bad_time && (_tm = localtime(&t)) &&
|
|
|
|
strftime(out,9,format,_tm) == 8)
|
|
|
|
retval = out;
|
|
|
|
if (_tm)
|
|
|
|
MSVCRT_free(_tm);
|
|
|
|
return retval;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**********************************************************************
|
|
|
|
* _strdate (MSVCRT.@)
|
|
|
|
*/
|
2001-04-10 21:16:07 +00:00
|
|
|
char* _strdate(char* date)
|
2001-01-10 23:59:25 +00:00
|
|
|
{
|
2001-04-10 21:16:07 +00:00
|
|
|
return msvcrt_get_current_time(date,"%m/%d/%y");
|
2001-01-10 23:59:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*********************************************************************
|
|
|
|
* _strtime (MSVCRT.@)
|
|
|
|
*/
|
2001-04-10 21:16:07 +00:00
|
|
|
char* _strtime(char* date)
|
2001-01-10 23:59:25 +00:00
|
|
|
{
|
2001-04-10 21:16:07 +00:00
|
|
|
return msvcrt_get_current_time(date,"%H:%M:%S");
|
2001-01-10 23:59:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*********************************************************************
|
|
|
|
* clock (MSVCRT.@)
|
|
|
|
*/
|
2001-04-10 21:16:07 +00:00
|
|
|
clock_t MSVCRT_clock(void)
|
2001-01-10 23:59:25 +00:00
|
|
|
{
|
|
|
|
struct tms alltimes;
|
|
|
|
clock_t res;
|
|
|
|
|
|
|
|
times(&alltimes);
|
|
|
|
res = alltimes.tms_utime + alltimes.tms_stime +
|
|
|
|
alltimes.tms_cutime + alltimes.tms_cstime;
|
|
|
|
/* FIXME: We need some symbolic representation for CLOCKS_PER_SEC,
|
|
|
|
* 10 holds only for Windows/Linux_i86)
|
|
|
|
*/
|
|
|
|
return 10*res;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*********************************************************************
|
|
|
|
* difftime (MSVCRT.@)
|
|
|
|
*/
|
2001-04-10 23:25:25 +00:00
|
|
|
double MSVCRT_difftime(MSVCRT_time_t time1, MSVCRT_time_t time2)
|
2001-01-10 23:59:25 +00:00
|
|
|
{
|
|
|
|
return (double)(time1 - time2);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*********************************************************************
|
|
|
|
* time (MSVCRT.@)
|
|
|
|
*/
|
2001-04-10 23:25:25 +00:00
|
|
|
MSVCRT_time_t MSVCRT_time(MSVCRT_time_t* buf)
|
2001-01-10 23:59:25 +00:00
|
|
|
{
|
2001-04-10 23:25:25 +00:00
|
|
|
MSVCRT_time_t curtime = time(NULL);
|
2001-01-10 23:59:25 +00:00
|
|
|
return buf ? *buf = curtime : curtime;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*********************************************************************
|
|
|
|
* _ftime (MSVCRT.@)
|
|
|
|
*/
|
2001-04-10 23:25:25 +00:00
|
|
|
void _ftime(struct _timeb *buf)
|
2001-01-10 23:59:25 +00:00
|
|
|
{
|
|
|
|
buf->time = MSVCRT_time(NULL);
|
|
|
|
buf->millitm = 0; /* FIXME */
|
|
|
|
buf->timezone = 0;
|
|
|
|
buf->dstflag = 0;
|
|
|
|
}
|