Example #1
0
static int
ev_gettimeofday (struct timeval *tv, struct timezone *tz)
{
  struct _timeb tb;

  _ftime (&tb);

  tv->tv_sec  = (long)tb.time;
  tv->tv_usec = ((long)tb.millitm) * 1000;

  return 0;
}
Example #2
0
/**
 * gettimeofday() not in Win32
 */
EXP_FUNC void STDCALL gettimeofday(struct timeval* t, void* timezone)
{
#if defined(_WIN32_WCE)
    t->tv_sec = time(NULL);
    t->tv_usec = 0;                         /* 1sec precision only */
#else
    struct _timeb timebuffer;
    _ftime(&timebuffer);
    t->tv_sec = (long)timebuffer.time;
    t->tv_usec = 1000 * timebuffer.millitm; /* 1ms precision */
#endif
}
Example #3
0
double Time( void )
{
#ifdef WIN32
	struct _timeb t;
	_ftime(&t);
	return double(t.time)+double(t.millitm)/1000.0;
#else // WIN32
	struct timeval t;
	gettimeofday(&t,NULL);
	return t.tv_sec+(double)t.tv_usec/1000000;
#endif // WIN32
}
Example #4
0
STDINLINE stdcode stdtime_now(stdtime *abs_time)
#if defined(_WIN32)
{
  struct _timeb t;

  _ftime(&t);

  abs_time->sec  = t.time;
  abs_time->nano = t.millitm * STD1MILLION;

  return STDESUCCESS;
}
Example #5
0
/*
 * init_random, written by Syzop.
 * This function tries to initialize the arc4 random number generator securely.
 */
void init_random()
{
struct {
#ifdef USE_SSL
	char egd[32];			/* from EGD */
#endif
#ifndef _WIN32
	struct timeval nowt;	/* time */
	char rnd[32];			/* /dev/urandom */
#else
	MEMORYSTATUS mstat;		/* memory status */
	struct _timeb nowt;		/* time */
#endif
} rdat;

int n;

#ifndef _WIN32
int fd;
#else
MEMORYSTATUS mstat;
#endif

	arc4_init();

	/* Grab non-OS specific "random" data */
#ifdef USE_SSL
 #if OPENSSL_VERSION_NUMBER >= 0x000907000
	if (EGD_PATH) {
		n = RAND_query_egd_bytes(EGD_PATH, rdat.egd, sizeof(rdat.egd));
	}
 #endif
#endif

	/* Grab OS specific "random" data */
#ifndef _WIN32
	gettimeofday(&rdat.nowt, NULL);
	fd = open("/dev/urandom", O_RDONLY);
	if (fd) {
		n = read(fd, &rdat.rnd, sizeof(rdat.rnd));
		Debug((DEBUG_INFO, "init_random: read from /dev/urandom returned %d", n));
		close(fd);
	}
	/* TODO: more!?? */
#else
	_ftime(&rdat.nowt);
	GlobalMemoryStatus (&rdat.mstat);
#endif	

	arc4_addrandom(&rdat, sizeof(rdat));

	/* NOTE: addtional entropy is added by add_entropy_* function(s) */
}
Example #6
0
void CTimer::TotalTime()//输出累计总时间
{
    _ftime( &timebuffer_end);//获取结束时间

	double dEndTime = GetSeconds(timebuffer_end);
	double dElapsed_time = dEndTime - m_dBeginTime;
	if(stream == NULL)
		return;
	
	fprintf( stream, m_strTitle + " \nElapsed time :%.4f seconds\n\n",dElapsed_time );
	
}
Example #7
0
int64_t av_gettime(void)
{
#ifdef CONFIG_WIN32
    struct timeb tb;
    _ftime(&tb);
    return ((int64_t)tb.time * int64_t_C(1000) + (int64_t)tb.millitm) * int64_t_C(1000);
#else
    struct timeval tv;
    gettimeofday(&tv,NULL);
    return (int64_t)tv.tv_sec * 1000000 + tv.tv_usec;
#endif
}
Example #8
0
// Get the global time with at least millisecond resolution.
double 
CS315::getTime(void) {
#ifdef WIN32
  struct _timeb tbuf;
  _ftime(&tbuf);
  return ((double)tbuf.time + 0.001 * (double)(tbuf.millitm)); 
#else
  struct timeval time;
  gettimeofday(&time, NULL);
  return ((double)time.tv_sec + 0.000001 * (double)time.tv_usec); 
#endif
}
Example #9
0
 LPCTSTR CreateTimeStamp(LPTSTR lpBuffer, size_t iBufferSize)
 {
       struct _timeb tb;
       _ftime(&tb);
       size_t len = _tcsftime(lpBuffer, iBufferSize, _T("%b %d %H:%M:%S"), localtime(&tb.time));
       if (len && len+4 < iBufferSize) {
           if (_sntprintf(lpBuffer+len, iBufferSize-len-1, _T(".%03d"), tb.millitm) < 0) {
                lpBuffer[iBufferSize-len-1] = 0;
           }
       }
       return lpBuffer;
 }
