xref: /llvm-project/libc/src/stdio/gpu/fopen.cpp (revision a6ef0debb1d60966b5bcc69f7d58a2b75c9c621d)
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<LIBC_OPEN_FILE>();
22   port.send_n(path, internal::string_length(path) + 1);
23   port.send_and_recv(
24       [=](rpc::Buffer *buffer, uint32_t) {
25         inline_memcpy(buffer->data, mode, internal::string_length(mode) + 1);
26       },
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