osip_time.h 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. /*
  2. The oSIP library implements the Session Initiation Protocol (SIP -rfc3261-)
  3. Copyright (C) 2001-2020 Aymeric MOIZARD amoizard@antisip.com
  4. This library is free software; you can redistribute it and/or
  5. modify it under the terms of the GNU Lesser General Public
  6. License as published by the Free Software Foundation; either
  7. version 2.1 of the License, or (at your option) any later version.
  8. This library is distributed in the hope that it will be useful,
  9. but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  11. Lesser General Public License for more details.
  12. You should have received a copy of the GNU Lesser General Public
  13. License along with this library; if not, write to the Free Software
  14. Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  15. */
  16. #ifndef _OSIP_TIME_H_
  17. #define _OSIP_TIME_H_
  18. #ifdef __cplusplus
  19. extern "C" {
  20. #endif
  21. /* Common time-related functions and data types */
  22. #if defined(_WIN32_WCE)
  23. struct _timeb {
  24. time_t time;
  25. unsigned short millitm;
  26. short timezone;
  27. short dstflag;
  28. };
  29. #endif
  30. /* struct timeval, as defined in <sys/time.h>, <winsock.h> or <winsock2.h> */
  31. struct timeval;
  32. /* Time manipulation functions */
  33. void add_gettimeofday(struct timeval *atv, int ms);
  34. void min_timercmp(struct timeval *tv1, struct timeval *tv2);
  35. /* Operations on struct timeval */
  36. #if !defined(timerisset)
  37. #define osip_timerisset(tvp) ((tvp)->tv_sec || (tvp)->tv_usec)
  38. #else
  39. #define osip_timerisset(tvp) timerisset(tvp)
  40. #endif
  41. #if !defined(timercmp)
  42. #define osip_timercmp(a, b, CMP) (((a)->tv_sec == (b)->tv_sec) ? ((a)->tv_usec CMP(b)->tv_usec) : ((a)->tv_sec CMP(b)->tv_sec))
  43. #else
  44. #define osip_timercmp(tvp, uvp, cmp) timercmp(tvp, uvp, cmp)
  45. #endif
  46. #if !defined(timerclear)
  47. #define osip_timerclear(tvp) (tvp)->tv_sec = (tvp)->tv_usec = 0
  48. #else
  49. #define osip_timerclear(tvp) timerclear(tvp)
  50. #endif
  51. #if !defined(timersub)
  52. #define osip_timersub(a, b, result) \
  53. do { \
  54. (result)->tv_sec = (a)->tv_sec - (b)->tv_sec; \
  55. (result)->tv_usec = (a)->tv_usec - (b)->tv_usec; \
  56. if ((result)->tv_usec < 0) { \
  57. --(result)->tv_sec; \
  58. (result)->tv_usec += 1000000; \
  59. } \
  60. } while (0)
  61. #else
  62. #define osip_timersub(a, b, result) timersub(a, b, result)
  63. #endif
  64. int osip_gettimeofday(struct timeval *tp, void *tz);
  65. time_t osip_getsystemtime(time_t *t);
  66. void osip_compensatetime(void);
  67. #ifdef __cplusplus
  68. }
  69. #endif
  70. #endif