Example #10
0
double TimeOfDay()
{
#if defined(WIN32) && !defined(__CYGWIN__)
  struct _timeb localTime;
  _ftime(&localTime);
  return localTime.time + 1.e-3 * localTime.millitm;
#else
  struct timeval t;
  gettimeofday(&t, NULL);
  return t.tv_sec + 1.e-6 * t.tv_usec;
#endif
}
Example #11
0
File: util.c Project: kjk/qemacs
int get_clock_ms(void)
{
#ifdef CONFIG_WIN32
    struct _timeb tb;
    _ftime(&tb);
    return tb.time * 1000 + tb.millitm;
#else
    struct timeval tv;
    gettimeofday(&tv, NULL);
    return tv.tv_sec * 1000 + (tv.tv_usec / 1000);
#endif
}
void CMessage::error(const int iErrorCode,                      
                    const char *pcErrorMessage,...)const
{

	ENTERCS;
	va_list args;
  
	va_start(args, pcErrorMessage);

	#if defined(__QNX__)
		timespec nowTimeVal;
		clock_gettime(CLOCK_REALTIME,&nowTimeVal);
		double fSeconds = (nowTimeVal.tv_sec
		  +(double(nowTimeVal.tv_nsec)/1e+9)) - m_fInitTime;
	#elif defined(_WIN32)
		_timeb nowTimeVal;
		_ftime(&nowTimeVal);
		double fSeconds = (nowTimeVal.time
		  +(double(nowTimeVal.millitm)/1e+3)) - m_fInitTime;
	#else
		timeval nowTimeVal;
		gettimeofday(&nowTimeVal,0);
		double fSeconds = (nowTimeVal.tv_sec
		  +(double(nowTimeVal.tv_usec)/1e+6)) - m_fInitTime;
	#endif

	static char acBuffer[255];	
	static char acOutBuffer[300];
	vsprintf(acBuffer, pcErrorMessage, args); 	
	sprintf(acOutBuffer, "\nERROR: #%i %5.3f %s::%s", iErrorCode, fSeconds, m_acClassName, acBuffer); 	
	if (m_bDebugFile==true)
	{	
		
		FILE* hFile;
		hFile=fopen(g_pcDebugFileName,"a+");
		if(hFile != NULL)
		{
			fprintf(hFile, "%s", acOutBuffer);
			fclose(hFile);
		}
		
	}
		
#ifdef WIN32
	OutputDebugString(acOutBuffer);
#else
	fprintf(stderr, "%s", acOutBuffer);
#endif
	LEAVECS;
	exit(-1);

};
Example #13
0
static void WaitMonitorThread(void *arg)
{
    PRIntervalTime timeout = (PRIntervalTime) arg;
    PRIntervalTime elapsed;
#if defined(XP_UNIX) || defined(WIN32)
    PRInt32 timeout_msecs = PR_IntervalToMilliseconds(timeout);
    PRInt32 elapsed_msecs;
#endif
#if defined(XP_UNIX)
    struct timeval end_time_tv;
#endif
#if defined(WIN32)
    struct _timeb end_time_tb;
#endif
    PRMonitor *mon;

    mon = PR_NewMonitor();
    if (mon == NULL) {
        fprintf(stderr, "PR_NewMonitor failed\n");
        exit(1);
    }
    PR_EnterMonitor(mon);
    PR_Wait(mon, timeout);
    PR_ExitMonitor(mon);
    elapsed = (PRIntervalTime)(PR_IntervalNow() - start_time);
    if (elapsed + tolerance < timeout || elapsed > timeout + tolerance) {
        fprintf(stderr, "timeout wrong\n");
        exit(1);
    }
#if defined(XP_UNIX)
    gettimeofday(&end_time_tv, NULL);
    elapsed_msecs = 1000*(end_time_tv.tv_sec - start_time_tv.tv_sec)
            + (end_time_tv.tv_usec - start_time_tv.tv_usec)/1000;
#endif
#if defined(WIN32)
    _ftime(&end_time_tb);
    elapsed_msecs = 1000*(end_time_tb.time - start_time_tb.time)
            + (end_time_tb.millitm - start_time_tb.millitm);
#endif
#if defined(XP_UNIX) || defined(WIN32)
    if (elapsed_msecs + tolerance_msecs < timeout_msecs
            || elapsed_msecs > timeout_msecs + tolerance_msecs) {
        fprintf(stderr, "timeout wrong\n");
        exit(1);
    }
#endif
    PR_DestroyMonitor(mon);
    if (debug_mode) {
        fprintf(stderr, "wait monitor thread (scope %d) done\n",
                PR_GetThreadScope(PR_GetCurrentThread()));
    }
}
static void
BasicHttpGetTimeOfDay(VmTimeType *time)         // OUT
{
#if _WIN32
   struct _timeb t;
   _ftime(&t);
   *time = (t.time * 1000000) + t.millitm * 1000;
#else // Linux
   struct timeval tv;
   gettimeofday(&tv, NULL);
   *time = ((VmTimeType)tv.tv_sec * 1000000) + tv.tv_usec;
#endif
}
Example #15
0
   double   current_time() {
#if defined(HAVE__FTIME)
	struct _timeb timebuffer;
	_ftime( &timebuffer );
	return ( timebuffer.time + (timebuffer.millitm * 0.001) );
#elif defined(HAVE_GETTIMEOFDAY)
	struct timeval	tv;
	gettimeofday( &tv, NULL );
	return ( tv.tv_sec + ( tv.tv_usec * 0.000001 ) );
#else
    return 0.0;
#endif
   }
