1 //===-- GPU implementation of fgets ---------------------------------------===// 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/fgets.h" 10 #include "file.h" 11 #include "src/stdio/feof.h" 12 #include "src/stdio/ferror.h" 13 14 #include <stddef.h> 15 #include <stdio.h> 16 17 namespace LIBC_NAMESPACE { 18 19 LLVM_LIBC_FUNCTION(char *, fgets, 20 (char *__restrict str, int count, 21 ::FILE *__restrict stream)) { 22 if (count < 1) 23 return nullptr; 24 25 uint64_t recv_size; 26 void *buf = nullptr; 27 rpc::Client::Port port = rpc::client.open<RPC_READ_FGETS>(); __anon0e2273a40102(rpc::Buffer *buffer) 28 port.send([=](rpc::Buffer *buffer) { 29 buffer->data[0] = count; 30 buffer->data[1] = file::from_stream(stream); 31 }); 32 port.recv_n(&buf, &recv_size, __anon0e2273a40202(uint64_t) 33 [&](uint64_t) { return reinterpret_cast<void *>(str); }); 34 port.close(); 35 36 if (recv_size == 0) 37 return nullptr; 38 39 return str; 40 } 41 42 } // namespace LIBC_NAMESPACE 43