[libc-commits] [libc] [libc] Implement fcntl() function (PR #89507)
Michael Jones via libc-commits
libc-commits at lists.llvm.org
Mon Apr 22 14:43:56 PDT 2024
================
@@ -0,0 +1,96 @@
+//===-- Implementation of fcntl -------------------------------------------===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+
+#include "src/fcntl/fcntl.h"
+
+#include "src/__support/OSUtil/syscall.h" // For internal syscall function.
+#include "src/__support/common.h"
+#include "src/errno/libc_errno.h"
+
+#include <stdarg.h>
+#include <sys/syscall.h> // For syscall numbers.
+
+namespace {
+struct fowner_ex {
+ int type;
+ pid_t pid;
+};
+} // namespace
+
+// The OFD file locks require special handling for LARGEFILES
+namespace LIBC_NAMESPACE {
+LLVM_LIBC_FUNCTION(int, fcntl, (int fd, int cmd, ...)) {
+ void *arg;
+ va_list varargs;
+ va_start(varargs, cmd);
+ arg = va_arg(varargs, void *);
+ va_end(varargs);
+
+ switch (cmd) {
+ case F_SETLKW:
+ return syscall_impl<int>(SYS_fcntl, fd, cmd, arg);
+ case F_OFD_SETLKW: {
+ struct flock *flk = (struct flock *)arg;
----------------
michaelrj-google wrote:
this should be a `reinterpret_cast`
https://github.com/llvm/llvm-project/pull/89507
More information about the libc-commits
mailing list