Example #16
0
int
evutil_gettimeofday(struct timeval *tv, struct timezone *tz)
{
	struct _timeb tb;

	if(tv == NULL)
		return -1;

	_ftime(&tb);
	tv->tv_sec = (long) tb.time;
	tv->tv_usec = ((int) tb.millitm) * 1000;
	return 0;
}
Example #17
0
int gettimeofday(struct timeval *tp, void *tzp)
{
#ifdef WIN32
    struct _timeb timebuffer;
    _ftime(&timebuffer);
    tp->tv_sec = (long)timebuffer.time;
    tp->tv_usec = timebuffer.millitm * 1000;
#else
    tp->tv_sec = time(NULL);
    tp->tv_usec = 0;
#endif
    return 0;
}
Example #18
0
void
__eXosip_clock_gettime (unsigned int clock_id, struct timespec *time)
{
  struct _timeb time_val;

  if (clock_id != OSIP_CLOCK_REALTIME)
    return;

  _ftime (&time_val);
  time->tv_sec = time_val.time;
  time->tv_nsec = time_val.millitm * 1000000;
  return;
}
Example #19
0
int64_t p264_mdate( void )
{
#if !(defined(_MSC_VER) || defined(__MINGW32__))
    struct timeval tv_date;

    gettimeofday( &tv_date, NULL );
    return( (int64_t) tv_date.tv_sec * 1000000 + (int64_t) tv_date.tv_usec );
#else
    struct _timeb tb;
    _ftime(&tb);
    return ((int64_t)tb.time * (1000) + (int64_t)tb.millitm) * (1000);
#endif
}
Example #20
0
File: misc.c Project: BMNLabs/snort
int gettimeofday(struct timeval *tv, struct timezone *tz)
{
    struct _timeb tb;

	if(tv==NULL)
    {
        return -1;
    }
	_ftime(&tb);
	tv->tv_sec = (unsigned long)tb.time;
	tv->tv_usec = ((int) tb.millitm) * 1000;
	return 0;
}
Example #21
0
void msec::refresh() {
// CK Ng    added #ifdef WIN32
#ifdef WIN32
  struct _timeb timebuffer;
  _ftime( &timebuffer );
  m_time.tv_usec = timebuffer.millitm;
  m_time.tv_sec  = timebuffer.time;
#else
  class timezone tzone;
  gettimeofday((timeval *)&m_time, &tzone);
  m_time.tv_usec /= 1000; // convert usec to millisec
#endif
}
Example #22
0
// D: initializes the high resolution timer
void InitializeHighResolutionTimer() {
    // obtain the counter frequency (ticks per second)
    QueryPerformanceFrequency(&iHighResCounterFrequency);

    // obtain the current time (starting time) (actually sit in a loop
    // until the current time changes so that we can avoid as much as 
    // possible granularity effects
    _timeb tTimeNow, tLastTime;
    _ftime(&tTimeNow);
    do {
        tLastTime = tTimeNow;
        _ftime(&tTimeNow);
    } while(tTimeNow.millitm == tLastTime.millitm);
    tStartUpTime = tTimeNow;

    // and obtain the current initial counter time
    QueryPerformanceCounter(&iStartUpCounterValue);

	// converts it into milliseconds
	iStartUpTimestamp = 1000*iStartUpCounterValue.QuadPart/
        iHighResCounterFrequency.QuadPart;
}
Example #23
0
int
main()
{
  int i;
  pthread_t t[NUMTHREADS + 1];
  int result = 0;
  struct _timeb currSysTime;
  const DWORD NANOSEC_PER_MILLISEC = 1000000;

  assert(pthread_cond_init(&cv, NULL) == 0);

  assert(pthread_mutex_init(&mutex, NULL) == 0);

  /* get current system time */
  _ftime(&currSysTime);

  abstime.tv_sec = currSysTime.time;
  abstime.tv_nsec = NANOSEC_PER_MILLISEC * currSysTime.millitm;

  abstime.tv_sec += 5;

  assert(pthread_mutex_lock(&mutex) == 0);

  for (i = 1; i <= NUMTHREADS; i++)
    {
      assert(pthread_create(&t[i], NULL, mythread, (void *) i) == 0);
    }

  assert(pthread_mutex_unlock(&mutex) == 0);

  for (i = 1; i <= NUMTHREADS; i++)
    {
      assert(pthread_join(t[i], (void **) &result) == 0);
	assert(result == i);
    }

  {
  int result = pthread_cond_destroy(&cv);
  if (result != 0)
    {
      fprintf(stderr, "Result = %s\n", error_string[result]);
	fprintf(stderr, "\tWaitersBlocked = %ld\n", cv->nWaitersBlocked);
	fprintf(stderr, "\tWaitersGone = %ld\n", cv->nWaitersGone);
	fprintf(stderr, "\tWaitersToUnblock = %ld\n", cv->nWaitersToUnblock);
	fflush(stderr);
    }
  assert(result == 0);
  }

  return 0;
}
Example #24
0
double getTime()
{
#ifdef _WIN32
	time_t ltime;
	_timeb tstruct;
	time( &ltime );
	_ftime( &tstruct );
	return (double) (ltime + 1e-3*(tstruct.millitm));
#else
    struct timeval t;
    gettimeofday( &t, NULL );  
    return (double)(t.tv_sec + 1e-6*t.tv_usec);
#endif
      }
