Merge pull request #5714 from alexischr/update_bockbuild
[mono.git] / support / time.c
1 /*
2  * <time.h> wrapper functions.
3  *
4  * Authors:
5  *   Jonathan Pryor (jonpryor@vt.edu)
6  *
7  * Copyright (C) 2004 Jonathan Pryor
8  */
9
10 #define _SVID_SOURCE
11 #include <time.h>
12 #include <errno.h>
13
14 #include "map.h"
15 #include "mph.h"
16 #include <glib.h>
17
18 G_BEGIN_DECLS
19
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)
24 {
25         struct timespec _req, _rem, *prem = NULL;
26         int r;
27
28         if (req == NULL) {
29                 errno = EFAULT;
30                 return -1;
31         }
32
33         if (Mono_Posix_FromTimespec (req, &_req) == -1)
34                 return -1;
35
36         if (rem) {
37                 if (Mono_Posix_FromTimespec (rem, &_rem) == -1)
38                         return -1;
39                 prem = &_rem;
40         }
41
42         r = nanosleep (&_req, prem);
43
44         if (rem && Mono_Posix_ToTimespec (prem, rem) == -1)
45                 return -1;
46
47         return r;
48 }
49 #endif
50
51 #ifdef HAVE_STIME
52 gint32
53 Mono_Posix_Syscall_stime (mph_time_t *t)
54 {
55         time_t _t;
56         if (t == NULL) {
57                 errno = EFAULT;
58                 return -1;
59         }
60         mph_return_if_time_t_overflow (*t);
61         _t = (time_t) *t;
62         return stime (&_t);
63 }
64 #endif /* ndef HAVE_STIME */
65
66 mph_time_t
67 Mono_Posix_Syscall_time (mph_time_t *t)
68 {
69         time_t _t, r;
70         if (t == NULL) {
71                 errno = EFAULT;
72                 return -1;
73         }
74
75         mph_return_if_time_t_overflow (*t);
76
77         _t = (time_t) *t;
78         r = time (&_t);
79         *t = _t;
80
81         return r;
82 }
83
84 G_END_DECLS
85
86 /*
87  * vim: noexpandtab
88  */