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