win_time.cpp 1.0 KB

12345678910111213141516171819202122232425262728293031323334353637
  1. /*
  2. * SRT - Secure, Reliable, Transport
  3. * Copyright (c) 2018 Haivision Systems Inc.
  4. *
  5. * This Source Code Form is subject to the terms of the Mozilla Public
  6. * License, v. 2.0. If a copy of the MPL was not distributed with this
  7. * file, You can obtain one at http://mozilla.org/MPL/2.0/.
  8. *
  9. */
  10. /*****************************************************************************
  11. written by
  12. Haivision Systems Inc.
  13. *****************************************************************************/
  14. #include "win/wintime.h"
  15. #include <sys/timeb.h>
  16. void SRTCompat_timeradd(struct timeval *a, struct timeval *b, struct timeval *result)
  17. {
  18. result->tv_sec = a->tv_sec + b->tv_sec;
  19. result->tv_usec = a->tv_usec + b->tv_usec;
  20. if (result->tv_usec >= 1000000)
  21. {
  22. result->tv_sec++;
  23. result->tv_usec -= 1000000;
  24. }
  25. }
  26. int SRTCompat_gettimeofday(struct timeval* tp, struct timezone*)
  27. {
  28. struct timeb tb;
  29. ftime(&tb);
  30. tp->tv_sec = (long)tb.time;
  31. tp->tv_usec = 1000*tb.millitm;
  32. return 0;
  33. }