2010-04-16 Zoltan Varga <vargaz@gmail.com>
[mono/afaerber.git] / support / sys-time.c
blobfdb8b63cd6ab5a6b61d8497fe0eb8acbc9866d98
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>
14 #include "map.h"
15 #include "mph.h"
17 G_BEGIN_DECLS
19 gint32
20 Mono_Posix_Syscall_gettimeofday (
21 struct Mono_Posix_Timeval *tv,
22 void *tz)
24 struct timeval _tv;
25 struct timezone _tz;
26 int r;
28 r = gettimeofday (&_tv, &_tz);
30 if (r == 0) {
31 if (tv) {
32 tv->tv_sec = _tv.tv_sec;
33 tv->tv_usec = _tv.tv_usec;
35 if (tz) {
36 struct Mono_Posix_Timezone *tz_ = (struct Mono_Posix_Timezone *) tz;
37 tz_->tz_minuteswest = _tz.tz_minuteswest;
38 tz_->tz_dsttime = 0;
42 return r;
45 gint32
46 Mono_Posix_Syscall_settimeofday (
47 struct Mono_Posix_Timeval *tv,
48 struct Mono_Posix_Timezone *tz)
50 struct timeval _tv = {0};
51 struct timeval *ptv = NULL;
52 struct timezone _tz = {0};
53 struct timezone *ptz = NULL;
54 int r;
56 if (tv) {
57 _tv.tv_sec = tv->tv_sec;
58 _tv.tv_usec = tv->tv_usec;
59 ptv = &_tv;
61 if (tz) {
62 _tz.tz_minuteswest = tz->tz_minuteswest;
63 _tz.tz_dsttime = 0;
64 ptz = &_tz;
67 r = settimeofday (ptv, ptz);
69 return r;
72 /* Remove this at some point in the future */
73 gint32
74 Mono_Posix_Syscall_utimes_bad (const char *filename,
75 struct Mono_Posix_Timeval *tv)
77 struct timeval _tv;
78 struct timeval *ptv = NULL;
80 if (tv) {
81 _tv.tv_sec = tv->tv_sec;
82 _tv.tv_usec = tv->tv_usec;
83 ptv = &_tv;
86 return utimes (filename, ptv);
89 static inline struct timeval*
90 copy_utimes (struct timeval* to, struct Mono_Posix_Timeval *from)
92 if (from) {
93 to[0].tv_sec = from[0].tv_sec;
94 to[0].tv_usec = from[0].tv_usec;
95 to[1].tv_sec = from[1].tv_sec;
96 to[1].tv_usec = from[1].tv_usec;
97 return to;
100 return NULL;
103 gint32
104 Mono_Posix_Syscall_utimes(const char *filename, struct Mono_Posix_Timeval *tv)
106 struct timeval _tv[2];
107 struct timeval *ptv;
109 ptv = copy_utimes (_tv, tv);
111 return utimes (filename, ptv);
114 #ifdef HAVE_LUTIMES
115 gint32
116 Mono_Posix_Syscall_lutimes(const char *filename, struct Mono_Posix_Timeval *tv)
118 struct timeval _tv[2];
119 struct timeval *ptv;
121 ptv = copy_utimes (_tv, tv);
123 return lutimes (filename, ptv);
125 #endif /* def HAVE_LUTIMES */
127 gint32
128 Mono_Posix_Syscall_futimes(int fd, struct Mono_Posix_Timeval *tv)
130 struct timeval _tv[2];
131 struct timeval *ptv;
133 ptv = copy_utimes (_tv, tv);
135 return futimes (fd, ptv);
138 G_END_DECLS
141 * vim: noexpandtab