2005-08-22 Michael Hutchinson <m.j.hutchinson@gmail.com>
[mono-project.git] / support / sys-time.c
blobb81f4657ebd93bfd0ff06ec0c0eceb4cca21f842
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_Timeval {
20 /* time_t */ mph_time_t tv_sec; /* seconds */
21 /* suseconds_t */ gint64 tv_usec; /* microseconds */
24 struct Mono_Posix_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_Timeval *tv,
32 void *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 struct Mono_Posix_Timezone *tz_ = (struct Mono_Posix_Timezone *) tz;
47 tz_->tz_minuteswest = _tz.tz_minuteswest;
48 tz_->tz_dsttime = 0;
52 return r;
55 gint32
56 Mono_Posix_Syscall_settimeofday (
57 struct Mono_Posix_Timeval *tv,
58 struct Mono_Posix_Timezone *tz)
60 struct timeval _tv = {0};
61 struct timeval *ptv = NULL;
62 struct timezone _tz = {0};
63 struct timezone *ptz = NULL;
64 int r;
66 if (tv) {
67 _tv.tv_sec = tv->tv_sec;
68 _tv.tv_usec = tv->tv_usec;
69 ptv = &_tv;
71 if (tz) {
72 _tz.tz_minuteswest = tz->tz_minuteswest;
73 _tz.tz_dsttime = 0;
74 ptz = &_tz;
77 r = settimeofday (ptv, ptz);
79 return r;
82 gint32
83 Mono_Posix_Syscall_utimes (const char *filename,
84 struct Mono_Posix_Timeval *tv)
86 struct timeval _tv;
87 struct timeval *ptv = NULL;
89 if (tv) {
90 _tv.tv_sec = tv->tv_sec;
91 _tv.tv_usec = tv->tv_usec;
92 ptv = &_tv;
95 return utimes (filename, ptv);
98 G_END_DECLS
101 * vim: noexpandtab