time.h 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145
  1. /* Copyright (C) 1991, 92, 93, 94, 96, 97, 98 Free Software Foundation, Inc.
  2. This file is part of the GNU C Library.
  3. The GNU C Library is free software; you can redistribute it and/or
  4. modify it under the terms of the GNU Library General Public License as
  5. published by the Free Software Foundation; either version 2 of the
  6. License, or (at your option) any later version.
  7. The GNU C Library is distributed in the hope that it will be useful,
  8. but WITHOUT ANY WARRANTY; without even the implied warranty of
  9. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  10. Library General Public License for more details.
  11. You should have received a copy of the GNU Library General Public
  12. License along with the GNU C Library; see the file COPYING.LIB. If not,
  13. write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
  14. Boston, MA 02111-1307, USA. */
  15. #ifndef _SYS_TIME_H
  16. #define _SYS_TIME_H 1
  17. #include <features.h>
  18. #include <time.h>
  19. #include <sys/select.h>
  20. #define __need_timeval
  21. #include <bits/time.h>
  22. __BEGIN_DECLS
  23. /* Macros for converting between `struct timeval' and `struct timespec'. */
  24. #define TIMEVAL_TO_TIMESPEC(tv, ts) { \
  25. (ts)->tv_sec = (tv)->tv_sec; \
  26. (ts)->tv_nsec = (tv)->tv_usec * 1000; \
  27. }
  28. #define TIMESPEC_TO_TIMEVAL(tv, ts) { \
  29. (tv)->tv_sec = (ts)->tv_sec; \
  30. (tv)->tv_usec = (ts)->tv_nsec / 1000; \
  31. }
  32. /* Structure crudely representing a timezone.
  33. This is obsolete and should never be used. */
  34. struct timezone
  35. {
  36. int tz_minuteswest; /* Minutes west of GMT. */
  37. int tz_dsttime; /* Nonzero if DST is ever in effect. */
  38. };
  39. /* Get the current time of day and timezone information,
  40. putting it into *TV and *TZ. If TZ is NULL, *TZ is not filled.
  41. Returns 0 on success, -1 on errors.
  42. NOTE: This form of timezone information is obsolete.
  43. Use the functions and variables declared in <time.h> instead. */
  44. extern int gettimeofday __P ((struct timeval *__tv,
  45. struct timezone *__tz));
  46. /* Set the current time of day and timezone information.
  47. This call is restricted to the super-user. */
  48. extern int settimeofday __P ((__const struct timeval *__tv,
  49. __const struct timezone *__tz));
  50. /* Adjust the current time of day by the amount in DELTA.
  51. If OLDDELTA is not NULL, it is filled in with the amount
  52. of time adjustment remaining to be done from the last `adjtime' call.
  53. This call is restricted to the super-user. */
  54. extern int adjtime __P ((__const struct timeval *__delta,
  55. struct timeval *__olddelta));
  56. /* Values for the first argument to `getitimer' and `setitimer'. */
  57. enum __itimer_which
  58. {
  59. /* Timers run in real time. */
  60. ITIMER_REAL = 0,
  61. #define ITIMER_REAL ITIMER_REAL
  62. /* Timers run only when the process is executing. */
  63. ITIMER_VIRTUAL = 1,
  64. #define ITIMER_VIRTUAL ITIMER_VIRTUAL
  65. /* Timers run when the process is executing and when
  66. the system is executing on behalf of the process. */
  67. ITIMER_PROF = 2
  68. #define ITIMER_PROF ITIMER_PROF
  69. };
  70. /* Type of the second argument to `getitimer' and
  71. the second and third arguments `setitimer'. */
  72. struct itimerval
  73. {
  74. /* Value to put into `it_value' when the timer expires. */
  75. struct timeval it_interval;
  76. /* Time to the next timer expiration. */
  77. struct timeval it_value;
  78. };
  79. /* Set *VALUE to the current setting of timer WHICH.
  80. Return 0 on success, -1 on errors. */
  81. extern int getitimer __P ((enum __itimer_which __which,
  82. struct itimerval *__value));
  83. /* Set the timer WHICH to *NEW. If OLD is not NULL,
  84. set *OLD to the old value of timer WHICH.
  85. Returns 0 on success, -1 on errors. */
  86. extern int setitimer __P ((enum __itimer_which __which,
  87. __const struct itimerval *__new,
  88. struct itimerval *__old));
  89. /* Change the access time of FILE to TVP[0] and
  90. the modification time of FILE to TVP[1]. */
  91. extern int utimes __P ((__const char *__file, struct timeval __tvp[2]));
  92. /* Convenience macros for operations on timevals.
  93. NOTE: `timercmp' does not work for >= or <=. */
  94. #define timerisset(tvp) ((tvp)->tv_sec || (tvp)->tv_usec)
  95. #define timerclear(tvp) ((tvp)->tv_sec = (tvp)->tv_usec = 0)
  96. #define timercmp(a, b, CMP) \
  97. (((a)->tv_sec == (b)->tv_sec) ? \
  98. ((a)->tv_usec CMP (b)->tv_usec) : \
  99. ((a)->tv_sec CMP (b)->tv_sec))
  100. #define timeradd(a, b, result) \
  101. do { \
  102. (result)->tv_sec = (a)->tv_sec + (b)->tv_sec; \
  103. (result)->tv_usec = (a)->tv_usec + (b)->tv_usec; \
  104. if ((result)->tv_usec >= 1000000) \
  105. { \
  106. ++(result)->tv_sec; \
  107. (result)->tv_usec -= 1000000; \
  108. } \
  109. } while (0)
  110. #define timersub(a, b, result) \
  111. do { \
  112. (result)->tv_sec = (a)->tv_sec - (b)->tv_sec; \
  113. (result)->tv_usec = (a)->tv_usec - (b)->tv_usec; \
  114. if ((result)->tv_usec < 0) { \
  115. --(result)->tv_sec; \
  116. (result)->tv_usec += 1000000; \
  117. } \
  118. } while (0)
  119. __END_DECLS
  120. #endif /* sys/time.h */