Don't return from overlapped ReadFile on EAGAIN and other non-fatal
[wine/gsoc_dplay.git] / dlls / msvcrt / time.c
bloba78ce992f450db34758cdee19c44c1c4fe374ee3
1 /*
2 * msvcrt.dll date/time functions
4 * Copyright 1996,1998 Marcus Meissner
5 * Copyright 1996 Jukka Iivonen
6 * Copyright 1997,2000 Uwe Bonnes
7 * Copyright 2000 Jon Griffiths
8 */
10 #include <time.h>
11 #include <sys/times.h>
13 #include "msvcrt.h"
14 #include "msvcrt/sys/timeb.h"
15 #include "msvcrt/time.h"
18 DEFAULT_DEBUG_CHANNEL(msvcrt);
21 /* INTERNAL: Return formatted current time/date */
22 char* msvcrt_get_current_time(char* out, const char* format)
24 static const MSVCRT_time_t bad_time = (MSVCRT_time_t)-1;
25 time_t t;
26 struct tm *_tm = NULL;
27 char *retval = NULL;
29 if (time(&t) != bad_time && (_tm = localtime(&t)) &&
30 strftime(out,9,format,_tm) == 8)
31 retval = out;
32 return retval;
35 /**********************************************************************
36 * mktime (MSVCRT.@)
38 MSVCRT_time_t MSVCRT_mktime(struct MSVCRT_tm *t)
40 MSVCRT_time_t res;
41 struct tm tm;
43 tm.tm_sec = t->tm_sec;
44 tm.tm_min = t->tm_min;
45 tm.tm_hour = t->tm_hour;
46 tm.tm_mday = t->tm_mday;
47 tm.tm_mon = t->tm_mon;
48 tm.tm_year = t->tm_year;
49 tm.tm_isdst = t->tm_isdst;
50 res = mktime(&tm);
51 if (res != -1)
53 t->tm_sec = tm.tm_sec;
54 t->tm_min = tm.tm_min;
55 t->tm_hour = tm.tm_hour;
56 t->tm_mday = tm.tm_mday;
57 t->tm_mon = tm.tm_mon;
58 t->tm_year = tm.tm_year;
59 t->tm_isdst = tm.tm_isdst;
61 return res;
64 /**********************************************************************
65 * _strdate (MSVCRT.@)
67 char* _strdate(char* date)
69 return msvcrt_get_current_time(date,"%m/%d/%y");
72 /*********************************************************************
73 * _strtime (MSVCRT.@)
75 char* _strtime(char* date)
77 return msvcrt_get_current_time(date,"%H:%M:%S");
80 /*********************************************************************
81 * clock (MSVCRT.@)
83 MSVCRT_clock_t MSVCRT_clock(void)
85 struct tms alltimes;
86 clock_t res;
88 times(&alltimes);
89 res = alltimes.tms_utime + alltimes.tms_stime +
90 alltimes.tms_cutime + alltimes.tms_cstime;
91 /* FIXME: We need some symbolic representation for CLOCKS_PER_SEC,
92 * 10 holds only for Windows/Linux_i86)
94 return 10*res;
97 /*********************************************************************
98 * difftime (MSVCRT.@)
100 double MSVCRT_difftime(MSVCRT_time_t time1, MSVCRT_time_t time2)
102 return (double)(time1 - time2);
105 /*********************************************************************
106 * time (MSVCRT.@)
108 MSVCRT_time_t MSVCRT_time(MSVCRT_time_t* buf)
110 MSVCRT_time_t curtime = time(NULL);
111 return buf ? *buf = curtime : curtime;
114 /*********************************************************************
115 * _ftime (MSVCRT.@)
117 void _ftime(struct _timeb *buf)
119 buf->time = MSVCRT_time(NULL);
120 buf->millitm = 0; /* FIXME */
121 buf->timezone = 0;
122 buf->dstflag = 0;