Skip to content

Commit aca5117

Browse files
authored
[libc] Implement fcntl() function (#89507)
Fixes #84968. Implements the `fcntl()` function defined in the `fcntl.h` header.
1 parent d1b3648 commit aca5117

File tree

22 files changed

+545
-0
lines changed

22 files changed

+545
-0
lines changed

libc/config/linux/aarch64/entrypoints.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ set(TARGET_LIBC_ENTRYPOINTS
2222

2323
# fcntl.h entrypoints
2424
libc.src.fcntl.creat
25+
libc.src.fcntl.fcntl
2526
libc.src.fcntl.open
2627
libc.src.fcntl.openat
2728

libc/config/linux/riscv/entrypoints.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ set(TARGET_LIBC_ENTRYPOINTS
2222

2323
# fcntl.h entrypoints
2424
libc.src.fcntl.creat
25+
libc.src.fcntl.fcntl
2526
libc.src.fcntl.open
2627
libc.src.fcntl.openat
2728

libc/config/linux/x86_64/entrypoints.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ set(TARGET_LIBC_ENTRYPOINTS
2222

2323
# fcntl.h entrypoints
2424
libc.src.fcntl.creat
25+
libc.src.fcntl.fcntl
2526
libc.src.fcntl.open
2627
libc.src.fcntl.openat
2728

libc/hdr/CMakeLists.txt

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,15 @@ add_proxy_header_library(
3232
libc.include.math
3333
)
3434

35+
add_proxy_header_library(
36+
fcntl_macros
37+
HDRS
38+
fcntl_macros.h
39+
FULL_BUILD_DEPENDS
40+
libc.include.llvm-libc-macros.fcntl_macros
41+
libc.include.fcntl
42+
)
43+
3544
add_proxy_header_library(
3645
fenv_macros
3746
HDRS

libc/hdr/fcntl_macros.h

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
//===-- Definition of macros from fcntl/fcntl.h ---------------------------===//
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+
#ifndef LLVM_LIBC_HDR_FCNTL_MACROS_H
10+
#define LLVM_LIBC_HDR_FCNTL_MACROS_H
11+
12+
#ifdef LIBC_FULL_BUILD
13+
14+
#include "include/llvm-libc-macros/fcntl-macros.h"
15+
16+
#else // Overlay mode
17+
18+
#include <fcntl.h>
19+
20+
#endif // LLVM_LIBC_FULL_BUILD
21+
22+
#endif // LLVM_LIBC_HDR_FCNTL_MACROS_H

libc/hdr/types/CMakeLists.txt

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,30 @@ add_proxy_header_library(
1414
libc.include.llvm-libc-types.struct_epoll_event
1515
)
1616

17+
add_proxy_header_library(
18+
struct_flock
19+
HDRS
20+
struct_flock.h
21+
FULL_BUILD_DEPENDS
22+
libc.include.llvm-libc-types.struct_flock
23+
)
24+
25+
add_proxy_header_library(
26+
struct_flock64
27+
HDRS
28+
struct_flock64.h
29+
FULL_BUILD_DEPENDS
30+
libc.include.llvm-libc-types.struct_flock64
31+
)
32+
33+
add_proxy_header_library(
34+
struct_f_owner_ex
35+
HDRS
36+
struct_f_owner_ex.h
37+
FULL_BUILD_DEPENDS
38+
libc.include.llvm-libc-types.struct_f_owner_ex
39+
)
40+
1741
add_proxy_header_library(
1842
struct_timespec
1943
HDRS

libc/hdr/types/struct_f_owner_ex.h

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
//===-- Proxy for struct f_owner_ex --------------------------------------===//
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+
#ifndef LLVM_LIBC_HDR_TYPES_STRUCT_F_OWNER_EX_H
9+
#define LLVM_LIBC_HDR_TYPES_STRUCT_F_OWNER_EX_H
10+
11+
#ifdef LIBC_FULL_BUILD
12+
13+
#include "include/llvm-libc-types/struct_f_owner_ex.h"
14+
15+
#else
16+
17+
#include <fcntl.h>
18+
19+
#endif // LIBC_FULL_BUILD
20+
21+
#endif // LLVM_LIBC_HDR_TYPES_STRUCT_F_OWNER_EX_H

libc/hdr/types/struct_flock.h

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
//===-- Proxy for struct flock -------------------------------------------===//
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+
#ifndef LLVM_LIBC_HDR_TYPES_STRUCT_FLOCK_H
9+
#define LLVM_LIBC_HDR_TYPES_STRUCT_FLOCK_H
10+
11+
#ifdef LIBC_FULL_BUILD
12+
13+
#include "include/llvm-libc-types/struct_flock.h"
14+
15+
#else
16+
17+
#include <fcntl.h>
18+
19+
#endif // LIBC_FULL_BUILD
20+
21+
#endif // LLVM_LIBC_HDR_TYPES_STRUCT_FLOCK_H

libc/hdr/types/struct_flock64.h

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
//===-- Proxy for struct flock64 -----------------------------------------===//
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+
#ifndef LLVM_LIBC_HDR_TYPES_STRUCT_FLOCK64_H
9+
#define LLVM_LIBC_HDR_TYPES_STRUCT_FLOCK64_H
10+
11+
#ifdef LIBC_FULL_BUILD
12+
13+
#include "include/llvm-libc-types/struct_flock64.h"
14+
15+
#else
16+
17+
#include <fcntl.h>
18+
19+
#endif // LIBC_FULL_BUILD
20+
21+
#endif // LLVM_LIBC_HDR_TYPES_STRUCT_FLOCK64_H

libc/include/CMakeLists.txt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,10 @@ add_gen_header(
4343
DEPENDS
4444
.llvm-libc-macros.fcntl_macros
4545
.llvm-libc-types.mode_t
46+
.llvm-libc-types.struct_flock
47+
.llvm-libc-types.struct_flock64
48+
.llvm-libc-types.off64_t
49+
.llvm-libc-types.pid_t
4650
.llvm-libc-types.off_t
4751
.llvm_libc_common_h
4852
)

0 commit comments

Comments
 (0)