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