* marshal.c: Iter usage.
[mono-project.git] / support / sys-time.c
blob0b41489463f7bb78acdc53219af005b48d5cf06c
1 /*
2 * <sys/stat.h> wrapper functions.
4 * Authors:
5 * Jonathan Pryor (jonpryor@vt.edu)
7 * Copyright (C) 2004 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 struct Mono_Posix_Syscall_Timeval {
20 /* time_t */ mph_time_t tv_sec; /* seconds */
21 /* suseconds_t */ gint64 tv_usec; /* microseconds */
24 struct Mono_Posix_Syscall_Timezone {
25 int tz_minuteswest; /* minutes W of Greenwich */
26 int tz_dsttime; /* ignored */
29 gint32
30 Mono_Posix_Syscall_gettimeofday (
31 struct Mono_Posix_Syscall_Timeval *tv,
32 struct Mono_Posix_Syscall_Timezone *tz)
34 struct timeval _tv;
35 struct timezone _tz;
36 int r;
38 r = gettimeofday (&_tv, &_tz);
40 if (r == 0) {
41 if (tv) {
42 tv->tv_sec = _tv.tv_sec;
43 tv->tv_usec = _tv.tv_usec;
45 if (tz) {
46 tz->tz_minuteswest = _tz.tz_minuteswest;
47 tz->tz_dsttime = 0;
51 return r;
54 gint32
55 Mono_Posix_Syscall_settimeofday (
56 const struct Mono_Posix_Syscall_Timeval *tv,
57 const struct Mono_Posix_Syscall_Timezone *tz)
59 struct timeval _tv = {0};
60 struct timeval *ptv = NULL;
61 struct timezone _tz = {0};
62 struct timezone *ptz = NULL;
63 int r;
65 if (tv) {
66 _tv.tv_sec = tv->tv_sec;
67 _tv.tv_usec = tv->tv_usec;
68 ptv = &_tv;
70 if (tz) {
71 _tz.tz_minuteswest = tz->tz_minuteswest;
72 _tz.tz_dsttime = 0;
73 ptz = &_tz;
76 r = settimeofday (ptv, ptz);
78 return r;
81 gint32
82 Mono_Posix_Syscall_utimes (const char *filename,
83 struct Mono_Posix_Syscall_Timeval *tv)
85 struct timeval _tv;
86 struct timeval *ptv = NULL;
88 if (tv) {
89 _tv.tv_sec = tv->tv_sec;
90 _tv.tv_usec = tv->tv_usec;
91 ptv = &_tv;
94 return utimes (filename, ptv);
97 G_END_DECLS
100 * vim: noexpandtab