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/stdio/gpu/file.h" |
12 | |
13 | #include <stdio.h> |
14 | |
15 | namespace LIBC_NAMESPACE { |
16 | |
17 | LLVM_LIBC_FUNCTION(::FILE *, fopen, |
18 | (const char *__restrict path, const char *__restrict mode)) { |
19 | uintptr_t file; |
20 | rpc::Client::Port port = rpc::client.open<RPC_OPEN_FILE>(); |
21 | port.send_n(src: path, size: internal::string_length(src: path) + 1); |
22 | port.send_and_recv( |
23 | fill: [=](rpc::Buffer *buffer) { |
24 | inline_memcpy(dst: buffer->data, src: mode, count: internal::string_length(src: mode) + 1); |
25 | }, |
26 | use: [&](rpc::Buffer *buffer) { file = buffer->data[0]; }); |
27 | port.close(); |
28 | |
29 | return reinterpret_cast<FILE *>(file); |
30 | } |
31 | |
32 | } // namespace LIBC_NAMESPACE |
33 |