deba@2028: /* -*- C++ -*- deba@2028: * deba@2028: * This file is a part of LEMON, a generic C++ optimization library deba@2028: * deba@2028: * Copyright (C) 2003-2006 deba@2028: * Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport deba@2028: * (Egervary Research Group on Combinatorial Optimization, EGRES). deba@2028: * deba@2028: * Permission to use, modify and distribute this software is granted deba@2028: * provided that this copyright notice appears in all copies. For deba@2028: * precise terms see the accompanying LICENSE file. deba@2028: * deba@2028: * This software is provided "AS IS" with no warranty of any kind, deba@2028: * express or implied, and with no claim as to its suitability for any deba@2028: * purpose. deba@2028: * deba@2028: */ deba@2028: deba@2028: #ifndef LEMON_BITS_MINGW32_TIME_H deba@2028: #define LEMON_BITS_MINGW32_TIME_H deba@2028: deba@2028: #ifdef WIN32 deba@2028: deba@2028: #include deba@2028: #include deba@2028: #include "dos.h" deba@2028: deba@2028: static const char days[] = deba@2028: "Sun Mon Tue Wed Thu Fri Sat "; deba@2028: static const char months[] = deba@2028: "Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec "; deba@2028: deba@2028: inline void num2str(char *c,int i) { deba@2028: c[0]=i/10+'0'; deba@2028: c[1]=i%10+'0'; deba@2028: } deba@2028: deba@2028: inline char *asctime_r(const struct tm *t, char *buf) { deba@2028: /* "Wed Jun 30 21:49:08 1993\n" */ deba@2028: *(int*)buf=*(int*)(days+(t->tm_wday<<2)); deba@2028: *(int*)(buf+4)=*(int*)(months+(t->tm_mon<<2)); deba@2028: num2str(buf+8,t->tm_mday); deba@2028: if (buf[8]=='0') buf[8]=' '; deba@2028: buf[10]=' '; deba@2028: num2str(buf+11,t->tm_hour); deba@2028: buf[13]=':'; deba@2028: num2str(buf+14,t->tm_min); deba@2028: buf[16]=':'; deba@2028: num2str(buf+17,t->tm_sec); deba@2028: buf[19]=' '; deba@2028: num2str(buf+20,(t->tm_year+1900)/100); deba@2028: num2str(buf+22,(t->tm_year+1900)%100); deba@2028: buf[24]='\n'; buf[25]='\0'; deba@2028: return buf; deba@2028: } deba@2028: deba@2028: inline struct tm * localtime_r (const time_t *t, struct tm *tm) { deba@2028: struct tm *tmp; deba@2028: deba@2028: if ((tmp = localtime(t)) && tm) deba@2028: *tm = *tmp; deba@2028: else deba@2028: return 0; deba@2028: deba@2028: return tm; deba@2028: } deba@2028: deba@2028: inline char *ctime_r(const time_t * tim_p , char * result) { deba@2028: struct tm tm; deba@2028: return asctime_r (localtime_r (tim_p, &tm), result); deba@2028: } deba@2028: deba@2028: deba@2028: inline int gettimeofday(struct timeval * tp, struct timezone *) { deba@2028: SYSTEMTIME systime; deba@2028: deba@2028: if (tp) { deba@2028: struct tm tmrec; deba@2028: time_t theTime = time(NULL); deba@2028: deba@2028: deba@2028: tmrec = *localtime(&theTime); deba@2028: tp->tv_sec = mktime(&tmrec); deba@2028: GetLocalTime(&systime); /* system time */ deba@2028: deba@2028: tp->tv_usec = systime.wMilliseconds * 1000; deba@2028: } deba@2028: return 0; deba@2028: } deba@2028: deba@2028: deba@2028: struct tms { deba@2028: long tms_utime; deba@2028: long tms_stime; deba@2028: long tms_cutime; deba@2028: long tms_cstime; deba@2028: }; deba@2028: deba@2028: inline long filetime_to_clock(FILETIME *ft) deba@2028: { deba@2028: __int64 qw = ft->dwHighDateTime; deba@2028: qw <<= 32; deba@2028: qw |= ft->dwLowDateTime; deba@2028: qw /= 10000; /* File time ticks at 0.1uS, clock at 1mS */ deba@2028: return (long) qw; deba@2028: deba@2028: } deba@2028: deba@2028: inline int times(struct tms *tmbuf) deba@2028: { deba@2028: FILETIME create, exit, kernel, user; deba@2028: if (GetProcessTimes(GetCurrentProcess(),&create, &exit, &kernel, &user)) { deba@2028: tmbuf->tms_utime = filetime_to_clock(&user); deba@2028: tmbuf->tms_stime = filetime_to_clock(&kernel); deba@2028: tmbuf->tms_cutime = 0; deba@2028: tmbuf->tms_cstime = 0; deba@2028: } deba@2028: else { deba@2028: tmbuf->tms_utime = clock(); deba@2028: tmbuf->tms_stime = 0; deba@2028: tmbuf->tms_cutime = 0; deba@2028: tmbuf->tms_cstime = 0; deba@2028: } deba@2028: return 0; deba@2028: } deba@2028: deba@2028: #define _SC_CLK_TCK 1 deba@2028: deba@2028: inline int sysconf(int) deba@2028: { deba@2028: return 1; deba@2028: } deba@2028: deba@2028: #endif deba@2028: deba@2028: deba@2028: #endif