You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

58 lines
1.2 KiB

25 years ago
  1. // cl_current_time().
  2. // General includes.
  3. #include "cl_sysdep.h"
  4. // Specification.
  5. #include "cl_timing.h"
  6. // Implementation.
  7. #include "cl_t_config.h"
  8. #if defined(HAVE_GETTIMEOFDAY)
  9. #include <sys/time.h>
  10. #ifdef GETTIMEOFDAY_DOTS
  11. extern "C" int gettimeofday (struct timeval * tp, ...);
  12. #else
  13. extern "C" int gettimeofday (struct timeval * tp, GETTIMEOFDAY_TZP_T tzp);
  14. #endif
  15. #elif defined(HAVE_FTIME)
  16. #include <sys/timeb.h>
  17. #ifdef _WIN32
  18. extern "C" void ftime (struct timeb * tp);
  19. #else
  20. extern "C" int ftime (struct timeb * tp);
  21. #endif
  22. #else
  23. #include <time.h>
  24. #endif
  25. #ifdef HAVE_PERROR_DECL
  26. #include <errno.h>
  27. #include <stdio.h>
  28. #else
  29. extern "C" int perror (const char *);
  30. #endif
  31. const cl_timespec cl_current_time ()
  32. {
  33. #if defined(HAVE_GETTIMEOFDAY)
  34. var struct timeval tv;
  35. if (gettimeofday(&tv,NULL) != 0) {
  36. perror("gettimeofday");
  37. tv.tv_sec = 0; tv.tv_usec = 0;
  38. }
  39. return cl_timespec(tv.tv_sec,
  40. tv.tv_usec * (1000000000/1000000)
  41. );
  42. #elif defined(HAVE_FTIME)
  43. var struct timeb timebuf;
  44. ftime(&timebuf);
  45. return cl_timespec(timebuf.time,
  46. (uintL)timebuf.millitm * (1000000000/1000)
  47. );
  48. #else
  49. return cl_timespec(time(NULL),0);
  50. #endif
  51. }