xref: /freebsd/lib/libc/gen/eventfd.c (revision 559a218c9b257775fb249b67945fe4a05b7a6b9f)
144c5db52SKonstantin Belousov /*-
244c5db52SKonstantin Belousov  * SPDX-License-Identifier: MIT
344c5db52SKonstantin Belousov  *
444c5db52SKonstantin Belousov  * Copyright (c) 2005-2020 Rich Felker, et al.
5*0b453151SVal Packett  * Copyright (c) 2020 Val Packett
644c5db52SKonstantin Belousov  *
744c5db52SKonstantin Belousov  * Permission is hereby granted, free of charge, to any person obtaining
844c5db52SKonstantin Belousov  * a copy of this software and associated documentation files (the
944c5db52SKonstantin Belousov  * "Software"), to deal in the Software without restriction, including
1044c5db52SKonstantin Belousov  * without limitation the rights to use, copy, modify, merge, publish,
1144c5db52SKonstantin Belousov  * distribute, sublicense, and/or sell copies of the Software, and to
1244c5db52SKonstantin Belousov  * permit persons to whom the Software is furnished to do so, subject to
1344c5db52SKonstantin Belousov  * the following conditions:
1444c5db52SKonstantin Belousov  *
1544c5db52SKonstantin Belousov  * The above copyright notice and this permission notice shall be
1644c5db52SKonstantin Belousov  * included in all copies or substantial portions of the Software.
1744c5db52SKonstantin Belousov  *
1844c5db52SKonstantin Belousov  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
1944c5db52SKonstantin Belousov  * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
2044c5db52SKonstantin Belousov  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
2144c5db52SKonstantin Belousov  * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
2244c5db52SKonstantin Belousov  * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
2344c5db52SKonstantin Belousov  * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
2444c5db52SKonstantin Belousov  * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
2544c5db52SKonstantin Belousov  */
2644c5db52SKonstantin Belousov 
2744c5db52SKonstantin Belousov #include "namespace.h"
2844c5db52SKonstantin Belousov #include <sys/eventfd.h>
2944c5db52SKonstantin Belousov #include <sys/specialfd.h>
3044c5db52SKonstantin Belousov #include <unistd.h>
3144c5db52SKonstantin Belousov #include "un-namespace.h"
3244c5db52SKonstantin Belousov #include "libc_private.h"
3344c5db52SKonstantin Belousov 
eventfd(unsigned int initval,int flags)3444c5db52SKonstantin Belousov int eventfd(unsigned int initval, int flags)
3544c5db52SKonstantin Belousov {
3644c5db52SKonstantin Belousov 	struct specialfd_eventfd args;
3744c5db52SKonstantin Belousov 
3844c5db52SKonstantin Belousov 	args.initval = initval;
3944c5db52SKonstantin Belousov 	args.flags = flags;
4044c5db52SKonstantin Belousov 	return (__sys___specialfd(SPECIALFD_EVENTFD, &args, sizeof(args)));
4144c5db52SKonstantin Belousov }
4244c5db52SKonstantin Belousov 
eventfd_read(int fd,eventfd_t * value)4344c5db52SKonstantin Belousov int eventfd_read(int fd, eventfd_t *value)
4444c5db52SKonstantin Belousov {
4544c5db52SKonstantin Belousov 	return (sizeof(*value) == _read(fd, value, sizeof(*value)) ? 0 : -1);
4644c5db52SKonstantin Belousov }
4744c5db52SKonstantin Belousov 
eventfd_write(int fd,eventfd_t value)4844c5db52SKonstantin Belousov int eventfd_write(int fd, eventfd_t value)
4944c5db52SKonstantin Belousov {
5044c5db52SKonstantin Belousov 	return (sizeof(value) == _write(fd, &value, sizeof(value)) ? 0 : -1);
5144c5db52SKonstantin Belousov }
52