Welcome to mirror list, hosted at ThFree Co, Russian Federation.

sys-time.c « support - github.com/mono/mono.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: b81f4657ebd93bfd0ff06ec0c0eceb4cca21f842 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
/*
 * <sys/stat.h> wrapper functions.
 *
 * Authors:
 *   Jonathan Pryor (jonpryor@vt.edu)
 *
 * Copyright (C) 2004 Jonathan Pryor
 */

#include <sys/types.h>
#include <sys/time.h>
#include <string.h>

#include "map.h"
#include "mph.h"

G_BEGIN_DECLS

struct Mono_Posix_Timeval {
	/* time_t */      mph_time_t  tv_sec;   /* seconds */
	/* suseconds_t */ gint64      tv_usec;  /* microseconds */
};

struct Mono_Posix_Timezone {
	int tz_minuteswest;  /* minutes W of Greenwich */
	int tz_dsttime;      /* ignored */
};

gint32
Mono_Posix_Syscall_gettimeofday (
	struct Mono_Posix_Timeval *tv,
	void *tz)
{
	struct timeval _tv;
	struct timezone _tz;
	int r;

	r = gettimeofday (&_tv, &_tz);

	if (r == 0) {
		if (tv) {
			tv->tv_sec  = _tv.tv_sec;
			tv->tv_usec = _tv.tv_usec;
		}
		if (tz) {
			struct Mono_Posix_Timezone *tz_ = (struct Mono_Posix_Timezone *) tz;
			tz_->tz_minuteswest = _tz.tz_minuteswest;
			tz_->tz_dsttime     = 0;
		}
	}

	return r;
}

gint32
Mono_Posix_Syscall_settimeofday (
	struct Mono_Posix_Timeval *tv,
	struct Mono_Posix_Timezone *tz)
{
	struct timeval _tv   = {0};
	struct timeval *ptv  = NULL;
	struct timezone _tz  = {0};
	struct timezone *ptz = NULL;
	int r;

	if (tv) {
		_tv.tv_sec  = tv->tv_sec;
		_tv.tv_usec = tv->tv_usec;
		ptv = &_tv;
	}
	if (tz) {
		_tz.tz_minuteswest = tz->tz_minuteswest;
		_tz.tz_dsttime = 0;
		ptz = &_tz;
	}

	r = settimeofday (ptv, ptz);

	return r;
}

gint32
Mono_Posix_Syscall_utimes (const char *filename,
	struct Mono_Posix_Timeval *tv)
{
	struct timeval _tv;
	struct timeval *ptv = NULL;

	if (tv) {
		_tv.tv_sec  = tv->tv_sec;
		_tv.tv_usec = tv->tv_usec;
		ptv = &_tv;
	}

	return utimes (filename, ptv);
}

G_END_DECLS

/*
 * vim: noexpandtab
 */