1*805a1ce9Schristos /* $NetBSD: epoll_sub.c,v 1.1.1.3 2017/01/31 21:14:52 christos Exp $ */
26ecf6635Schristos /*
36ecf6635Schristos * Copyright 2003-2009 Niels Provos <provos@citi.umich.edu>
46ecf6635Schristos * Copyright 2009-2012 Niels Provos and Nick Mathewson
56ecf6635Schristos *
66ecf6635Schristos * Redistribution and use in source and binary forms, with or without
76ecf6635Schristos * modification, are permitted provided that the following conditions
86ecf6635Schristos * are met:
96ecf6635Schristos * 1. Redistributions of source code must retain the above copyright
106ecf6635Schristos * notice, this list of conditions and the following disclaimer.
116ecf6635Schristos * 2. Redistributions in binary form must reproduce the above copyright
126ecf6635Schristos * notice, this list of conditions and the following disclaimer in the
136ecf6635Schristos * documentation and/or other materials provided with the distribution.
146ecf6635Schristos * 3. The name of the author may not be used to endorse or promote products
156ecf6635Schristos * derived from this software without specific prior written permission.
166ecf6635Schristos *
176ecf6635Schristos * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
186ecf6635Schristos * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
196ecf6635Schristos * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
206ecf6635Schristos * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
216ecf6635Schristos * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
226ecf6635Schristos * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
236ecf6635Schristos * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
246ecf6635Schristos * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
256ecf6635Schristos * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
266ecf6635Schristos * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
276ecf6635Schristos */
28*805a1ce9Schristos #include "evconfig-private.h"
296ecf6635Schristos #include <stdint.h>
306ecf6635Schristos
316ecf6635Schristos #include <sys/param.h>
326ecf6635Schristos #include <sys/types.h>
336ecf6635Schristos #include <sys/syscall.h>
346ecf6635Schristos #include <sys/epoll.h>
356ecf6635Schristos #include <unistd.h>
36447d9fdcSspz #include <errno.h>
376ecf6635Schristos
386ecf6635Schristos int
epoll_create(int size)396ecf6635Schristos epoll_create(int size)
406ecf6635Schristos {
41447d9fdcSspz #if !defined(__NR_epoll_create) && defined(__NR_epoll_create1)
42447d9fdcSspz if (size <= 0) {
43447d9fdcSspz errno = EINVAL;
44447d9fdcSspz return -1;
45447d9fdcSspz }
46447d9fdcSspz return (syscall(__NR_epoll_create1, 0));
47447d9fdcSspz #else
486ecf6635Schristos return (syscall(__NR_epoll_create, size));
49447d9fdcSspz #endif
506ecf6635Schristos }
516ecf6635Schristos
526ecf6635Schristos int
epoll_ctl(int epfd,int op,int fd,struct epoll_event * event)536ecf6635Schristos epoll_ctl(int epfd, int op, int fd, struct epoll_event *event)
546ecf6635Schristos {
556ecf6635Schristos
566ecf6635Schristos return (syscall(__NR_epoll_ctl, epfd, op, fd, event));
576ecf6635Schristos }
586ecf6635Schristos
596ecf6635Schristos int
epoll_wait(int epfd,struct epoll_event * events,int maxevents,int timeout)606ecf6635Schristos epoll_wait(int epfd, struct epoll_event *events, int maxevents, int timeout)
616ecf6635Schristos {
62447d9fdcSspz #if !defined(__NR_epoll_wait) && defined(__NR_epoll_pwait)
63447d9fdcSspz return (syscall(__NR_epoll_pwait, epfd, events, maxevents, timeout, NULL, 0));
64447d9fdcSspz #else
656ecf6635Schristos return (syscall(__NR_epoll_wait, epfd, events, maxevents, timeout));
66447d9fdcSspz #endif
676ecf6635Schristos }
68