Add missing prototypes to Mono.Posix C sources.
[mono.git] / support / sys-time.c
1 /*
2  * <sys/stat.h> wrapper functions.
3  *
4  * Authors:
5  *   Jonathan Pryor (jonpryor@vt.edu)
6  *
7  * Copyright (C) 2004-2006 Jonathan Pryor
8  */
9
10 #include <sys/types.h>
11 #include <sys/time.h>
12 #include <string.h>
13
14 #include "map.h"
15 #include "mph.h"
16
17 G_BEGIN_DECLS
18
19 gint32
20 Mono_Posix_Syscall_gettimeofday (
21         struct Mono_Posix_Timeval *tv,
22         void *tz)
23 {
24         struct timeval _tv;
25         struct timezone _tz;
26         int r;
27
28         r = gettimeofday (&_tv, &_tz);
29
30         if (r == 0) {
31                 if (tv) {
32                         tv->tv_sec  = _tv.tv_sec;
33                         tv->tv_usec = _tv.tv_usec;
34                 }
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;
39                 }
40         }
41
42         return r;
43 }
44
45 gint32
46 Mono_Posix_Syscall_settimeofday (
47         struct Mono_Posix_Timeval *tv,
48         struct Mono_Posix_Timezone *tz)
49 {
50         struct timeval _tv   = {0};
51         struct timeval *ptv  = NULL;
52         struct timezone _tz  = {0};
53         struct timezone *ptz = NULL;
54         int r;
55
56         if (tv) {
57                 _tv.tv_sec  = tv->tv_sec;
58                 _tv.tv_usec = tv->tv_usec;
59                 ptv = &_tv;
60         }
61         if (tz) {
62                 _tz.tz_minuteswest = tz->tz_minuteswest;
63                 _tz.tz_dsttime = 0;
64                 ptz = &_tz;
65         }
66
67         r = settimeofday (ptv, ptz);
68
69         return r;
70 }
71
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);
76
77 gint32
78 Mono_Posix_Syscall_utimes_bad (const char *filename,
79         struct Mono_Posix_Timeval *tv)
80 {
81         struct timeval _tv;
82         struct timeval *ptv = NULL;
83
84         if (tv) {
85                 _tv.tv_sec  = tv->tv_sec;
86                 _tv.tv_usec = tv->tv_usec;
87                 ptv = &_tv;
88         }
89
90         return utimes (filename, ptv);
91 }
92
93 static inline struct timeval*
94 copy_utimes (struct timeval* to, struct Mono_Posix_Timeval *from)
95 {
96         if (from) {
97                 to[0].tv_sec  = from[0].tv_sec;
98                 to[0].tv_usec = from[0].tv_usec;
99                 to[1].tv_sec  = from[1].tv_sec;
100                 to[1].tv_usec = from[1].tv_usec;
101                 return to;
102         }
103
104         return NULL;
105 }
106
107 gint32
108 Mono_Posix_Syscall_utimes(const char *filename, struct Mono_Posix_Timeval *tv)
109 {
110         struct timeval _tv[2];
111         struct timeval *ptv;
112
113         ptv = copy_utimes (_tv, tv);
114
115         return utimes (filename, ptv);
116 }
117
118 #ifdef HAVE_LUTIMES
119 gint32
120 Mono_Posix_Syscall_lutimes(const char *filename, struct Mono_Posix_Timeval *tv)
121 {
122         struct timeval _tv[2];
123         struct timeval *ptv;
124
125         ptv = copy_utimes (_tv, tv);
126
127         return lutimes (filename, ptv);
128 }
129 #endif /* def HAVE_LUTIMES */
130
131 #if HAVE_FUTIMES
132 gint32
133 Mono_Posix_Syscall_futimes(int fd, struct Mono_Posix_Timeval *tv)
134 {
135         struct timeval _tv[2];
136         struct timeval *ptv;
137
138         ptv = copy_utimes (_tv, tv);
139
140         return futimes (fd, ptv);
141 }
142 #endif  /* def HAVE_FUTIMES */
143
144 G_END_DECLS
145
146 /*
147  * vim: noexpandtab
148  */