summaryrefslogtreecommitdiff
path: root/libc/src/__support/File/linux
AgeCommit message (Collapse)Author
2025-10-08[libc] Fix integer overflow for large offsets in lseek. (#162394)Jackson Stogel
Currently, the return value `LIBC_NAMESPACE::syscall_impl<int>(SYS_lseek, fd, offset, whence)` will overflow when seeking on files >4GB.
2025-07-23[libc][NFC] Add stdint.h proxy header to fix dependency issue with ↵lntue
<stdint.h> includes. (#150303) https://github.com/llvm/llvm-project/issues/149993
2025-06-13[libc][NFC] clean internal fd handling (#143991)Michael Jones
The previous internal fcntl implementation modified errno directly, this patch fixes that. This patch also moves open and close into OSUtil since they are used in multiple places. There are more places that need similar cleanup but only got comments in this patch to keep it relatively reviewable. Related to: https://github.com/llvm/llvm-project/issues/143937
2025-06-11[libc] Move libc_errno.h to libc/src/__support and make ↵lntue
LIBC_ERRNO_MODE_SYSTEM to be header-only. (#143187) This is the first step in preparation for: https://discourse.llvm.org/t/rfc-make-clang-builtin-math-functions-constexpr-with-llvm-libc-to-support-c-23-constexpr-math-functions/86450
2024-10-28[libc] remove #include <fcntl.h> and add proxy or type (#113836)Job Henandez Lara
2024-10-01[libc][stdio] Use proxy headers of stdio.h in src and test folders. (#110067)lntue
https://github.com/llvm/llvm-project/issues/60481
2024-07-12[libc] Migrate to using LIBC_NAMESPACE_DECL for namespace declaration (#98597)Petr Hosek
This is a part of #97655.
2024-07-12Revert "[libc] Migrate to using LIBC_NAMESPACE_DECL for namespace ↵Mehdi Amini
declaration" (#98593) Reverts llvm/llvm-project#98075 bots are broken
2024-07-11[libc] Migrate to using LIBC_NAMESPACE_DECL for namespace declaration (#98075)Petr Hosek
This is a part of #97655.
2024-07-11Reland: [libc] Move off_t and stdio macros to proxy hdrs (#98384)Michael Jones
reland of https://github.com/llvm/llvm-project/pull/98215 Additionally adds proxy headers for FILE and the fopencookie types The arm32 build has been failing due to redefinitions of the off_t type. This patch fixes this by moving off_t to a proper proxy header. To do this, it also moves stdio macros to a proxy header to hopefully avoid including this proxy header alongside this public stdio.h.
2024-07-09Revert "[libc] Move off_t and stdio macros to proxy hdrs" (#98242)Michael Jones
Reverts llvm/llvm-project#98215 Breaks linux bots
2024-07-09[libc] Move off_t and stdio macros to proxy hdrs (#98215)Michael Jones
The arm32 build has been failing due to redefinitions of the off_t type. This patch fixes this by moving off_t to a proper proxy header. To do this, it also moves stdio macros to a proxy header to hopefully avoid including this proxy header alongside this public stdio.h.
2024-07-08[libc][NFC] Adjust use of off_t internally (#68269)Mikhail R. Gadelha
This patch includes changes related to the use of off_t in libc, targeted at 32-bit systems: in several places, the offset is used either as a long or an off_t (64-bit signed int), but in 32-bit systems a long type is only 32 bits long. Fix a warning in mmap where a long offset is expected, but we were passing an off_t. A static_cast and a comment were added to explain that we know we are ignoring the upper 32-bit of the off_t in 32-bit systems. The code in pread and pwrite was slightly improved to remove a #ifdef LIBC_TARGET_ARCH_IS_RISCV32; we are using an if constexpr now. The Linux file operations were changed to use off_t instead of a long where applicable. No changes were made to the standard API, e.g., ftell returns the offset as an int so we added a static_cast and a comment explaining that this will cause a loss of integer precision in 32-bit systems.
2024-07-07[libc] fix aarch64 GCC build (#97932)Schrodinger ZHU Yifan
This PR fix several build errors on aarch64 targets when building with gcc: - uninitialized values leading to `Werrors` - undefined builtin functions - glibc header pollution
2024-06-14[libc] Add the implementation of the fdopen function (#94186)Xu Zhang
Fixes #93711 . This patch implements the ``fdopen`` function. Given that ``fdopen`` internally calls ``fcntl``, the implementation of ``fcntl`` has been moved to the ``__support/OSUtil``, where it serves as an internal public function.
2023-12-13[libc] fix -Wmacro-redefined (#75261)Nick Desaulniers
When building with compiler-rt enabled, warnings such as the following are observed: llvm-project/llvm/build/projects/compiler-rt/../libc/include/llvm-libc-macros/linux/sys-stat-macros.h:46:9: warning: 'S_IXOTH' macro redefined [-Wmacro-redefined] #define S_IXOTH 00001 ^ llvm-project/llvm/build/projects/compiler-rt/../libc/include/llvm-libc-macros/linux/fcntl-macros.h:61:9: note: previous definition is here #define S_IXOTH 01 ^ It looks like we have these multiply defined. Deduplicate these flags; users should expect to find them in sys/stat.h. S_FIFO was wrong anyways (should have been S_IFIFO).
2023-09-26[libc] Mass replace enclosing namespace (#67032)Guillaume Chatelet
This is step 4 of https://discourse.llvm.org/t/rfc-customizable-namespace-to-allow-testing-the-libc-when-the-system-libc-is-also-llvms-libc/73079
2023-09-21[libc][clang-tidy] Add llvm-header-guard to get consistant naming and ↵Guillaume Chatelet
prevent file copy/paste issues. (#66477)
2023-09-06[libc] Unify lseek implementationsMikhail R. Gadelha
In patch D157792, the calls to SYS_llseek/SYS_llseek for 32-bit systems were fixed in lseek.cpp but there was another implementation in file.cpp that was missed. To reduce the code duplication, this patch unifies both call sites to use a new lseekimpl function. Reviewed By: sivachandra Differential Revision: https://reviews.llvm.org/D159208
2023-08-17[libc][NFC] Put definitions of stdout and friends into their own object files.Siva Chandra Reddy
This is done so that tests which only require platform file but not the platform streams can be run as unit tests. The tests which use platform streams can only be hermetic tests to avoid conflicts with the system-libc streams. Fixes: https://github.com/llvm/llvm-project/issues/64663 https://github.com/llvm/llvm-project/issues/63558 Reviewed By: jhuber6 Differential Revision: https://reviews.llvm.org/D158193
2023-08-07[libc][cleanup] Fix most conversion warningsMichael Jones
This patch is large, but is almost entirely just adding casts to calls to syscall_impl. Much of the work was done programatically, with human checking when the syntax or types got confusing. Reviewed By: mcgrathr Differential Revision: https://reviews.llvm.org/D156950
2023-08-03[libc] Add support to compile some syscalls on 32 bit platformMikhail R. Gadelha
This patch adds a bunch of ifdefs to handle the 32 bit versions of some syscalls, which often only append a 64 to the name of the syscall (with exception of SYS_lseek -> SYS_llseek and SYS_futex -> SYS_futex_time64) This patch also tries to handle cases where wait4 is not available (as in riscv32): to implement wait, wait4 and waitpid when wait4 is not available, we check for alternative wait calls and ultimately rely on waitid to implement them all. In riscv32, only waitid is available, so we need it to support this platform. Reviewed By: michaelrj Differential Revision: https://reviews.llvm.org/D148371
2023-06-21[libc] Make close function of the internal File class cleanup the file object.Siva Chandra Reddy
Before this change, a separate static method named cleanup was used to cleanup the file. Instead, now the close method cleans up the full file object using the platform's close function. Reviewed By: lntue Differential Revision: https://reviews.llvm.org/D153377
2023-06-19[libc] Remove the requirement of a platform-flush operation in File abstraction.Siva Chandra Reddy
The libc flush operation is not supposed to trigger a platform level flush operation. See "Notes" on this Linux man page: https://man7.org/linux/man-pages/man3/fflush.3.html Reviewed By: michaelrj Differential Revision: https://reviews.llvm.org/D153182
2023-06-15[libc] Move the definitions of the standard IO streams to the platformJoseph Huber
This patch moves the definitions of the standard IO streams to the platform file definition. This is necessary because previously we had a level of indirection where the stream's `FILE *` was initialized based on the pointer to the internal `__llvm_libc` version. This cannot be resolved ahead of time by the linker because the address will not be known until runtime. This caused the previous implementation to emit a global constructor to initialize the pointer to the actual `FILE *`. By moving these definitions so that we can bind their address to the original file type we can avoid this global constructor. This file keeps the entrypoints, but makes them empty files only containing an external reference. This is so they still appear as entrypoints and get emitted as declarations in the generated headers. Reviewed By: lntue, sivachandra Differential Revision: https://reviews.llvm.org/D152983
2023-05-30[libc][NFC] Move the Linux file implementation to a subdirectoryJoseph Huber
This patch simply moves the special handling for `linux` files to a subdirectory. This is done to make it easier in the future to extend this support to targets (like the GPU) that will have different dependencies. Reviewed By: lntue Differential Revision: https://reviews.llvm.org/D151231