sys-time.c 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127
  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. static inline struct timeval*
  61. copy_utimes (struct timeval* to, struct Mono_Posix_Timeval *from)
  62. {
  63. if (from) {
  64. to[0].tv_sec = from[0].tv_sec;
  65. to[0].tv_usec = from[0].tv_usec;
  66. to[1].tv_sec = from[1].tv_sec;
  67. to[1].tv_usec = from[1].tv_usec;
  68. return to;
  69. }
  70. return NULL;
  71. }
  72. gint32
  73. Mono_Posix_Syscall_utimes(const char *filename, struct Mono_Posix_Timeval *tv)
  74. {
  75. struct timeval _tv[2];
  76. struct timeval *ptv;
  77. ptv = copy_utimes (_tv, tv);
  78. return utimes (filename, ptv);
  79. }
  80. #ifdef HAVE_LUTIMES
  81. gint32
  82. Mono_Posix_Syscall_lutimes(const char *filename, struct Mono_Posix_Timeval *tv)
  83. {
  84. struct timeval _tv[2];
  85. struct timeval *ptv;
  86. ptv = copy_utimes (_tv, tv);
  87. return lutimes (filename, ptv);
  88. }
  89. #endif /* def HAVE_LUTIMES */
  90. #if HAVE_FUTIMES
  91. gint32
  92. Mono_Posix_Syscall_futimes(int fd, struct Mono_Posix_Timeval *tv)
  93. {
  94. struct timeval _tv[2];
  95. struct timeval *ptv;
  96. ptv = copy_utimes (_tv, tv);
  97. return futimes (fd, ptv);
  98. }
  99. #endif /* def HAVE_FUTIMES */
  100. G_END_DECLS
  101. /*
  102. * vim: noexpandtab
  103. */