summaryrefslogtreecommitdiff
path: root/libc/src/__support/File/file.cpp
AgeCommit message (Collapse)Author
2025-11-14[libc] replace for loops with a call to memcpy in File (#165219)Shreeyash Pandey
Addresses `TODO`s in file.cpp by replacing data copies via for loops with calls to inline_memcpy. Signed-off-by: Shreeyash Pandey <shreeyash335@gmail.com>
2025-08-19[libc] Fix copy/paste error in file.cpp (#150802)codefaber
Fix using wrong variable due to copy/paste error. --------- Co-authored-by: codefaber <codefaber>
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
2025-01-09[libc] Support _IONBF buffering for read_unlocked (#120677)Jack Huang
Support _IONBF buffering for read_unlocked. Add the functions read_unlocked_nbf() and read_unlocked_fbf(). Fixes: #120155
2024-11-03[libc] Add proxy headers to handle memory allocation associated with the ↵Job Henandez Lara
header `#include <stdlib.h> (#114690) This finishes the work from https://github.com/llvm/llvm-project/pull/114453 by adding proxy headers for `malloc`, `realloc`, `free` and `aligned_alloc`.
2024-07-20[libc] Enable most of the libc entrypoitns for riscv (#99771)Mikhail R. Gadelha
This patch enables most of the libc entrypoints for riscv, except for fstatvfs, statvfs, dmull and fmull which are currently failing compilation. float16 is also not added, as rv32 doesn't seem to support it yet. This patch also fixes the call to seek, which should take an off_t, and was missed in PR #68269.
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.
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-08-09[libc] Rework the file handling for the GPUJoseph Huber
The GPU has much tighter requirements for handling IO functions. Previously we attempted to define the GPU as one of the platform files. Using a common interface allowed us to easily define these functions without much extra work. However, it became more clear that this was a poor fit for the GPU. The file interface uses function pointers, which prevented inlining and caused bad perfromance and resource usage on the GPU. Further, using an actual `FILE` type rather than referring to it as a host stub prevented us from usin files coming from the host on the GPU device. After talking with @sivachandra, the approach now is to simply define GPU specific versions of the functions we intend to support. Also, we are ignoring `errno` for the time being as it is unlikely we will ever care about supporting it fully. Reviewed By: sivachandra Differential Revision: https://reviews.llvm.org/D157427
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-05[libc] Add initial support for 'puts' and 'fputs' to the GPUJoseph Huber
This patch adds the initial support required to support basic priting in `stdio.h` via `puts` and `fputs`. This is done using the existing LLVM C library `File` API. In this sense we can think of the RPC interface as our system call to dump the character string to the file. We carry a `uintptr_t` reference as our native "file descriptor" as it will be used as an opaque reference to the host's version once functions like `fopen` are supported. For some unknown reason the declaration of the `StdIn` variable causes both the AMDGPU and NVPTX backends to crash if I use the `READ` flag. This is not used currently as we only support output now, but it needs to be fixed Reviewed By: sivachandra, lntue Differential Revision: https://reviews.llvm.org/D151282
2023-03-03[libc] move stdlib and stdio to new errno patternMichael Jones
Fixes https://github.com/llvm/llvm-project/issues/61071 Reviewed By: sivachandra Differential Revision: https://reviews.llvm.org/D145191
2022-12-22[libc][NFC] Use operator delete to cleanup a File object.Siva Chandra Reddy
The File API has been refactored to allow cleanup using operator delete. Reviewed By: lntue Differential Revision: https://reviews.llvm.org/D140574
2022-12-22[libc] Handle allocation failures gracefully in FILE related API.Siva Chandra Reddy
Few uses of free have not yet been replaced by the custom operator delete yet. They will be done in a follow up patch. Reviewed By: lntue, michaelrj Differential Revision: https://reviews.llvm.org/D140526
2022-12-12[libc] move errno out of file internalsMichael Jones
Now errno is only set by the terminal entrypoints, and not the internal implementations. This patch is part of the larger effort to not set errno in libc internal code: https://github.com/llvm/llvm-project/issues/59278 Reviewed By: sivachandra Differential Revision: https://reviews.llvm.org/D139576
2022-11-07[libc] Add implementations of ftell.Siva Chandra Reddy
Reviewed By: michaelrj, lntue Differential Revision: https://reviews.llvm.org/D137395
2022-11-04[libc] Add implementation of setbuf and setvbuf.Siva Chandra Reddy
Reviewed By: michaelrj Differential Revision: https://reviews.llvm.org/D137356
2022-11-02[libc] Add implementation of ungetc.Siva Chandra Reddy
A bug in the file read logic has also been fixed along the way. Parts of the ungetc tests will fail without that bug fixed. Reviewed By: michaelrj Differential Revision: https://reviews.llvm.org/D137286
2022-09-21[libc] add fputs and putsMichael Jones
add fputs, puts, and the EOF macro that they use. Reviewed By: sivachandra Differential Revision: https://reviews.llvm.org/D134328
2022-08-22[NFC][libc] Switch File impl to span instead of ArrayRefGuillaume Chatelet
2022-06-16[libc] fix line buffered empty file writesMichael Jones
Previously, any line buffered write of size 0 would cause an error. The variable used to track the index of the last newline started at the size of the write - 1, which underflowed. Now it's handled properly, and a test has been added to prevent regressions. Reviewed By: sivachandra, lntue Differential Revision: https://reviews.llvm.org/D127914
2022-06-15[libc][Obvious] Removed few unused vars.Siva Chandra Reddy
2022-06-10[libc] add buffering to FILE writesMichael Jones
Previously all FILE objects were fully buffered, this patch adds line buffering and unbuffered output, as well as applying them to stdout and stderr. Reviewed By: sivachandra Differential Revision: https://reviews.llvm.org/D126829
2022-04-20[libc] Add the implementation of the fflush function.Siva Chandra Reddy
Note that the underlying flush implementation does not yet fully implement the POSIX standard. It is complete with respect to the C standard however. A future change will add the POSIX behavior. It should not affect the implementation of the fflush function however as the POSIX behavior will be added in a lower layer. Reviewed By: lntue Differential Revision: https://reviews.llvm.org/D124073
2022-04-20[libc] Add GNU extention functions fread_unlocked and fwrite_unlocked.Siva Chandra Reddy
POSIX locking and unlocking functions flockfile and funlockfile have also been added. The locking is not recursive yet. A future patch will make the underlying lock a recursive lock. Reviewed By: lntue Differential Revision: https://reviews.llvm.org/D123986
2022-03-23[libc][File] Fix a bug under fseek(..., SEEK_CUR).Siva Chandra Reddy
Reviewed By: lntue Differential Revision: https://reviews.llvm.org/D122284
2022-03-17[libc][NFC] Add a separate flag for capturing the '+' in fopen mode string.Siva Chandra Reddy
Having a separate flag helps in setting up proper flags when implementing, say the Linux specialization of File. Along the way, a signature for a function which is to be used to open files has been added. The implementation of the function is to be included in platform specializations. Reviewed By: lntue Differential Revision: https://reviews.llvm.org/D121889
2022-02-15[libc] Add a platform independent buffered file IO data structure.Siva Chandra Reddy
Reviewed By: lntue Differential Revision: https://reviews.llvm.org/D119458