C_RESULT ardrone_timer_update(ardrone_timer_t* timer) { C_RESULT retVal = C_OK; if( timer->init == FALSE ) { _gettimeofday(&timer->tv_init, NULL); timer->init = TRUE; } _gettimeofday(&timer->tv, NULL); if (timer->tv.tv_usec >= timer->tv_init.tv_usec) { timer->tv.tv_usec -= timer->tv_init.tv_usec; } else { timer->tv.tv_usec = 1000000 - timer->tv_init.tv_usec + timer->tv.tv_usec; timer->tv.tv_sec -= 1; } if (timer->tv.tv_sec < timer->tv_init.tv_sec) { /* The tv timer has a time sooner than the tv_init timer */ retVal = C_FAIL; /* We do the calculation anyway because it still can be used. We'll only have a negative time */ } timer->tv.tv_sec -= timer->tv_init.tv_sec; return C_OK; }
void _tzset(void) { #if defined(__BSD4_2) struct timeval tv; struct timezone tz; _gettimeofday(&tv, &tz); _daylight = tz.tz_dsttime; _timezone = tz.tz_minuteswest * 60L; #elif !defined(_POSIX_SOURCE) && !defined(__USG) #if !defined(_MINIX) /* MINIX has no ftime() */ struct timeb time; _ftime(&time); _timezone = time.timezone * 60L; _daylight = time.dstflag; #endif #endif /* !_POSIX_SOURCE && !__USG */ parseTZ(getenv("TZ")); /* should go inside #if */ #if defined(__USG) || defined(_POSIX_SOURCE) tzname[0] = _tzname[0]; tzname[1] = _tzname[1]; #if defined(__USG) timezone = _timezone; daylight = _daylight; #endif #endif /* __USG || _POSIX_SOURCE */ }
int ftime(struct timeb *tp) { struct timeval t; if (_gettimeofday(&t) < 0) return (-1); _ltzset(t.tv_sec); tp->time = t.tv_sec; tp->millitm = t.tv_usec / 1000; tp->timezone = _timezone / 60; tp->dstflag = _daylight; return (0); }
int main( int argc, char **argv ) #endif { int i; int sc; puts( "\n\n*** POSIX TIME OF DAY TEST ***" ); puts( "gettimeofday( NULL, NULL ) - EFAULT" ); sc = gettimeofday( NULL, NULL ); rtems_test_assert( sc == -1 ); rtems_test_assert( errno == EFAULT ); puts( "_gettimeofday( NULL, NULL ) - EFAULT" ); sc = _gettimeofday( NULL, NULL ); rtems_test_assert( sc == -1 ); rtems_test_assert( errno == EFAULT ); test_adjtime(); /* * Now test a number of dates */ i = 0; while ( i < NUMBER_OF_DATES ) { check_a_tod( &Dates[i] ); i++; } puts( "\n\n*** END OF TIME OF DAY TEST 01 ***" ); rtems_test_exit(0); }
/* * P R E P _ T I M E R */ void rt_prep_timer() { _gettimeofday(&time0, (struct timezone *)0); _getrusage(RUSAGE_SELF, &ru0); }