45 lines · cpp
1//===---------- Linux implementation of the epoll_create function ---------===//2//3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.4// See https://llvm.org/LICENSE.txt for license information.5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception6//7//===----------------------------------------------------------------------===//8 9#include "src/sys/epoll/epoll_create.h"10 11#include "src/__support/OSUtil/syscall.h" // For internal syscall function.12#include "src/__support/common.h"13#include "src/__support/libc_errno.h"14#include "src/__support/macros/config.h"15#include <sys/syscall.h> // For syscall numbers.16 17namespace LIBC_NAMESPACE_DECL {18 19LLVM_LIBC_FUNCTION(int, epoll_create, ([[maybe_unused]] int size)) {20#ifdef SYS_epoll_create21 int ret = LIBC_NAMESPACE::syscall_impl<int>(SYS_epoll_create, size);22#elif defined(SYS_epoll_create1)23 if (size == 0) {24 libc_errno = EINVAL;25 return -1;26 }27 28 int ret = LIBC_NAMESPACE::syscall_impl<int>(SYS_epoll_create1, 0);29#else30#error \31 "epoll_create and epoll_create1 are unavailable. Unable to build epoll_create."32#endif33 34 // A negative return value indicates an error with the magnitude of the35 // value being the error code.36 if (ret < 0) {37 libc_errno = -ret;38 return -1;39 }40 41 return ret;42}43 44} // namespace LIBC_NAMESPACE_DECL45