- Add math calls: scalb, fpclass, nextafter, logb, _CI*
[wine] / dlls / crtdll / time.c
1 /*
2  * CRTDLL date/time functions
3  * 
4  * Copyright 1996,1998 Marcus Meissner
5  * Copyright 1996 Jukka Iivonen
6  * Copyright 1997,2000 Uwe Bonnes
7  * Copyright 2000 Jon Griffiths
8  *
9  * Implementation Notes:
10  * MT Safe.
11  */
12
13 #include "crtdll.h"
14 #include "process.h"
15 #include "options.h"
16 #include <stdlib.h>
17 #include <sys/times.h>
18
19
20 DEFAULT_DEBUG_CHANNEL(crtdll);
21
22
23 /* INTERNAL: Return formatted current time/date */
24 static LPSTR __CRTDLL__get_current_time(LPSTR out, const char * format);
25 static LPSTR __CRTDLL__get_current_time(LPSTR out, const char * format)
26 {
27   time_t t;
28   struct tm *_tm;
29
30   if ((time(&t) != ((time_t)-1)) &&
31       ((_tm = localtime(&t)) != 0) &&
32       (strftime(out,9,format,_tm) == 8))
33   {
34     CRTDLL_free(_tm);
35     return out;
36   }
37
38   return NULL;
39 }
40
41
42 /*********************************************************************
43  *                  _ftime      (CRTDLL.112)
44  *
45  * Get current time.
46  */
47 VOID __cdecl CRTDLL__ftime (struct _timeb* t)
48 {
49   t->time = CRTDLL_time(NULL);
50   t->millitm = 0; /* FIXME */
51   t->timezone = 0;
52   t->dstflag = 0;
53 }
54
55
56 /**********************************************************************
57  *                  _strdate          (CRTDLL.283)
58  *
59  * Return the current date as MM/DD/YY - (American Format)
60  */
61 LPSTR __cdecl CRTDLL__strdate (LPSTR date)
62 {
63   return __CRTDLL__get_current_time(date,"%m/%d/%y");
64 }
65
66
67 /*********************************************************************
68  *                  _strtime          (CRTDLL.299)
69  *
70  * Return the current time as HH:MM:SS
71  */
72 LPSTR __cdecl CRTDLL__strtime (LPSTR date)
73 {
74   return __CRTDLL__get_current_time(date,"%H:%M:%S");
75 }
76
77
78 /*********************************************************************
79  *                  clock         (CRTDLL.350)
80  */
81 clock_t __cdecl CRTDLL_clock(void)
82 {
83     struct tms alltimes;
84     clock_t res;
85
86     times(&alltimes);
87     res = alltimes.tms_utime + alltimes.tms_stime+
88         alltimes.tms_cutime + alltimes.tms_cstime;
89     /* Fixme: We need some symbolic representation
90        for (Hostsystem_)CLOCKS_PER_SEC 
91        and (Emulated_system_)CLOCKS_PER_SEC
92        10 holds only for Windows/Linux_i86)
93     */
94     return 10*res;
95 }
96
97
98 /*********************************************************************
99  *                  difftime      (CRTDLL.357)
100  */
101 double __cdecl CRTDLL_difftime (time_t time1, time_t time2)
102 {
103     double timediff;
104
105     timediff = (double)(time1 - time2);
106     return timediff;
107 }
108
109
110 /*********************************************************************
111  *                  time          (CRTDLL.488)
112  */
113 time_t __cdecl CRTDLL_time(time_t *timeptr)
114 {
115     time_t curtime = time(NULL);
116
117     if (timeptr)
118         *timeptr = curtime;
119     return curtime;
120 }