Example #25
0
/**
 * gets the current time in micro seconds.
 */
int64_t av_gettime(void)
{
#if defined(CONFIG_WINCE)
    return timeGetTime() * INT64_C(1000);
#elif defined(__MINGW32__)
    struct timeb tb;
    _ftime(&tb);
    return ((int64_t)tb.time * INT64_C(1000) + (int64_t)tb.millitm) * INT64_C(1000);
#else
    struct timeval tv;
    gettimeofday(&tv,NULL);
    return (int64_t)tv.tv_sec * 1000000 + tv.tv_usec;
#endif
}
Example #26
0
/* This function will begin to fail in the year 2038 */
int
afs_gettimeofday(struct timeval *tv, struct timezone *tz)
{
    struct _timeb myTime;

    _ftime(&myTime);
    tv->tv_sec = myTime.time;
    tv->tv_usec = myTime.millitm * 1000;
    if (tz) {
	tz->tz_minuteswest = myTime.timezone;
	tz->tz_dsttime = myTime.dstflag;
    }
    return 0;
}
Example #27
0
/******************* check whether time has expired *********************/
int bInchiTimeIsOver( e_inchiTime *TickEnd )
{
    struct _timeb timeb;
    if ( !TickEnd )
        return 0;
    _ftime( &timeb );
    if ( TickEnd->clockTime > (unsigned long)timeb.time )
        return 0;
    if ( TickEnd->clockTime < (unsigned long)timeb.time ||
         TickEnd->millitime < (long)timeb.millitm ) {
        return 1;
    }
    return 0;
}
Example #28
0
/*
================
Sys_DoubleTime
================
*/
double Sys_DoubleTime (void)
{
	double t;
    struct _timeb tstruct;
	static int	starttime;

	_ftime( &tstruct );
 
	if (!starttime)
		starttime = tstruct.time;
	t = (tstruct.time-starttime) + tstruct.millitm*0.001;
	
	return t;
}
Example #29
0
//---------------------------------------------------------------
// gettime(timeval&) const (Private)
// Get the current time.
//
void Eventloop::gettime(timeval& timeval) const
{
#if defined(WIN32)
    _timeb currTime;

    _ftime(&currTime);
    timeval.tv_sec = currTime.time;
    timeval.tv_usec = currTime.millitm * USECS_PER_MSEC;
#else
    (void) gettimeofday(&timeval, NULL);
#endif

    return;
} // end of Eventloop::gettime(timeval&) const
static void SleepThread(void *arg)
{
    PRIntervalTime timeout = (PRIntervalTime) arg;
    PRIntervalTime elapsed;
#if defined(XP_UNIX) || defined(WIN32)
    PRInt32 timeout_msecs = PR_IntervalToMilliseconds(timeout);
    PRInt32 elapsed_msecs;
#endif
#if defined(XP_UNIX)
    struct timeval end_time_tv;
#endif
#if defined(WIN32) && !defined(WINCE)
    struct _timeb end_time_tb;
#endif

    if (PR_Sleep(timeout) == PR_FAILURE) {
        fprintf(stderr, "PR_Sleep failed\n");
        exit(1);
    }
    elapsed = (PRIntervalTime)(PR_IntervalNow() - start_time);
    if (elapsed + tolerance < timeout || elapsed > timeout + tolerance) {
        fprintf(stderr, "timeout wrong\n");
        exit(1);
    }
#if defined(XP_UNIX)
    gettimeofday(&end_time_tv, NULL);
    elapsed_msecs = 1000*(end_time_tv.tv_sec - start_time_tv.tv_sec)
            + (end_time_tv.tv_usec - start_time_tv.tv_usec)/1000;
#endif
#if defined(WIN32)
#if defined(WINCE)
    elapsed_msecs = GetTickCount() - start_time_tick;
#else
    _ftime(&end_time_tb);
    elapsed_msecs = 1000*(end_time_tb.time - start_time_tb.time)
            + (end_time_tb.millitm - start_time_tb.millitm);
#endif
#endif
#if defined(XP_UNIX) || defined(WIN32)
    if (elapsed_msecs + tolerance_msecs < timeout_msecs
            || elapsed_msecs > timeout_msecs + tolerance_msecs) {
        fprintf(stderr, "timeout wrong\n");
        exit(1);
    }
#endif
    if (debug_mode) {
        fprintf(stderr, "Sleep thread (scope %d) done\n",
                PR_GetThreadScope(PR_GetCurrentThread()));
    }
}