Skip to content

Commit 7f3c40a

Browse files
[libc] implement pathconf/fpathconf (llvm#87165)
1 parent d043e4c commit 7f3c40a

21 files changed

+516
-0
lines changed

libc/config/linux/aarch64/entrypoints.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -290,6 +290,7 @@ set(TARGET_LIBC_ENTRYPOINTS
290290
libc.src.unistd.dup3
291291
libc.src.unistd.execve
292292
libc.src.unistd.fchdir
293+
libc.src.unistd.fpathconf
293294
libc.src.unistd.fsync
294295
libc.src.unistd.ftruncate
295296
libc.src.unistd.getcwd
@@ -301,6 +302,7 @@ set(TARGET_LIBC_ENTRYPOINTS
301302
libc.src.unistd.link
302303
libc.src.unistd.linkat
303304
libc.src.unistd.lseek
305+
libc.src.unistd.pathconf
304306
libc.src.unistd.pread
305307
libc.src.unistd.pwrite
306308
libc.src.unistd.read

libc/config/linux/riscv/entrypoints.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -289,6 +289,7 @@ set(TARGET_LIBC_ENTRYPOINTS
289289
libc.src.unistd.dup3
290290
libc.src.unistd.execve
291291
libc.src.unistd.fchdir
292+
libc.src.unistd.fpathconf
292293
libc.src.unistd.fsync
293294
libc.src.unistd.ftruncate
294295
libc.src.unistd.getcwd
@@ -300,6 +301,7 @@ set(TARGET_LIBC_ENTRYPOINTS
300301
libc.src.unistd.link
301302
libc.src.unistd.linkat
302303
libc.src.unistd.lseek
304+
libc.src.unistd.pathconf
303305
libc.src.unistd.pread
304306
libc.src.unistd.pwrite
305307
libc.src.unistd.read

libc/config/linux/x86_64/entrypoints.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -308,6 +308,7 @@ set(TARGET_LIBC_ENTRYPOINTS
308308
libc.src.unistd.dup3
309309
libc.src.unistd.execve
310310
libc.src.unistd.fchdir
311+
libc.src.unistd.fpathconf
311312
libc.src.unistd.fsync
312313
libc.src.unistd.ftruncate
313314
libc.src.unistd.getcwd
@@ -319,6 +320,7 @@ set(TARGET_LIBC_ENTRYPOINTS
319320
libc.src.unistd.link
320321
libc.src.unistd.linkat
321322
libc.src.unistd.lseek
323+
libc.src.unistd.pathconf
322324
libc.src.unistd.pipe
323325
libc.src.unistd.pread
324326
libc.src.unistd.pwrite

libc/hdr/CMakeLists.txt

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,24 @@ add_proxy_header_library(
7878
libc.include.llvm-libc-macros.sys_epoll_macros
7979
)
8080

81+
add_proxy_header_library(
82+
sys_stat_macros
83+
HDRS
84+
sys_stat_macros.h
85+
FULL_BUILD_DEPENDS
86+
libc.include.sys_stat
87+
libc.include.llvm-libc-macros.sys_stat_macros
88+
)
89+
90+
add_proxy_header_library(
91+
unistd_macros
92+
HDRS
93+
unistd_macros.h
94+
FULL_BUILD_DEPENDS
95+
libc.include.unistd
96+
libc.include.llvm-libc-macros.unistd_macros
97+
)
98+
8199
add_proxy_header_library(
82100
time_macros
83101
HDRS
@@ -97,4 +115,13 @@ add_proxy_header_library(
97115
libc.include.float
98116
)
99117

118+
add_proxy_header_library(
119+
limits_macros
120+
HDRS
121+
limits_macros.h
122+
FULL_BUILD_DEPENDS
123+
libc.include.limits
124+
libc.include.llvm-libc-macros.limits_macros
125+
)
126+
100127
add_subdirectory(types)

libc/hdr/limits_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 limits.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_LIMITS_MACROS_H
10+
#define LLVM_LIBC_HDR_LIMITS_MACROS_H
11+
12+
#ifdef LIBC_FULL_BUILD
13+
14+
#include "include/llvm-libc-macros/limits-macros.h"
15+
16+
#else // Overlay mode
17+
18+
#include <limits.h>
19+
20+
#endif // LLVM_LIBC_FULL_BUILD
21+
22+
#endif // LLVM_LIBC_HDR_LIMITS_MACROS_H

libc/hdr/sys_stat_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 sys/stat.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_SYS_STAT_MACROS_H
10+
#define LLVM_LIBC_HDR_SYS_STAT_MACROS_H
11+
12+
#ifdef LIBC_FULL_BUILD
13+
14+
#include "include/llvm-libc-macros/sys-stat-macros.h"
15+
16+
#else // Overlay mode
17+
18+
#include <sys/stat.h>
19+
20+
#endif // LLVM_LIBC_FULL_BUILD
21+
22+
#endif // LLVM_LIBC_HDR_SYS_STAT_MACROS_H

libc/hdr/unistd_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 unistd.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_UNISTD_MACROS_H
10+
#define LLVM_LIBC_HDR_UNISTD_MACROS_H
11+
12+
#ifdef LIBC_FULL_BUILD
13+
14+
#include "include/llvm-libc-macros/unistd-macros.h"
15+
16+
#else // Overlay mode
17+
18+
#include <unistd.h>
19+
20+
#endif // LLVM_LIBC_FULL_BUILD
21+
22+
#endif // LLVM_LIBC_HDR_UNISTD_MACROS_H

libc/include/llvm-libc-macros/limits-macros.h

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -225,4 +225,16 @@
225225
#define ULLONG_MIN 0ULL
226226
#endif // ULLONG_MIN
227227

228+
#ifndef _POSIX_MAX_CANON
229+
#define _POSIX_MAX_CANON 255
230+
#endif
231+
232+
#ifndef _POSIX_MAX_INPUT
233+
#define _POSIX_MAX_INPUT 255
234+
#endif
235+
236+
#ifndef _POSIX_NAME_MAX
237+
#define _POSIX_PATH_MAX 256
238+
#endif
239+
228240
#endif // LLVM_LIBC_MACROS_LIMITS_MACROS_H

libc/include/llvm-libc-macros/linux/unistd-macros.h

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,33 @@
1818
#define _SC_PAGESIZE 1
1919
#define _SC_PAGE_SIZE _SC_PAGESIZE
2020

21+
#define _PC_FILESIZEBITS 0
22+
#define _PC_LINK_MAX 1
23+
#define _PC_MAX_CANON 2
24+
#define _PC_MAX_INPUT 3
25+
#define _PC_NAME_MAX 4
26+
#define _PC_PATH_MAX 5
27+
#define _PC_PIPE_BUF 6
28+
#define _PC_2_SYMLINKS 7
29+
#define _PC_ALLOC_SIZE_MIN 8
30+
#define _PC_REC_INCR_XFER_SIZE 9
31+
#define _PC_REC_MAX_XFER_SIZE 10
32+
#define _PC_REC_MIN_XFER_SIZE 11
33+
#define _PC_REC_XFER_ALIGN 12
34+
#define _PC_SYMLINK_MAX 13
35+
#define _PC_CHOWN_RESTRICTED 14
36+
#define _PC_NO_TRUNC 15
37+
#define _PC_VDISABLE 16
38+
#define _PC_ASYNC_IO 17
39+
#define _PC_PRIO_IO 18
40+
#define _PC_SYNC_IO 19
41+
42+
// TODO: Move these limit macros to a separate file
43+
#define _POSIX_CHOWN_RESTRICTED 1
44+
#define _POSIX_PIPE_BUF 512
45+
#define _POSIX_NO_TRUNC 1
46+
#define _POSIX_VDISABLE '\0'
47+
2148
// Macro to set up the call to the __llvm_libc_syscall function
2249
// This is to prevent the call from having fewer than 6 arguments, since six
2350
// arguments are always passed to the syscall. Unnecessary arguments are

libc/src/sys/statvfs/linux/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ add_header_library(
88
libc.src.__support.common
99
libc.src.__support.CPP.optional
1010
libc.include.sys_syscall
11+
libc.include.llvm-libc-types.struct_statvfs
1112
)
1213

1314
add_entrypoint_object(

0 commit comments

Comments
 (0)