source: trunk/src/msvcrt/time.c@ 10005

Last change on this file since 10005 was 10005, checked in by sandervl, 22 years ago

PF: MSVCRT update

File size: 4.3 KB
Line 
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#ifdef __WIN32OS2__
24#include <emxheader.h>
25#include <unistd.h>
26#include <time.h>
27#include <sys\times.h>
28#else
29#include "config.h"
30#endif
31
32#include <time.h>
33#ifdef HAVE_SYS_TIMES_H
34# include <sys/times.h>
35#endif
36
37#include "msvcrt.h"
38#include "msvcrt/sys/timeb.h"
39#include "msvcrt/time.h"
40
41
42#include "wine/debug.h"
43
44WINE_DEFAULT_DEBUG_CHANNEL(msvcrt);
45
46
47/* INTERNAL: Return formatted current time/date */
48char* msvcrt_get_current_time(char* out, const char* format)
49{
50 static const MSVCRT_time_t bad_time = (MSVCRT_time_t)-1;
51 time_t t;
52 struct tm *_tm = NULL;
53 char *retval = NULL;
54
55 if (time(&t) != bad_time && (_tm = localtime(&t)) &&
56 strftime(out,9,format,_tm) == 8)
57 retval = out;
58 return retval;
59}
60
61/**********************************************************************
62 * mktime (MSVCRT.@)
63 */
64MSVCRT_time_t MSVCRT_mktime(struct MSVCRT_tm *t)
65{
66 MSVCRT_time_t res;
67 dprintf(("MSVCRT: mktime"));
68 struct tm tm;
69
70 tm.tm_sec = t->tm_sec;
71 tm.tm_min = t->tm_min;
72 tm.tm_hour = t->tm_hour;
73 tm.tm_mday = t->tm_mday;
74 tm.tm_mon = t->tm_mon;
75 tm.tm_year = t->tm_year;
76 tm.tm_isdst = t->tm_isdst;
77 res = mktime(&tm);
78 if (res != -1)
79 {
80 t->tm_sec = tm.tm_sec;
81 t->tm_min = tm.tm_min;
82 t->tm_hour = tm.tm_hour;
83 t->tm_mday = tm.tm_mday;
84 t->tm_mon = tm.tm_mon;
85 t->tm_year = tm.tm_year;
86 t->tm_isdst = tm.tm_isdst;
87 }
88 return res;
89}
90
91/**********************************************************************
92 * _strdate (MSVCRT.@)
93 */
94char* MSVCRT__strdate(char* date)
95{
96 dprintf(("MSVCRT: _strdate"));
97 return msvcrt_get_current_time(date,"%m/%d/%y");
98}
99
100/*********************************************************************
101 * _strtime (MSVCRT.@)
102 */
103char* MSVCRT__strtime(char* date)
104{
105 dprintf(("MSVCRT: _strtime"));
106 return msvcrt_get_current_time(date,"%H:%M:%S");
107}
108
109/*********************************************************************
110 * clock (MSVCRT.@)
111 */
112MSVCRT_clock_t MSVCRT_clock(void)
113{
114 struct tms alltimes;
115 clock_t res;
116
117 dprintf(("MSVCRT: clock"));
118
119 emx__times(&alltimes);
120 res = alltimes.tms_utime + alltimes.tms_stime +
121 alltimes.tms_cutime + alltimes.tms_cstime;
122 /* FIXME: We need some symbolic representation for CLOCKS_PER_SEC,
123 * 10 holds only for Windows/Linux_i86)
124 */
125 return 10*res;
126}
127
128/*********************************************************************
129 * difftime (MSVCRT.@)
130 */
131double MSVCRT_difftime(MSVCRT_time_t time1, MSVCRT_time_t time2)
132{
133 dprintf(("MSVCRT: difftime"));
134 return (double)(time1 - time2);
135}
136
137/*********************************************************************
138 * time (MSVCRT.@)
139 */
140MSVCRT_time_t MSVCRT_time(MSVCRT_time_t* buf)
141{
142 MSVCRT_time_t curtime = time(NULL);
143 dprintf(("MSVCRT: time"));
144 return buf ? *buf = curtime : curtime;
145}
146
147/*********************************************************************
148 * _ftime (MSVCRT.@)
149 */
150#ifdef __WIN32OS2__
151void MSVCRT__ftime(struct _timeb *buf)
152#else
153void _ftime(struct _timeb *buf)
154#endif
155{
156 dprintf(("MSVCRT: _ftime %p",buf));
157 buf->time = MSVCRT_time(NULL);
158 buf->millitm = 0; /* FIXME */
159 buf->timezone = 0;
160 buf->dstflag = 0;
161}
162
163/*********************************************************************
164 * _daylight (MSVCRT.@)
165 */
166int MSVCRT___daylight = 1; /* FIXME: assume daylight */
167
168/*********************************************************************
169 * __p_daylight (MSVCRT.@)
170 */
171void *MSVCRT___p__daylight(void)
172{
173 return &MSVCRT___daylight;
174}
Note: See TracBrowser for help on using the repository browser.