1 //===-- GPU implementation of fgets ---------------------------------------===//
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
7 //===----------------------------------------------------------------------===//
9 #include "src/stdio/fgets.h"
11 #include "src/__support/macros/config.h"
12 #include "src/stdio/feof.h"
13 #include "src/stdio/ferror.h"
15 #include "hdr/stdio_macros.h" // for EOF.
16 #include "hdr/types/FILE.h"
19 namespace LIBC_NAMESPACE_DECL
{
21 LLVM_LIBC_FUNCTION(char *, fgets
,
22 (char *__restrict str
, int count
,
23 ::FILE *__restrict stream
)) {
29 rpc::Client::Port port
= rpc::client
.open
<RPC_READ_FGETS
>();
30 port
.send([=](rpc::Buffer
*buffer
, uint32_t) {
31 buffer
->data
[0] = count
;
32 buffer
->data
[1] = file::from_stream(stream
);
34 port
.recv_n(&buf
, &recv_size
,
35 [&](uint64_t) { return reinterpret_cast<void *>(str
); });
44 } // namespace LIBC_NAMESPACE_DECL