xref: /llvm-project/libc/src/stdio/linux/fdopen.cpp (revision 5ff3ff33ff930e4ec49da7910612d8a41eb068cb)
10b24b470SXu Zhang //===-- Implementation of fdopen --------------------------------*- C++ -*-===//
20b24b470SXu Zhang //
30b24b470SXu Zhang // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
40b24b470SXu Zhang // See https://llvm.org/LICENSE.txt for license information.
50b24b470SXu Zhang // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
60b24b470SXu Zhang //
70b24b470SXu Zhang //===----------------------------------------------------------------------===//
80b24b470SXu Zhang 
90b24b470SXu Zhang #include "src/stdio/fdopen.h"
100b24b470SXu Zhang 
110b24b470SXu Zhang #include "src/__support/File/linux/file.h"
12*5ff3ff33SPetr Hosek #include "src/__support/macros/config.h"
130b24b470SXu Zhang #include "src/errno/libc_errno.h"
140b24b470SXu Zhang 
15*5ff3ff33SPetr Hosek namespace LIBC_NAMESPACE_DECL {
160b24b470SXu Zhang 
170b24b470SXu Zhang LLVM_LIBC_FUNCTION(::FILE *, fdopen, (int fd, const char *mode)) {
180b24b470SXu Zhang   auto result = LIBC_NAMESPACE::create_file_from_fd(fd, mode);
190b24b470SXu Zhang   if (!result.has_value()) {
200b24b470SXu Zhang     libc_errno = result.error();
210b24b470SXu Zhang     return nullptr;
220b24b470SXu Zhang   }
230b24b470SXu Zhang   return reinterpret_cast<::FILE *>(result.value());
240b24b470SXu Zhang }
250b24b470SXu Zhang 
26*5ff3ff33SPetr Hosek } // namespace LIBC_NAMESPACE_DECL
27