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