1eac58b9emaste/*
2eac58b9emaste * Copyright 2003-2009 Niels Provos <provos@citi.umich.edu>
3eac58b9emaste * Copyright 2009-2012 Niels Provos and Nick Mathewson
4eac58b9emaste *
5eac58b9emaste * Redistribution and use in source and binary forms, with or without
6eac58b9emaste * modification, are permitted provided that the following conditions
7eac58b9emaste * are met:
8eac58b9emaste * 1. Redistributions of source code must retain the above copyright
9eac58b9emaste *    notice, this list of conditions and the following disclaimer.
10eac58b9emaste * 2. Redistributions in binary form must reproduce the above copyright
11eac58b9emaste *    notice, this list of conditions and the following disclaimer in the
12eac58b9emaste *    documentation and/or other materials provided with the distribution.
13eac58b9emaste * 3. The name of the author may not be used to endorse or promote products
14eac58b9emaste *    derived from this software without specific prior written permission.
15eac58b9emaste *
16eac58b9emaste * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
17eac58b9emaste * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
18eac58b9emaste * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
19eac58b9emaste * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
20eac58b9emaste * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
21eac58b9emaste * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
22eac58b9emaste * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
23eac58b9emaste * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24eac58b9emaste * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
25eac58b9emaste * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26eac58b9emaste */
27eac58b9emaste#include "evconfig-private.h"
28eac58b9emaste#include <stdint.h>
29eac58b9emaste
30eac58b9emaste#include <sys/param.h>
31eac58b9emaste#include <sys/types.h>
32eac58b9emaste#include <sys/syscall.h>
33eac58b9emaste#include <sys/epoll.h>
34eac58b9emaste#include <unistd.h>
35eac58b9emaste#include <errno.h>
36eac58b9emaste
37eac58b9emasteint
38eac58b9emasteepoll_create(int size)
39eac58b9emaste{
40eac58b9emaste#if !defined(__NR_epoll_create) && defined(__NR_epoll_create1)
41eac58b9emaste	if (size <= 0) {
42eac58b9emaste		errno = EINVAL;
43eac58b9emaste		return -1;
44eac58b9emaste	}
45eac58b9emaste	return (syscall(__NR_epoll_create1, 0));
46eac58b9emaste#else
47eac58b9emaste	return (syscall(__NR_epoll_create, size));
48eac58b9emaste#endif
49eac58b9emaste}
50eac58b9emaste
51eac58b9emasteint
52eac58b9emasteepoll_ctl(int epfd, int op, int fd, struct epoll_event *event)
53eac58b9emaste{
54eac58b9emaste
55eac58b9emaste	return (syscall(__NR_epoll_ctl, epfd, op, fd, event));
56eac58b9emaste}
57eac58b9emaste
58eac58b9emasteint
59eac58b9emasteepoll_wait(int epfd, struct epoll_event *events, int maxevents, int timeout)
60eac58b9emaste{
61eac58b9emaste#if !defined(__NR_epoll_wait) && defined(__NR_epoll_pwait)
62eac58b9emaste	return (syscall(__NR_epoll_pwait, epfd, events, maxevents, timeout, NULL, 0));
63eac58b9emaste#else
64eac58b9emaste	return (syscall(__NR_epoll_wait, epfd, events, maxevents, timeout));
65eac58b9emaste#endif
66eac58b9emaste}
67