[interp] Remove unreachable code (#12411)
[mono-project.git] / support / time.c
blob9c67d8a5bdc81d6e3964fa53e3819fec2c1e747a
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 /* AIX has stime in libc, but not at all in headers, so declare here */
53 #if defined(_AIX)
54 extern int stime(time_t);
55 #endif
57 gint32
58 Mono_Posix_Syscall_stime (mph_time_t *t)
60 time_t _t;
61 if (t == NULL) {
62 errno = EFAULT;
63 return -1;
65 mph_return_if_time_t_overflow (*t);
66 _t = (time_t) *t;
67 return stime (&_t);
69 #endif /* ndef HAVE_STIME */
71 mph_time_t
72 Mono_Posix_Syscall_time (mph_time_t *t)
74 time_t _t, r;
75 if (t == NULL) {
76 errno = EFAULT;
77 return -1;
80 mph_return_if_time_t_overflow (*t);
82 _t = (time_t) *t;
83 r = time (&_t);
84 *t = _t;
86 return r;
89 G_END_DECLS
92 * vim: noexpandtab