brintos

brintos / llvm-project-archived public Read only

0
0
Text · 1.2 KiB · e1c6088 Raw
43 lines · cpp
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-exception6//7//===----------------------------------------------------------------------===//8 9#include "src/stdio/fgets.h"10 11#include "file.h"12#include "hdr/stdint_proxy.h"13#include "hdr/stdio_macros.h" // for EOF.14#include "hdr/types/FILE.h"15#include "src/__support/common.h"16 17namespace LIBC_NAMESPACE_DECL {18 19LLVM_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<LIBC_READ_FGETS>();28  port.send([=](rpc::Buffer *buffer, uint32_t) {29    buffer->data[0] = count;30    buffer->data[1] = file::from_stream(stream);31  });32  port.recv_n(&buf, &recv_size,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_DECL43