1//===-- Implementation of fcntl -------------------------------------------===//
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-exception
6//
7//===----------------------------------------------------------------------===//
8
9#include "src/fcntl/fcntl.h"
10
11#include "src/__support/OSUtil/fcntl.h"
12#include "src/__support/common.h"
13#include "src/__support/libc_errno.h"
14#include "src/__support/macros/config.h"
15
16#include <stdarg.h>
17
18namespace LIBC_NAMESPACE_DECL {
19
20LLVM_LIBC_FUNCTION(int, fcntl, (int fd, int cmd, ...)) {
21 void *arg;
22 va_list varargs;
23 va_start(varargs, cmd);
24 arg = va_arg(varargs, void *);
25 va_end(varargs);
26
27 auto result = LIBC_NAMESPACE::internal::fcntl(fd, cmd, arg);
28
29 if (!result.has_value()) {
30 libc_errno = result.error();
31 return -1;
32 }
33 return result.value();
34}
35
36} // namespace LIBC_NAMESPACE_DECL
37

source code of libc/src/fcntl/linux/fcntl.cpp