Cast time_t to long for printing.
[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  * This library is free software; you can redistribute it and/or
10  * modify it under the terms of the GNU Lesser General Public
11  * License as published by the Free Software Foundation; either
12  * version 2.1 of the License, or (at your option) any later version.
13  *
14  * This library is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
17  * Lesser General Public License for more details.
18  *
19  * You should have received a copy of the GNU Lesser General Public
20  * License along with this library; if not, write to the Free Software
21  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
22  */
23
24 #include "config.h"
25
26 #include <time.h>
27 #ifdef HAVE_SYS_TIMES_H
28 # include <sys/times.h>
29 #endif
30
31 #include "msvcrt.h"
32 #include "msvcrt/sys/timeb.h"
33 #include "msvcrt/time.h"
34
35
36 #include "wine/debug.h"
37
38 WINE_DEFAULT_DEBUG_CHANNEL(msvcrt);
39
40 /* INTERNAL: Return formatted current time/date */
41 char* msvcrt_get_current_time(char* out, const char* format)
42 {
43   static const MSVCRT_time_t bad_time = (MSVCRT_time_t)-1;
44   time_t t;
45   struct tm *_tm = NULL;
46   char *retval = NULL;
47
48   if (time(&t) != bad_time && (_tm = localtime(&t)) &&
49       strftime(out,9,format,_tm) == 8)
50     retval = out;
51   return retval;
52 }
53
54 /**********************************************************************
55  *              mktime (MSVCRT.@)
56  */
57 MSVCRT_time_t MSVCRT_mktime(struct MSVCRT_tm *t)
58 {
59   MSVCRT_time_t res;
60   struct tm tm;
61
62   tm.tm_sec = t->tm_sec;
63   tm.tm_min = t->tm_min;
64   tm.tm_hour = t->tm_hour;
65   tm.tm_mday = t->tm_mday;
66   tm.tm_mon = t->tm_mon;
67   tm.tm_year = t->tm_year;
68   tm.tm_isdst = t->tm_isdst;
69   res = mktime(&tm);
70   if (res != -1)
71   {
72       t->tm_sec = tm.tm_sec;
73       t->tm_min = tm.tm_min;
74       t->tm_hour = tm.tm_hour;
75       t->tm_mday = tm.tm_mday;
76       t->tm_mon = tm.tm_mon;
77       t->tm_year = tm.tm_year;
78       t->tm_isdst = tm.tm_isdst;
79   }
80   return res;
81 }
82
83 /**********************************************************************
84  *              _strdate (MSVCRT.@)
85  */
86 char* _strdate(char* date)
87 {
88   return msvcrt_get_current_time(date,"%m/%d/%y");
89 }
90
91 /*********************************************************************
92  *              _strtime (MSVCRT.@)
93  */
94 char* _strtime(char* date)
95 {
96   return msvcrt_get_current_time(date,"%H:%M:%S");
97 }
98
99 /*********************************************************************
100  *              clock (MSVCRT.@)
101  */
102 MSVCRT_clock_t MSVCRT_clock(void)
103 {
104   struct tms alltimes;
105   clock_t res;
106
107   times(&alltimes);
108   res = alltimes.tms_utime + alltimes.tms_stime +
109         alltimes.tms_cutime + alltimes.tms_cstime;
110   /* FIXME: We need some symbolic representation for CLOCKS_PER_SEC,
111    *  10 holds only for Windows/Linux_i86)
112    */
113   return 10*res;
114 }
115
116 /*********************************************************************
117  *              difftime (MSVCRT.@)
118  */
119 double MSVCRT_difftime(MSVCRT_time_t time1, MSVCRT_time_t time2)
120 {
121     return (double)(time1 - time2);
122 }
123
124 /*********************************************************************
125  *              time (MSVCRT.@)
126  */
127 MSVCRT_time_t MSVCRT_time(MSVCRT_time_t* buf)
128 {
129   MSVCRT_time_t curtime = time(NULL);
130   return buf ? *buf = curtime : curtime;
131 }
132
133 /*********************************************************************
134  *              _ftime (MSVCRT.@)
135  */
136 void _ftime(struct _timeb *buf)
137 {
138   buf->time = MSVCRT_time(NULL);
139   buf->millitm = 0; /* FIXME */
140   buf->timezone = 0;
141   buf->dstflag = 0;
142 }
143
144 /*********************************************************************
145  *              _daylight (MSVCRT.@)
146  */
147 int MSVCRT___daylight = 1; /* FIXME: assume daylight */
148
149 /*********************************************************************
150  *              __p_daylight (MSVCRT.@)
151  */
152 void *MSVCRT___p__daylight(void)
153 {
154         return &MSVCRT___daylight;
155 }