[libc-commits] [libc] [libc] Implement fgetpos/fsetpos (PR #221349)

Jeff Bailey via libc-commits libc-commits at lists.llvm.org
Fri Oct 9 04:04:03 PDT 2026


================
@@ -0,0 +1,308 @@
+//===----------------------------------------------------------------------===//
+//
+// 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 fgetpos
+///
+//===----------------------------------------------------------------------===//
+
+#include "hdr/stdio_macros.h"
+#include "hdr/types/fpos_t.h"
+#include "hdr/types/wint_t.h"
+#include "src/__support/CPP/scope.h"
+#include "src/stdio/fclose.h"
+#include "src/stdio/feof.h"
+#include "src/stdio/ferror.h"
+#include "src/stdio/fgetpos.h"
+#include "src/stdio/fopen.h"
+#include "src/stdio/fread.h"
+#include "src/stdio/fseek.h"
+#include "src/stdio/fwrite.h"
+#include "src/stdio/setvbuf.h"
+#include "src/stdio/ungetc.h"
+#include "src/wchar/fgetwc.h"
+#include "src/wchar/fputwc.h"
+#include "src/wchar/fwide.h"
+#include "src/wchar/mbsinit.h"
+#include "src/wchar/ungetwc.h"
+#include "test/UnitTest/ErrnoCheckingTest.h"
+#include "test/UnitTest/ErrnoSetterMatcher.h"
+#include "test/UnitTest/Test.h"
+
+using LIBC_NAMESPACE::cpp::scope_exit;
+using LIBC_NAMESPACE::testing::ErrnoSetterMatcher::Fails;
+using LIBC_NAMESPACE::testing::ErrnoSetterMatcher::Succeeds;
+
+class LlvmLibcFgetposTest : public LIBC_NAMESPACE::testing::ErrnoCheckingTest {
+protected:
+  void test_with_bufmode(int bufmode) {
+    constexpr char FILENAME[] = "testdata/fgetpos_bufmode.test";
+    auto FILEPATH = libc_make_test_file_path(FILENAME);
+
+    constexpr size_t BUFFER_SIZE = 1024;
+    char buffer[BUFFER_SIZE];
+
+    ::FILE *file = LIBC_NAMESPACE::fopen(FILEPATH, "w+");
+    ASSERT_FALSE(file == nullptr);
----------------
kaladron wrote:

ASSERT_NE(file, nullptr);

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


More information about the libc-commits mailing list