diff --git a/lib/libc/gen/Makefile.inc b/lib/libc/gen/Makefile.inc --- a/lib/libc/gen/Makefile.inc +++ b/lib/libc/gen/Makefile.inc @@ -154,6 +154,7 @@ telldir.c \ termios.c \ time.c \ + timerfd.c \ times.c \ timespec_get.c \ timezone.c \ diff --git a/lib/libc/gen/Symbol.map b/lib/libc/gen/Symbol.map --- a/lib/libc/gen/Symbol.map +++ b/lib/libc/gen/Symbol.map @@ -436,6 +436,9 @@ }; FBSD_1.7 { + timerfd_create; + timerfd_gettime; + timerfd_settime; posix_spawn_file_actions_addchdir_np; posix_spawn_file_actions_addclosefrom_np; posix_spawn_file_actions_addfchdir_np; diff --git a/lib/libc/gen/timerfd.c b/lib/libc/gen/timerfd.c new file mode 100644 --- /dev/null +++ b/lib/libc/gen/timerfd.c @@ -0,0 +1,69 @@ +/*- + * SPDX-License-Identifier: BSD-2-Clause-FreeBSD + * + * Copyright (c) 2023 Jake Freeland + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + */ + +#include +__FBSDID("$FreeBSD$"); + +#include +#include +#include + +#include + +#include "namespace.h" +#include "un-namespace.h" +#include "libc_private.h" + +int timerfd_create(int clockid, int flags) +{ + struct specialfd_timerfd args; + + args.clockid = clockid; + args.flags = flags; + return (__sys___specialfd(SPECIALFD_TIMERFD, &args, sizeof(args))); +} + +int timerfd_gettime(int fd, struct itimerspec *curr_value) +{ + struct timerfd_gettime_args args; + + args.fd = fd; + args.curr_value = curr_value; + return (ioctl(fd, TFD_GETTIME, &args)); +} + +int timerfd_settime(int fd, int flags, const struct itimerspec *new_value, + struct itimerspec *old_value) +{ + struct timerfd_settime_args args; + + args.fd = fd; + args.flags = flags; + args.new_value = new_value; + args.old_value = old_value; + return (ioctl(fd, TFD_SETTIME, &args)); +}