[libc-commits] [libc] [libc] Implement posix_fadvise64. (PR #223294)

Jeff Bailey via libc-commits libc-commits at lists.llvm.org
Mon Sep 14 06:47:01 PDT 2026


================
@@ -0,0 +1,84 @@
+//===----------------------------------------------------------------------===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+///
+/// \file
+/// Unittests for posix_fadvise64.
+///
+//===----------------------------------------------------------------------===//
+
+#include "hdr/errno_macros.h"
+#include "hdr/fcntl_macros.h"
+#include "hdr/sys_stat_macros.h"
+#include "hdr/types/off64_t.h"
+#include "src/__support/CPP/scope.h"
+#include "src/fcntl/creat.h"
+#include "src/fcntl/posix_fadvise64.h"
+#include "src/unistd/close.h"
+#include "src/unistd/pipe.h"
+#include "src/unistd/unlink.h"
+#include "test/UnitTest/ErrnoCheckingTest.h"
+#include "test/UnitTest/Test.h"
+
+using LlvmLibcPosixFadvise64Test = LIBC_NAMESPACE::testing::ErrnoCheckingTest;
+
+TEST_F(LlvmLibcPosixFadvise64Test, InvalidFileDescriptor) {
+  EXPECT_EQ(LIBC_NAMESPACE::posix_fadvise64(-1, 0, 0, POSIX_FADV_NORMAL),
+            EBADF);
+  // posix_fadvise64 must return the error directly and not set errno.
+  ASSERT_ERRNO_SUCCESS();
+}
+
+TEST_F(LlvmLibcPosixFadvise64Test, ValidFile) {
+  constexpr const char *TEST_FILE = "testdata/posix_fadvise64.test";
+  int fd = LIBC_NAMESPACE::creat(TEST_FILE, S_IRWXU);
+  ASSERT_GT(fd, 0);
----------------
kaladron wrote:

I don't think this assert makes sense since if stdin is closed, fd 0 could be assigned.

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


More information about the libc-commits mailing list