Merge pull request #12952 from lewing/debugger-proxy-discovery
[mono-project.git] / support / sys-time.c
blob4f5db9c8b2261269b2cf9268f43efd19c1068faf
1 /*
2 * <sys/stat.h> wrapper functions.
4 * Authors:
5 * Jonathan Pryor (jonpryor@vt.edu)
7 * Copyright (C) 2004-2006 Jonathan Pryor
8 */
10 #include <sys/types.h>
11 #include <sys/time.h>
12 #include <string.h>
13 #ifdef __HAIKU__
14 #include <os/kernel/OS.h>
15 #endif
17 #include "map.h"
18 #include "mph.h"
20 G_BEGIN_DECLS
22 gint32
23 Mono_Posix_Syscall_gettimeofday (
24 struct Mono_Posix_Timeval *tv,
25 void *tz)
27 struct timeval _tv;
28 struct timezone _tz;
29 int r;
31 r = gettimeofday (&_tv, &_tz);
33 if (r == 0) {
34 if (tv) {
35 tv->tv_sec = _tv.tv_sec;
36 tv->tv_usec = _tv.tv_usec;
38 if (tz) {
39 struct Mono_Posix_Timezone *tz_ = (struct Mono_Posix_Timezone *) tz;
40 tz_->tz_minuteswest = _tz.tz_minuteswest;
41 tz_->tz_dsttime = 0;
45 return r;
48 gint32
49 Mono_Posix_Syscall_settimeofday (
50 struct Mono_Posix_Timeval *tv,
51 struct Mono_Posix_Timezone *tz)
53 struct timeval _tv = {0};
54 struct timeval *ptv = NULL;
55 struct timezone _tz = {0};
56 struct timezone *ptz = NULL;
57 int r;
59 if (tv) {
60 _tv.tv_sec = tv->tv_sec;
61 _tv.tv_usec = tv->tv_usec;
62 ptv = &_tv;
64 if (tz) {
65 _tz.tz_minuteswest = tz->tz_minuteswest;
66 _tz.tz_dsttime = 0;
67 ptz = &_tz;
70 #ifdef __HAIKU__
71 set_real_time_clock(ptv->tv_sec);
72 r = 0;
73 #else
74 r = settimeofday (ptv, ptz);
75 #endif
77 return r;
80 static inline struct timeval*
81 copy_utimes (struct timeval* to, struct Mono_Posix_Timeval *from)
83 if (from) {
84 to[0].tv_sec = from[0].tv_sec;
85 to[0].tv_usec = from[0].tv_usec;
86 to[1].tv_sec = from[1].tv_sec;
87 to[1].tv_usec = from[1].tv_usec;
88 return to;
91 return NULL;
94 gint32
95 Mono_Posix_Syscall_utimes(const char *filename, struct Mono_Posix_Timeval *tv)
97 struct timeval _tv[2];
98 struct timeval *ptv;
100 ptv = copy_utimes (_tv, tv);
102 return utimes (filename, ptv);
105 #ifdef HAVE_LUTIMES
106 gint32
107 Mono_Posix_Syscall_lutimes(const char *filename, struct Mono_Posix_Timeval *tv)
109 struct timeval _tv[2];
110 struct timeval *ptv;
112 ptv = copy_utimes (_tv, tv);
114 return lutimes (filename, ptv);
116 #endif /* def HAVE_LUTIMES */
118 #if HAVE_FUTIMES
119 gint32
120 Mono_Posix_Syscall_futimes(int fd, struct Mono_Posix_Timeval *tv)
122 struct timeval _tv[2];
123 struct timeval *ptv;
125 ptv = copy_utimes (_tv, tv);
127 return futimes (fd, ptv);
129 #endif /* def HAVE_FUTIMES */
131 G_END_DECLS
134 * vim: noexpandtab