2 * This file and its contents are supplied under the terms of the
3 * Common Development and Distribution License ("CDDL"), version 1.0.
4 * You may only use this file in accordance with the terms of version
7 * A full copy of the text of the CDDL should have accompanied this
8 * source. A copy of the CDDL is also available via the Internet at
9 * http://www.illumos.org/license/CDDL.
13 * Copyright (c) 2015, Joyent, Inc. All rights reserved.
16 #include <sys/timerfd.h>
23 timerfd_create(int clockid
, int flags
)
28 if (flags
& ~(TFD_NONBLOCK
| TFD_CLOEXEC
)) {
33 if (flags
& TFD_NONBLOCK
)
36 if (flags
& TFD_CLOEXEC
)
39 if ((fd
= open("/dev/timerfd", oflags
)) < 0)
42 if (ioctl(fd
, TIMERFDIOC_CREATE
, clockid
) != 0) {
51 timerfd_settime(int fd
, int flags
, const struct itimerspec
*new_value
,
52 struct itimerspec
*old_value
)
57 if (flags
& ~(TFD_TIMER_ABSTIME
| TFD_TIMER_CANCEL_ON_SET
)) {
62 st
.tfd_settime_flags
= flags
;
63 st
.tfd_settime_value
= (uint64_t)(uintptr_t)new_value
;
64 st
.tfd_settime_ovalue
= (uint64_t)(uintptr_t)old_value
;
66 rval
= ioctl(fd
, TIMERFDIOC_SETTIME
, &st
);
68 if (rval
== -1 && errno
== ENOTTY
) {
70 * Linux has us return EINVAL when the file descriptor is valid
71 * but is not a timerfd file descriptor -- and LTP explicitly
81 timerfd_gettime(int fd
, struct itimerspec
*curr_value
)
83 int rval
= ioctl(fd
, TIMERFDIOC_GETTIME
, curr_value
);
85 if (rval
== -1 && errno
== ENOTTY
) {
87 * See comment in timerfd_settime(), above.