Support for nonstandard baud rate in SetCommState.
[wine] / dlls / msvcrt / time.c
1 /*
2  * msvcrt.dll 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
10 #include <time.h>
11 #include <sys/times.h>
12
13 #include "msvcrt.h"
14 #include "msvcrt/sys/timeb.h"
15 #include "msvcrt/time.h"
16
17
18 #include "wine/debug.h"
19
20 WINE_DEFAULT_DEBUG_CHANNEL(msvcrt);
21
22
23 /* INTERNAL: Return formatted current time/date */
24 char* msvcrt_get_current_time(char* out, const char* format)
25 {
26   static const MSVCRT_time_t bad_time = (MSVCRT_time_t)-1;
27   time_t t;
28   struct tm *_tm = NULL;
29   char *retval = NULL;
30
31   if (time(&t) != bad_time && (_tm = localtime(&t)) &&
32       strftime(out,9,format,_tm) == 8)
33     retval = out;
34   return retval;
35 }
36
37 /**********************************************************************
38  *              mktime (MSVCRT.@)
39  */
40 MSVCRT_time_t MSVCRT_mktime(struct MSVCRT_tm *t)
41 {
42   MSVCRT_time_t res;
43   struct tm tm;
44
45   tm.tm_sec = t->tm_sec;
46   tm.tm_min = t->tm_min;
47   tm.tm_hour = t->tm_hour;
48   tm.tm_mday = t->tm_mday;
49   tm.tm_mon = t->tm_mon;
50   tm.tm_year = t->tm_year;
51   tm.tm_isdst = t->tm_isdst;
52   res = mktime(&tm);
53   if (res != -1)
54   {
55       t->tm_sec = tm.tm_sec;
56       t->tm_min = tm.tm_min;
57       t->tm_hour = tm.tm_hour;
58       t->tm_mday = tm.tm_mday;
59       t->tm_mon = tm.tm_mon;
60       t->tm_year = tm.tm_year;
61       t->tm_isdst = tm.tm_isdst;
62   }
63   return res;
64 }
65
66 /**********************************************************************
67  *              _strdate (MSVCRT.@)
68  */
69 char* _strdate(char* date)
70 {
71   return msvcrt_get_current_time(date,"%m/%d/%y");
72 }
73
74 /*********************************************************************
75  *              _strtime (MSVCRT.@)
76  */
77 char* _strtime(char* date)
78 {
79   return msvcrt_get_current_time(date,"%H:%M:%S");
80 }
81
82 /*********************************************************************
83  *              clock (MSVCRT.@)
84  */
85 MSVCRT_clock_t MSVCRT_clock(void)
86 {
87   struct tms alltimes;
88   clock_t res;
89
90   times(&alltimes);
91   res = alltimes.tms_utime + alltimes.tms_stime +
92         alltimes.tms_cutime + alltimes.tms_cstime;
93   /* FIXME: We need some symbolic representation for CLOCKS_PER_SEC,
94    *  10 holds only for Windows/Linux_i86)
95    */
96   return 10*res;
97 }
98
99 /*********************************************************************
100  *              difftime (MSVCRT.@)
101  */
102 double MSVCRT_difftime(MSVCRT_time_t time1, MSVCRT_time_t time2)
103 {
104     return (double)(time1 - time2);
105 }
106
107 /*********************************************************************
108  *              time (MSVCRT.@)
109  */
110 MSVCRT_time_t MSVCRT_time(MSVCRT_time_t* buf)
111 {
112   MSVCRT_time_t curtime = time(NULL);
113   return buf ? *buf = curtime : curtime;
114 }
115
116 /*********************************************************************
117  *              _ftime (MSVCRT.@)
118  */
119 void _ftime(struct _timeb *buf)
120 {
121   buf->time = MSVCRT_time(NULL);
122   buf->millitm = 0; /* FIXME */
123   buf->timezone = 0;
124   buf->dstflag = 0;
125 }