1/* time.h -- An implementation of the standard Unix <sys/time.h> file. 2 Written by Geoffrey Noer <noer@cygnus.com> 3 Public domain; no rights reserved. */ 4 5#ifndef _SYS_TIME_H_ 6#define _SYS_TIME_H_ 7 8#include <_ansi.h> 9#include <sys/types.h> 10 11#ifdef __cplusplus 12extern "C" { 13#endif 14 15#ifndef _TIMEVAL_DEFINED 16#define _TIMEVAL_DEFINED 17struct timeval { 18 time_t tv_sec; 19 suseconds_t tv_usec; 20}; 21 22/* BSD time macros used by RTEMS code */ 23#if defined (__rtems__) || defined (__CYGWIN__) 24 25/* Convenience macros for operations on timevals. 26 NOTE: `timercmp' does not work for >= or <=. */ 27#define timerisset(tvp) ((tvp)->tv_sec || (tvp)->tv_usec) 28#define timerclear(tvp) ((tvp)->tv_sec = (tvp)->tv_usec = 0) 29#define timercmp(a, b, CMP) \ 30 (((a)->tv_sec == (b)->tv_sec) ? \ 31 ((a)->tv_usec CMP (b)->tv_usec) : \ 32 ((a)->tv_sec CMP (b)->tv_sec)) 33#define timeradd(a, b, result) \ 34 do { \ 35 (result)->tv_sec = (a)->tv_sec + (b)->tv_sec; \ 36 (result)->tv_usec = (a)->tv_usec + (b)->tv_usec; \ 37 if ((result)->tv_usec >= 1000000) \ 38 { \ 39 ++(result)->tv_sec; \ 40 (result)->tv_usec -= 1000000; \ 41 } \ 42 } while (0) 43#define timersub(a, b, result) \ 44 do { \ 45 (result)->tv_sec = (a)->tv_sec - (b)->tv_sec; \ 46 (result)->tv_usec = (a)->tv_usec - (b)->tv_usec; \ 47 if ((result)->tv_usec < 0) { \ 48 --(result)->tv_sec; \ 49 (result)->tv_usec += 1000000; \ 50 } \ 51 } while (0) 52#endif /* defined (__rtems__) || defined (__CYGWIN__) */ 53#endif /* !_TIMEVAL_DEFINED */ 54 55struct timezone { 56 int tz_minuteswest; 57 int tz_dsttime; 58}; 59 60#ifdef __CYGWIN__ 61#include <cygwin/sys_time.h> 62#endif /* __CYGWIN__ */ 63 64#define ITIMER_REAL 0 65#define ITIMER_VIRTUAL 1 66#define ITIMER_PROF 2 67 68struct itimerval { 69 struct timeval it_interval; 70 struct timeval it_value; 71}; 72 73#ifdef _COMPILING_NEWLIB 74int _EXFUN(_gettimeofday, (struct timeval *__p, void *__tz)); 75#endif 76 77int _EXFUN(gettimeofday, (struct timeval *__p, void *__tz)); 78int _EXFUN(settimeofday, (const struct timeval *, const struct timezone *)); 79int _EXFUN(utimes, (const char *__path, const struct timeval *__tvp)); 80int _EXFUN(getitimer, (int __which, struct itimerval *__value)); 81int _EXFUN(setitimer, (int __which, const struct itimerval *__value, 82 struct itimerval *__ovalue)); 83 84#ifdef __cplusplus 85} 86#endif 87#endif /* _SYS_TIME_H_ */ 88