[libc-commits] [libc] [libc] Implement fallocate (PR #222843)

via libc-commits libc-commits at lists.llvm.org
Fri Sep 11 03:29:14 PDT 2026


github-actions[bot] wrote:

<!--LLVM CODE FORMAT COMMENT: {clang-format}-->


:warning: C/C++ code formatter, clang-format found issues in your code. :warning:

<details>
<summary>
You can test this locally with the following command:
</summary>

``````````bash
git-clang-format --diff origin/main HEAD --extensions cpp,h -- libc/src/__support/OSUtil/linux/syscall_wrappers/fallocate.h libc/src/fcntl/fallocate.h libc/src/fcntl/linux/fallocate.cpp libc/test/src/fcntl/fallocate_test.cpp libc/include/llvm-libc-macros/linux/fcntl-macros.h --diff_from_common_commit
``````````

:warning:
The reproduction instructions above might return results for more than one PR
in a stack if you are using a stacked PR workflow. You can limit the results by
changing `origin/main` to the base branch/commit you want to compare against.
:warning:

</details>

<details>
<summary>
View the diff from clang-format here.
</summary>

``````````diff
diff --git a/libc/src/fcntl/fallocate.h b/libc/src/fcntl/fallocate.h
index bfc5605fe..2924637c3 100644
--- a/libc/src/fcntl/fallocate.h
+++ b/libc/src/fcntl/fallocate.h
@@ -14,12 +14,12 @@
 #ifndef LLVM_LIBC_SRC_FCNTL_FALLOCATE_H
 #define LLVM_LIBC_SRC_FCNTL_FALLOCATE_H
 
-#include "src/__support/macros/config.h"
 #include "hdr/types/off_t.h"
+#include "src/__support/macros/config.h"
 
 namespace LIBC_NAMESPACE_DECL {
 
-  int fallocate(int fd, int mode, off_t offset, off_t size);
+int fallocate(int fd, int mode, off_t offset, off_t size);
 
 }
 
diff --git a/libc/src/fcntl/linux/fallocate.cpp b/libc/src/fcntl/linux/fallocate.cpp
index 9237428f0..593619888 100644
--- a/libc/src/fcntl/linux/fallocate.cpp
+++ b/libc/src/fcntl/linux/fallocate.cpp
@@ -14,19 +14,20 @@
 
 #include "src/fcntl/fallocate.h"
 
+#include "hdr/types/off_t.h"
 #include "src/__support/OSUtil/linux/syscall_wrappers/fallocate.h"
-#include "src/__support/macros/config.h"
 #include "src/__support/libc_errno.h"
-#include "hdr/types/off_t.h"
+#include "src/__support/macros/config.h"
 
 namespace LIBC_NAMESPACE_DECL {
 
-  LLVM_LIBC_FUNCTION(int, fallocate, (int fd, int mode, off_t offset, off_t size)) {
-    auto result = linux_syscalls::fallocate(fd, mode, offset, size);
-    if (!result.has_value()) {
-      libc_errno = result.error();
-      return -1;
-    }
-    return 0;
+LLVM_LIBC_FUNCTION(int, fallocate,
+                   (int fd, int mode, off_t offset, off_t size)) {
+  auto result = linux_syscalls::fallocate(fd, mode, offset, size);
+  if (!result.has_value()) {
+    libc_errno = result.error();
+    return -1;
   }
+  return 0;
 }
+} // namespace LIBC_NAMESPACE_DECL
diff --git a/libc/test/src/fcntl/fallocate_test.cpp b/libc/test/src/fcntl/fallocate_test.cpp
index 62b2258cc..75e6ba359 100644
--- a/libc/test/src/fcntl/fallocate_test.cpp
+++ b/libc/test/src/fcntl/fallocate_test.cpp
@@ -6,15 +6,15 @@
 //
 //===----------------------------------------------------------------------===//
 
+#include "src/__support/libc_errno.h"
 #include "src/fcntl/fallocate.h"
 #include "src/fcntl/open.h"
 #include "src/sys/stat/fstat.h"
 #include "src/unistd/close.h"
 #include "src/unistd/unlink.h"
-#include "src/__support/libc_errno.h"
+#include "test/UnitTest/ErrnoCheckingTest.h"
 #include "test/UnitTest/ErrnoSetterMatcher.h"
 #include "test/UnitTest/Test.h"
-#include "test/UnitTest/ErrnoCheckingTest.h"
 #include <fcntl.h>
 #include <sys/stat.h>
 
@@ -46,9 +46,8 @@ TEST(LlvmLibcFallocateTest, KeepSize) {
   ASSERT_GT(fd, 0);
 
   // Pre-allocate space at offset 8192, length 4096, but keep file size at 0
-  ASSERT_THAT(
-      LIBC_NAMESPACE::fallocate(fd, FALLOC_FL_KEEP_SIZE, 8192, 4096),
-      Succeeds(0));
+  ASSERT_THAT(LIBC_NAMESPACE::fallocate(fd, FALLOC_FL_KEEP_SIZE, 8192, 4096),
+              Succeeds(0));
 
   struct stat st;
   ASSERT_EQ(LIBC_NAMESPACE::fstat(fd, &st), 0);

``````````

</details>


https://github.com/llvm/llvm-project/pull/222843


More information about the libc-commits mailing list