3 * This file is a part of LEMON, a generic C++ optimization library
5 * Copyright (C) 2003-2006
6 * Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport
7 * (Egervary Research Group on Combinatorial Optimization, EGRES).
9 * Permission to use, modify and distribute this software is granted
10 * provided that this copyright notice appears in all copies. For
11 * precise terms see the accompanying LICENSE file.
13 * This software is provided "AS IS" with no warranty of any kind,
14 * express or implied, and with no claim as to its suitability for any
19 #ifndef LEMON_BITS_MINGW32_TIME_H
20 #define LEMON_BITS_MINGW32_TIME_H
28 static const char days[] =
29 "Sun Mon Tue Wed Thu Fri Sat ";
30 static const char months[] =
31 "Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec ";
33 inline void num2str(char *c,int i) {
38 inline char *asctime_r(const struct tm *t, char *buf) {
39 /* "Wed Jun 30 21:49:08 1993\n" */
40 *(int*)buf=*(int*)(days+(t->tm_wday<<2));
41 *(int*)(buf+4)=*(int*)(months+(t->tm_mon<<2));
42 num2str(buf+8,t->tm_mday);
43 if (buf[8]=='0') buf[8]=' ';
45 num2str(buf+11,t->tm_hour);
47 num2str(buf+14,t->tm_min);
49 num2str(buf+17,t->tm_sec);
51 num2str(buf+20,(t->tm_year+1900)/100);
52 num2str(buf+22,(t->tm_year+1900)%100);
53 buf[24]='\n'; buf[25]='\0';
57 inline struct tm * localtime_r (const time_t *t, struct tm *tm) {
60 if ((tmp = localtime(t)) && tm)
68 inline char *ctime_r(const time_t * tim_p , char * result) {
70 return asctime_r (localtime_r (tim_p, &tm), result);
74 inline int gettimeofday(struct timeval * tp, struct timezone *) {
79 time_t theTime = time(NULL);
82 tmrec = *localtime(&theTime);
83 tp->tv_sec = mktime(&tmrec);
84 GetLocalTime(&systime); /* system time */
86 tp->tv_usec = systime.wMilliseconds * 1000;
99 inline long filetime_to_clock(FILETIME *ft)
101 __int64 qw = ft->dwHighDateTime;
103 qw |= ft->dwLowDateTime;
104 qw /= 10000; /* File time ticks at 0.1uS, clock at 1mS */
109 inline int times(struct tms *tmbuf)
111 FILETIME create, exit, kernel, user;
112 if (GetProcessTimes(GetCurrentProcess(),&create, &exit, &kernel, &user)) {
113 tmbuf->tms_utime = filetime_to_clock(&user);
114 tmbuf->tms_stime = filetime_to_clock(&kernel);
115 tmbuf->tms_cutime = 0;
116 tmbuf->tms_cstime = 0;
119 tmbuf->tms_utime = clock();
120 tmbuf->tms_stime = 0;
121 tmbuf->tms_cutime = 0;
122 tmbuf->tms_cstime = 0;
127 #define _SC_CLK_TCK 1
129 inline int sysconf(int)