[libc-commits] [libc] [libc] Implement freopen (PR #207837)

Alexey Samsonov via libc-commits libc-commits at lists.llvm.org
Tue Aug 18 10:38:37 PDT 2026


================
@@ -0,0 +1,328 @@
+//===----------------------------------------------------------------------===//
+//
+// 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 freopen.
+///
+//===----------------------------------------------------------------------===//
+
+#include "src/fcntl/fcntl.h"
+#include "src/stdio/clearerr.h"
+#include "src/stdio/fclose.h"
+#include "src/stdio/feof.h"
+#include "src/stdio/ferror.h"
+#include "src/stdio/fflush.h"
+#include "src/stdio/fileno.h"
+#include "src/stdio/fopen.h"
+#include "src/stdio/fread.h"
+#include "src/stdio/freopen.h"
+#include "src/stdio/fwrite.h"
+#include "src/stdio/stdout.h"
+#include "src/unistd/close.h"
+#include "src/wchar/fwide.h"
+#include "test/UnitTest/ErrnoCheckingTest.h"
+#include "test/UnitTest/ErrnoSetterMatcher.h"
+#include "test/UnitTest/Test.h"
+
+#include "hdr/fcntl_macros.h"
+#include "hdr/stdio_macros.h"
+#include "src/__support/macros/properties/os.h"
+
+using LlvmLibcFreopenTest = LIBC_NAMESPACE::testing::ErrnoCheckingTest;
+using LIBC_NAMESPACE::testing::ErrnoSetterMatcher::Fails;
+using LIBC_NAMESPACE::testing::ErrnoSetterMatcher::Succeeds;
----------------
vonosmas wrote:

You don't actually use `Succeeds` below, but it would be a good idea, as it also verifies that errno is not set by the call. E.g. you can use patterns like:

`ASSERT_THAT(LIBC_NAMESPACE::fclose(file), Succeeds(0));`

where appropriate below.

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


More information about the libc-commits mailing list