Changeset 5065:18cdc8c3a1ab in roaraudio for libroar/time.c


Ignore:
Timestamp:
06/18/11 04:07:49 (13 years ago)
Author:
phi
Branch:
default
Phase:
public
Message:

added roar_clock_gettime()

File:
1 edited

Legend:

Unmodified
Added
Removed
  • libroar/time.c

    r5031 r5065  
    5757 
    5858 if ( time->c_drift == 0 ) { 
    59   mes->datalen -= 4; 
     59  mes->datalen -= 8; 
    6060  if ( time->c_freq == 0 ) { 
    61    mes->datalen -= 4; 
     61   mes->datalen -= 8; 
    6262   if ( time->t_ssec == 0 ) { 
    63     mes->datalen -= 4; 
     63    mes->datalen -= 8; 
    6464   } 
    6565  } 
     
    140140} 
    141141 
     142int roar_clock_gettime(struct roar_time * rt, int clock) { 
     143#ifdef ROAR_HAVE_GETTIMEOFDAY 
     144 struct timeval tv; 
     145#elif defined(ROAR_HAVE_TIME) 
     146 time_t now; 
     147#endif 
     148 
     149 if ( rt == NULL ) { 
     150  roar_err_set(ROAR_ERROR_FAULT); 
     151  return -1; 
     152 } 
     153 
     154 memset(rt, 0, sizeof(struct roar_time)); 
     155 
     156 if ( clock == ROAR_CLOCK_DEFAULT ) 
     157  clock = ROAR_CLOCK_REALTIME; 
     158 
     159 switch (clock) { 
     160  case ROAR_CLOCK_REALTIME: 
     161#ifdef ROAR_HAVE_GETTIMEOFDAY 
     162    if ( gettimeofday(&tv, NULL) == -1 ) { 
     163     roar_err_from_errno(); 
     164     return -1; 
     165    } 
     166    rt->t_sec  = tv.tv_sec; 
     167    rt->t_ssec = (uint64_t)tv.tv_usec * (uint64_t)18446744073709ULL; 
     168    rt->c_freq = 1000LLU; 
     169#elif defined(ROAR_HAVE_TIME) 
     170    now = time(NULL); 
     171    rt->t_sec  = now; 
     172    rt->c_freq = 1000000000LLU; 
     173#else 
     174    roar_err_set(ROAR_ERROR_NOTSUP); 
     175    return -1; 
     176#endif 
     177    return 0; 
     178   break; 
     179 } 
     180 
     181 roar_err_set(ROAR_ERROR_NOTSUP); 
     182 return -1; 
     183} 
     184 
    142185//ll 
Note: See TracChangeset for help on using the changeset viewer.