aboutsummaryrefslogtreecommitdiff
path: root/libc/include
diff options
context:
space:
mode:
authorVinayak Dev <104419489+vinayakdsci@users.noreply.github.com>2024-05-01 23:48:44 +0530
committerGitHub <noreply@github.com>2024-05-01 11:18:44 -0700
commitaca511734f5ff6204fdc65427566c8bd3b810a24 (patch)
tree2ce595024c5e12c967d59cd94d287a66e2e62ea7 /libc/include
parentd1b3648ed9da1ea8f1ca62a150b519f9d08fffaf (diff)
downloadllvm-aca511734f5ff6204fdc65427566c8bd3b810a24.zip
llvm-aca511734f5ff6204fdc65427566c8bd3b810a24.tar.gz
llvm-aca511734f5ff6204fdc65427566c8bd3b810a24.tar.bz2
[libc] Implement fcntl() function (#89507)
Fixes #84968. Implements the `fcntl()` function defined in the `fcntl.h` header.
Diffstat (limited to 'libc/include')
-rw-r--r--libc/include/CMakeLists.txt4
-rw-r--r--libc/include/llvm-libc-macros/linux/fcntl-macros.h31
-rw-r--r--libc/include/llvm-libc-types/CMakeLists.txt3
-rw-r--r--libc/include/llvm-libc-types/struct_f_owner_ex.h25
-rw-r--r--libc/include/llvm-libc-types/struct_flock.h25
-rw-r--r--libc/include/llvm-libc-types/struct_flock64.h25
6 files changed, 113 insertions, 0 deletions
diff --git a/libc/include/CMakeLists.txt b/libc/include/CMakeLists.txt
index 6dea8e5..6101ec1 100644
--- a/libc/include/CMakeLists.txt
+++ b/libc/include/CMakeLists.txt
@@ -43,6 +43,10 @@ add_gen_header(
DEPENDS
.llvm-libc-macros.fcntl_macros
.llvm-libc-types.mode_t
+ .llvm-libc-types.struct_flock
+ .llvm-libc-types.struct_flock64
+ .llvm-libc-types.off64_t
+ .llvm-libc-types.pid_t
.llvm-libc-types.off_t
.llvm_libc_common_h
)
diff --git a/libc/include/llvm-libc-macros/linux/fcntl-macros.h b/libc/include/llvm-libc-macros/linux/fcntl-macros.h
index 1d4e5bb..8ee9586 100644
--- a/libc/include/llvm-libc-macros/linux/fcntl-macros.h
+++ b/libc/include/llvm-libc-macros/linux/fcntl-macros.h
@@ -67,5 +67,36 @@
#define F_SETFD 2
#define F_GETFL 3
#define F_SETFL 4
+#define F_GETLK 5
+#define F_SETLK 6
+#define F_SETLKW 7
+#define F_SETOWN 8
+#define F_GETOWN 9
+#define F_SETSIG 10
+#define F_GETSIG 11
+#define F_GETLK64 12
+#define F_SETLK64 13
+#define F_SETLKW64 14
+#define F_SETOWN_EX 15
+#define F_GETOWN_EX 16
+
+// Open File Description Locks.
+#define F_OFD_GETLK 36
+#define F_OFD_SETLK 37
+#define F_OFD_SETLKW 38
+
+// Close on succesful
+#define F_CLOEXEC 1
+
+#define F_RDLCK 0
+#define F_WRLCK 1
+#define F_UNLCK 2
+
+// For Large File Support
+#if defined(_LARGEFILE64_SOURCE)
+#define F_GETLK F_GETLK64
+#define F_SETLK F_SETLK64
+#define F_SETLKW F_SETLKW64
+#endif
#endif // LLVM_LIBC_MACROS_LINUX_FCNTL_MACROS_H
diff --git a/libc/include/llvm-libc-types/CMakeLists.txt b/libc/include/llvm-libc-types/CMakeLists.txt
index 16e343d..018b6c5 100644
--- a/libc/include/llvm-libc-types/CMakeLists.txt
+++ b/libc/include/llvm-libc-types/CMakeLists.txt
@@ -60,6 +60,9 @@ add_header(rlim_t HDR rlim_t.h)
add_header(time_t HDR time_t.h)
add_header(stack_t HDR stack_t.h)
add_header(suseconds_t HDR suseconds_t.h)
+add_header(struct_flock HDR struct_flock.h DEPENDS .off_t .pid_t)
+add_header(struct_flock64 HDR struct_flock64.h DEPENDS .off64_t .pid_t)
+add_header(struct_f_owner_ex HDR struct_f_owner_ex.h DEPENDS .pid_t)
add_header(struct_timeval HDR struct_timeval.h DEPENDS .suseconds_t .time_t)
add_header(struct_rlimit HDR struct_rlimit.h DEPENDS .rlim_t)
add_header(struct_rusage HDR struct_rusage.h DEPENDS .struct_timeval)
diff --git a/libc/include/llvm-libc-types/struct_f_owner_ex.h b/libc/include/llvm-libc-types/struct_f_owner_ex.h
new file mode 100644
index 0000000..c9cc85f
--- /dev/null
+++ b/libc/include/llvm-libc-types/struct_f_owner_ex.h
@@ -0,0 +1,25 @@
+//===-- Definition of type struct f_owner_ex ------------------------------===//
+//
+// 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
+//
+//===----------------------------------------------------------------------===//
+
+#ifndef LLVM_LIBC_TYPES_STRUCT_F_OWNER_EX_H
+#define LLVM_LIBC_TYPES_STRUCT_F_OWNER_EX_H
+
+#include "llvm-libc-types/pid_t.h"
+
+enum pid_type {
+ F_OWNER_TID = 0,
+ F_OWNER_PID,
+ F_OWNER_PGRP,
+};
+
+struct f_owner_ex {
+ enum pid_type type;
+ pid_t pid;
+};
+
+#endif // LLVM_LIBC_TYPES_STRUCT_F_OWNER_EX_H
diff --git a/libc/include/llvm-libc-types/struct_flock.h b/libc/include/llvm-libc-types/struct_flock.h
new file mode 100644
index 0000000..51c9d27
--- /dev/null
+++ b/libc/include/llvm-libc-types/struct_flock.h
@@ -0,0 +1,25 @@
+//===-- Definition of type struct flock64 ---------------------------------===//
+//
+// 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
+//
+//===----------------------------------------------------------------------===//
+
+#ifndef LLVM_LIBC_TYPES_STRUCT_FLOCK_H
+#define LLVM_LIBC_TYPES_STRUCT_FLOCK_H
+
+#include "llvm-libc-types/off_t.h"
+#include "llvm-libc-types/pid_t.h"
+
+#include <stdint.h>
+
+struct flock {
+ int16_t l_type;
+ int16_t l_whence;
+ off_t l_start;
+ off_t l_len;
+ pid_t l_pid;
+};
+
+#endif // LLVM_LIBC_TYPES_STRUCT_FLOCK_H
diff --git a/libc/include/llvm-libc-types/struct_flock64.h b/libc/include/llvm-libc-types/struct_flock64.h
new file mode 100644
index 0000000..ac50003
--- /dev/null
+++ b/libc/include/llvm-libc-types/struct_flock64.h
@@ -0,0 +1,25 @@
+//===-- Definition of type struct flock64 ---------------------------------===//
+//
+// 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
+//
+//===----------------------------------------------------------------------===//
+
+#ifndef LLVM_LIBC_TYPES_STRUCT_FLOCK64_H
+#define LLVM_LIBC_TYPES_STRUCT_FLOCK64_H
+
+#include "llvm-libc-types/off64_t.h"
+#include "llvm-libc-types/pid_t.h"
+
+#include <stdint.h>
+
+struct flock64 {
+ int16_t l_type;
+ int16_t l_whence;
+ off64_t l_start;
+ off64_t l_len;
+ pid_t l_pid;
+};
+
+#endif // LLVM_LIBC_TYPES_STRUCT_FLOCK64_H