Backport gc_memmove and gc_bzero with all fixes together.
[mono-project.git] / support / time.c
blob05ceb4ccca8993499f36a83a9ef80c81c7b187a5
1 /*
2 * <time.h> wrapper functions.
4 * Authors:
5 * Jonathan Pryor (jonpryor@vt.edu)
7 * Copyright (C) 2004 Jonathan Pryor
8 */
10 #define _SVID_SOURCE
11 #include <time.h>
12 #include <errno.h>
14 #include "map.h"
15 #include "mph.h"
16 #include <glib.h>
18 G_BEGIN_DECLS
20 #if defined(HAVE_STRUCT_TIMESPEC) && _POSIX_C_SOURCE >= 199309L
21 int
22 Mono_Posix_Syscall_nanosleep (struct Mono_Posix_Timespec *req,
23 struct Mono_Posix_Timespec *rem)
25 struct timespec _req, _rem, *prem = NULL;
26 int r;
28 if (req == NULL) {
29 errno = EFAULT;
30 return -1;
33 if (Mono_Posix_FromTimespec (req, &_req) == -1)
34 return -1;
36 if (rem) {
37 if (Mono_Posix_FromTimespec (rem, &_rem) == -1)
38 return -1;
39 prem = &_rem;
42 r = nanosleep (&_req, prem);
44 if (rem && Mono_Posix_ToTimespec (prem, rem) == -1)
45 return -1;
47 return r;
49 #endif
51 #ifdef HAVE_STIME
52 gint32
53 Mono_Posix_Syscall_stime (mph_time_t *t)
55 time_t _t;
56 if (t == NULL) {
57 errno = EFAULT;
58 return -1;
60 mph_return_if_time_t_overflow (*t);
61 _t = (time_t) *t;
62 return stime (&_t);
64 #endif /* ndef HAVE_STIME */
66 mph_time_t
67 Mono_Posix_Syscall_time (mph_time_t *t)
69 time_t _t, r;
70 if (t == NULL) {
71 errno = EFAULT;
72 return -1;
75 mph_return_if_time_t_overflow (*t);
77 _t = (time_t) *t;
78 r = time (&_t);
79 *t = _t;
81 return r;
84 G_END_DECLS
87 * vim: noexpandtab