xref: /aosp_15_r20/external/llvm-libc/src/stdio/gpu/fopen.cpp (revision 71db0c75aadcf003ffe3238005f61d7618a3fead)
1 //===-- GPU Implementation of fopen ---------------------------------------===//
2 //
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6 //
7 //===----------------------------------------------------------------------===//
8 
9 #include "src/stdio/fopen.h"
10 #include "src/__support/CPP/string_view.h"
11 #include "src/__support/macros/config.h"
12 #include "src/stdio/gpu/file.h"
13 
14 #include "hdr/types/FILE.h"
15 
16 namespace LIBC_NAMESPACE_DECL {
17 
18 LLVM_LIBC_FUNCTION(::FILE *, fopen,
19                    (const char *__restrict path, const char *__restrict mode)) {
20   uintptr_t file;
21   rpc::Client::Port port = rpc::client.open<RPC_OPEN_FILE>();
22   port.send_n(path, internal::string_length(path) + 1);
23   port.send_and_recv(
__anon02a56c250102(rpc::Buffer *buffer, uint32_t) 24       [=](rpc::Buffer *buffer, uint32_t) {
25         inline_memcpy(buffer->data, mode, internal::string_length(mode) + 1);
26       },
__anon02a56c250202(rpc::Buffer *buffer, uint32_t) 27       [&](rpc::Buffer *buffer, uint32_t) { file = buffer->data[0]; });
28   port.close();
29 
30   return reinterpret_cast<FILE *>(file);
31 }
32 
33 } // namespace LIBC_NAMESPACE_DECL
34