home *** CD-ROM | disk | FTP | other *** search
/ RISCWORLD 7 / RISCWORLD_VOL7.iso / Software / Issue6 / SDL.ZIP / !gcc / include / unixlib / sys / h / time < prev    next >
Encoding:
Text File  |  2006-09-17  |  6.0 KB  |  174 lines

  1. /****************************************************************************
  2.  *
  3.  * $Source: /usr/local/cvsroot/gccsdk/unixlib/source/clib/sys/time.h,v $
  4.  * $Date: 2004/10/17 16:24:43 $
  5.  * $Revision: 1.7 $
  6.  * $State: Exp $
  7.  * $Author: joty $
  8.  *
  9.  ***************************************************************************/
  10.  
  11. #ifndef __SYS_TIME_H
  12.  
  13. #if ! defined __need_timeval
  14. #define __SYS_TIME_H
  15.  
  16. #define __need_timeval
  17. #endif
  18.  
  19. #if !defined __timeval_defined && defined __need_timeval
  20. #define __timeval_defined 1
  21. #include <unixlib/types.h>
  22. /* A time value that is accurate to the nearest
  23.    microsecond but also has a range of years.  */
  24. struct timeval
  25.   {
  26.     __time_t tv_sec;        /* Seconds.  */
  27.     __suseconds_t tv_usec;    /* Microseconds.  */
  28.   };
  29. #endif
  30. #undef __need_timeval
  31.  
  32. #ifdef __SYS_TIME_H
  33.  
  34. #define __need_time_t
  35. #include <time.h>
  36. #include <sys/select.h>
  37.  
  38. #ifndef __suseconds_t_defined
  39. typedef __suseconds_t suseconds_t;
  40. #define __suseconds_t_defined
  41. #endif
  42.  
  43. #ifndef __UNIXLIB_FEATURES_H
  44. #include <features.h>
  45. #endif
  46.  
  47. __BEGIN_DECLS
  48.  
  49. #ifdef __USE_GNU
  50. /* Macros for converting between `struct timeval' and `struct timespec'.  */
  51. #define TIMEVAL_TO_TIMESPEC(tv, ts) {                                   \
  52.         (ts)->tv_sec = (tv)->tv_sec;                                    \
  53.         (ts)->tv_nsec = (tv)->tv_usec * 1000;                           \
  54. }
  55. #define TIMESPEC_TO_TIMEVAL(tv, ts) {                                   \
  56.         (tv)->tv_sec = (ts)->tv_sec;                                    \
  57.         (tv)->tv_usec = (ts)->tv_nsec / 1000;                           \
  58. }
  59. #endif
  60.  
  61. #ifdef __USE_BSD
  62. /* Structure crudely representing a timezone.
  63.    This is obsolete and should never be used.  */
  64. struct timezone
  65.   {
  66.     int tz_minuteswest;        /* Minutes west of GMT.  */
  67.     int tz_dsttime;        /* Nonzero if DST is ever in effect.  */
  68.   };
  69.  
  70. typedef struct timezone *__restrict __timezone_ptr_t;
  71. #else
  72. typedef void *__restrict __timezone_ptr_t;
  73. #endif
  74.  
  75. /* Get the current time of day and timezone information,
  76.    putting it into *TV and *TZ.  If TZ is NULL, *TZ is not filled.
  77.    Returns 0 on success, -1 on errors.
  78.    NOTE: This form of timezone information is obsolete.
  79.    Use the functions and variables declared in <time.h> instead.  */
  80. extern int gettimeofday (struct timeval *__restrict __tv,
  81.              __timezone_ptr_t __tz) __THROW;
  82.  
  83. #ifdef __USE_BSD
  84. /* Set the current time of day and timezone information.
  85.    This call is restricted to the super-user.  */
  86. extern int settimeofday (const struct timeval *__tv,
  87.              const struct timezone *__tz) __THROW;
  88.  
  89. /* Adjust the current time of day by the amount in DELTA.
  90.    If OLDDELTA is not NULL, it is filled in with the amount
  91.    of time adjustment remaining to be done from the last `adjtime' call.
  92.    This call is restricted to the super-user.  */
  93. extern int adjtime (const struct timeval *, struct timeval *) __THROW;
  94. #endif
  95.  
  96. /* Values for the first argument to `getitimer' and `setitimer'.  */
  97. enum __itimer_which
  98.   {
  99.     /* Timers run in real time.  */
  100.     ITIMER_REAL = 0,
  101.     /* Timers run only when the process is executing.  */
  102.     ITIMER_VIRTUAL = 1,
  103.     /* Timers run when the process is executing and when
  104.        the system is executing on behalf of the process.  */
  105.     ITIMER_PROF = 2,
  106.     /* Used in <unixlib/unix.h>.  */
  107.     __MAX_ITIMERS = 3
  108.   };
  109.  
  110.  
  111. /* Type of the second argument to `getitimer' and
  112.    the second and third arguments `setitimer'.  */
  113. struct itimerval
  114.   {
  115.     /* Value to put into `it_value' when the timer expires.  */
  116.     struct timeval it_interval;
  117.     /* Time to the next timer expiration.  */
  118.     struct timeval it_value;
  119.   };
  120.  
  121. /* Set *VALUE to the current setting of timer WHICH.
  122.    Return 0 on success, -1 on errors.  */
  123. extern int getitimer (enum __itimer_which, struct itimerval *) __THROW;
  124.  
  125. /* Set the timer WHICH to *NEW.  If OLD is not NULL,
  126.    set *OLD to the old value of timer WHICH.
  127.    Returns 0 on success, -1 on errors.  */
  128. extern int setitimer (enum __itimer_which, const struct itimerval *__new_timer,
  129.               struct itimerval *__old_timer) __THROW;
  130.  
  131. /* Change the access time of FILE to TVP[0] and
  132.    the modification time of FILE to TVP[1].  */
  133. extern int utimes (const char *, const struct timeval __tvp[2]) __THROW;
  134.  
  135. #ifdef __USE_BSD
  136. /* Convenience macros for operations on timevals.
  137.    NOTE: `timercmp' does not work for >= or <=.  */
  138. #define    timerisset(tvp)        ((tvp)->tv_sec || (tvp)->tv_usec)
  139. #define    timerclear(tvp)        ((tvp)->tv_sec = (tvp)->tv_usec = 0)
  140.  
  141. #define    timercmp(tvp, uvp, CMP)    \
  142.   ((tvp)->tv_sec CMP (uvp)->tv_sec || \
  143.    (tvp)->tv_sec == (uvp)->tv_sec && (tvp)->tv_usec CMP (uvp)->tv_usec)
  144.  
  145. # define timeradd(a, b, result)                                               \
  146.   do {                                                                        \
  147.     (result)->tv_sec = (a)->tv_sec + (b)->tv_sec;                             \
  148.     (result)->tv_usec = (a)->tv_usec + (b)->tv_usec;                          \
  149.     if ((result)->tv_usec >= 1000000)                                         \
  150.       {                                                                       \
  151.         ++(result)->tv_sec;                                                   \
  152.         (result)->tv_usec -= 1000000;                                         \
  153.       }                                                                       \
  154.   } while (0)
  155.  
  156. # define timersub(a, b, result)                                               \
  157.   do {                                                                        \
  158.     (result)->tv_sec = (a)->tv_sec - (b)->tv_sec;                             \
  159.     (result)->tv_usec = (a)->tv_usec - (b)->tv_usec;                          \
  160.     if ((result)->tv_usec < 0) {                                              \
  161.       --(result)->tv_sec;                                                     \
  162.       (result)->tv_usec += 1000000;                                           \
  163.     }                                                                         \
  164.   } while (0)
  165.  
  166. #endif
  167.  
  168. __END_DECLS
  169.  
  170. #endif /* sys/time.h */
  171. #else
  172. #undef __need_timeval
  173. #endif /* ! __SYS_TIME_H */
  174.