time.c 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. /*
  2. * <time.h> wrapper functions.
  3. *
  4. * Authors:
  5. * Jonathan Pryor ([email protected])
  6. *
  7. * Copyright (C) 2004 Jonathan Pryor
  8. */
  9. #define _SVID_SOURCE
  10. #include <time.h>
  11. #include <errno.h>
  12. #include "map.h"
  13. #include "mph.h"
  14. #include <glib.h>
  15. G_BEGIN_DECLS
  16. #if defined(HAVE_STRUCT_TIMESPEC) && _POSIX_C_SOURCE >= 199309L
  17. int
  18. Mono_Posix_Syscall_nanosleep (struct Mono_Posix_Timespec *req,
  19. struct Mono_Posix_Timespec *rem)
  20. {
  21. struct timespec _req, _rem, *prem = NULL;
  22. int r;
  23. if (req == NULL) {
  24. errno = EFAULT;
  25. return -1;
  26. }
  27. if (Mono_Posix_FromTimespec (req, &_req) == -1)
  28. return -1;
  29. if (rem) {
  30. if (Mono_Posix_FromTimespec (rem, &_rem) == -1)
  31. return -1;
  32. prem = &_rem;
  33. }
  34. r = nanosleep (&_req, prem);
  35. if (rem && Mono_Posix_ToTimespec (prem, rem) == -1)
  36. return -1;
  37. return r;
  38. }
  39. #endif
  40. #ifdef HAVE_STIME
  41. gint32
  42. Mono_Posix_Syscall_stime (mph_time_t *t)
  43. {
  44. time_t _t;
  45. if (t == NULL) {
  46. errno = EFAULT;
  47. return -1;
  48. }
  49. mph_return_if_time_t_overflow (*t);
  50. _t = (time_t) *t;
  51. return stime (&_t);
  52. }
  53. #endif /* ndef HAVE_STIME */
  54. mph_time_t
  55. Mono_Posix_Syscall_time (mph_time_t *t)
  56. {
  57. time_t _t, r;
  58. if (t == NULL) {
  59. errno = EFAULT;
  60. return -1;
  61. }
  62. mph_return_if_time_t_overflow (*t);
  63. _t = (time_t) *t;
  64. r = time (&_t);
  65. *t = _t;
  66. return r;
  67. }
  68. G_END_DECLS
  69. /*
  70. * vim: noexpandtab
  71. */