sys-time.c 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142
  1. /*
  2. * <sys/stat.h> wrapper functions.
  3. *
  4. * Authors:
  5. * Jonathan Pryor ([email protected])
  6. *
  7. * Copyright (C) 2004-2006 Jonathan Pryor
  8. */
  9. #include <sys/types.h>
  10. #include <sys/time.h>
  11. #include <string.h>
  12. #include "map.h"
  13. #include "mph.h"
  14. G_BEGIN_DECLS
  15. gint32
  16. Mono_Posix_Syscall_gettimeofday (
  17. struct Mono_Posix_Timeval *tv,
  18. void *tz)
  19. {
  20. struct timeval _tv;
  21. struct timezone _tz;
  22. int r;
  23. r = gettimeofday (&_tv, &_tz);
  24. if (r == 0) {
  25. if (tv) {
  26. tv->tv_sec = _tv.tv_sec;
  27. tv->tv_usec = _tv.tv_usec;
  28. }
  29. if (tz) {
  30. struct Mono_Posix_Timezone *tz_ = (struct Mono_Posix_Timezone *) tz;
  31. tz_->tz_minuteswest = _tz.tz_minuteswest;
  32. tz_->tz_dsttime = 0;
  33. }
  34. }
  35. return r;
  36. }
  37. gint32
  38. Mono_Posix_Syscall_settimeofday (
  39. struct Mono_Posix_Timeval *tv,
  40. struct Mono_Posix_Timezone *tz)
  41. {
  42. struct timeval _tv = {0};
  43. struct timeval *ptv = NULL;
  44. struct timezone _tz = {0};
  45. struct timezone *ptz = NULL;
  46. int r;
  47. if (tv) {
  48. _tv.tv_sec = tv->tv_sec;
  49. _tv.tv_usec = tv->tv_usec;
  50. ptv = &_tv;
  51. }
  52. if (tz) {
  53. _tz.tz_minuteswest = tz->tz_minuteswest;
  54. _tz.tz_dsttime = 0;
  55. ptz = &_tz;
  56. }
  57. r = settimeofday (ptv, ptz);
  58. return r;
  59. }
  60. /* Remove this at some point in the future */
  61. gint32
  62. Mono_Posix_Syscall_utimes_bad (const char *filename,
  63. struct Mono_Posix_Timeval *tv)
  64. {
  65. struct timeval _tv;
  66. struct timeval *ptv = NULL;
  67. if (tv) {
  68. _tv.tv_sec = tv->tv_sec;
  69. _tv.tv_usec = tv->tv_usec;
  70. ptv = &_tv;
  71. }
  72. return utimes (filename, ptv);
  73. }
  74. static inline struct timeval*
  75. copy_utimes (struct timeval* to, struct Mono_Posix_Timeval *from)
  76. {
  77. if (from) {
  78. to[0].tv_sec = from->tv_sec;
  79. to[0].tv_usec = from->tv_usec;
  80. to[1].tv_sec = from->tv_sec;
  81. to[1].tv_usec = from->tv_usec;
  82. return to;
  83. }
  84. return NULL;
  85. }
  86. gint32
  87. Mono_Posix_Syscall_utimes(const char *filename, struct Mono_Posix_Timeval *tv)
  88. {
  89. struct timeval _tv[2];
  90. struct timeval *ptv;
  91. ptv = copy_utimes (_tv, tv);
  92. return utimes (filename, ptv);
  93. }
  94. #ifdef HAVE_LUTIMES
  95. gint32
  96. Mono_Posix_Syscall_lutimes(const char *filename, struct Mono_Posix_Timeval *tv)
  97. {
  98. struct timeval _tv[2];
  99. struct timeval *ptv;
  100. ptv = copy_utimes (_tv, tv);
  101. return lutimes (filename, ptv);
  102. }
  103. #endif /* def HAVE_LUTIMES */
  104. gint32
  105. Mono_Posix_Syscall_futimes(int fd, struct Mono_Posix_Timeval *tv)
  106. {
  107. struct timeval _tv[2];
  108. struct timeval *ptv;
  109. ptv = copy_utimes (_tv, tv);
  110. return futimes (fd, ptv);
  111. }
  112. G_END_DECLS
  113. /*
  114. * vim: noexpandtab
  115. */