| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,24 @@ | ||
| //===-- Implementation of clearerr ----------------------------------------===// | ||
| // | ||
| // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. | ||
| // See https://llvm.org/LICENSE.txt for license information. | ||
| // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception | ||
| // | ||
| //===----------------------------------------------------------------------===// | ||
|
|
||
| #include "src/stdio/clearerr.h" | ||
| #include "file.h" | ||
|
|
||
| #include <stdio.h> | ||
|
|
||
| namespace __llvm_libc { | ||
|
|
||
| LLVM_LIBC_FUNCTION(void, clearerr, (::FILE * stream)) { | ||
| rpc::Client::Port port = rpc::client.open<RPC_FERROR>(); | ||
| port.send_and_recv( | ||
| [=](rpc::Buffer *buffer) { buffer->data[0] = file::from_stream(stream); }, | ||
| [&](rpc::Buffer *) {}); | ||
| port.close(); | ||
| } | ||
|
|
||
| } // namespace __llvm_libc |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,26 @@ | ||
| //===-- Implementation of feof --------------------------------------------===// | ||
| // | ||
| // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. | ||
| // See https://llvm.org/LICENSE.txt for license information. | ||
| // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception | ||
| // | ||
| //===----------------------------------------------------------------------===// | ||
|
|
||
| #include "src/stdio/feof.h" | ||
| #include "file.h" | ||
|
|
||
| #include <stdio.h> | ||
|
|
||
| namespace __llvm_libc { | ||
|
|
||
| LLVM_LIBC_FUNCTION(int, feof, (::FILE * stream)) { | ||
| int ret; | ||
| rpc::Client::Port port = rpc::client.open<RPC_FEOF>(); | ||
| port.send_and_recv( | ||
| [=](rpc::Buffer *buffer) { buffer->data[0] = file::from_stream(stream); }, | ||
| [&](rpc::Buffer *buffer) { ret = static_cast<int>(buffer->data[0]); }); | ||
| port.close(); | ||
| return ret; | ||
| } | ||
|
|
||
| } // namespace __llvm_libc |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,26 @@ | ||
| //===-- Implementation of ferror ------------------------------------------===// | ||
| // | ||
| // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. | ||
| // See https://llvm.org/LICENSE.txt for license information. | ||
| // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception | ||
| // | ||
| //===----------------------------------------------------------------------===// | ||
|
|
||
| #include "src/stdio/ferror.h" | ||
| #include "file.h" | ||
|
|
||
| #include <stdio.h> | ||
|
|
||
| namespace __llvm_libc { | ||
|
|
||
| LLVM_LIBC_FUNCTION(int, ferror, (::FILE * stream)) { | ||
| int ret; | ||
| rpc::Client::Port port = rpc::client.open<RPC_FERROR>(); | ||
| port.send_and_recv( | ||
| [=](rpc::Buffer *buffer) { buffer->data[0] = file::from_stream(stream); }, | ||
| [&](rpc::Buffer *buffer) { ret = static_cast<int>(buffer->data[0]); }); | ||
| port.close(); | ||
| return ret; | ||
| } | ||
|
|
||
| } // namespace __llvm_libc |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,25 @@ | ||
| //===-- GPU implementation of fgetc ---------------------------------------===// | ||
| // | ||
| // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. | ||
| // See https://llvm.org/LICENSE.txt for license information. | ||
| // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception | ||
| // | ||
| //===----------------------------------------------------------------------===// | ||
|
|
||
| #include "src/stdio/fgetc.h" | ||
| #include "file.h" | ||
|
|
||
| #include <stdio.h> | ||
|
|
||
| namespace __llvm_libc { | ||
|
|
||
| LLVM_LIBC_FUNCTION(int, fgetc, (::FILE * stream)) { | ||
| unsigned char c; | ||
| size_t r = file::read(stream, &c, 1); | ||
|
|
||
| if (r != 1) | ||
| return EOF; | ||
| return c; | ||
| } | ||
|
|
||
| } // namespace __llvm_libc |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,46 @@ | ||
| //===-- GPU implementation of fgets ---------------------------------------===// | ||
| // | ||
| // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. | ||
| // See https://llvm.org/LICENSE.txt for license information. | ||
| // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception | ||
| // | ||
| //===----------------------------------------------------------------------===// | ||
|
|
||
| #include "src/stdio/fgets.h" | ||
| #include "file.h" | ||
| #include "src/stdio/feof.h" | ||
| #include "src/stdio/ferror.h" | ||
|
|
||
| #include <stddef.h> | ||
| #include <stdio.h> | ||
|
|
||
| namespace __llvm_libc { | ||
|
|
||
| LLVM_LIBC_FUNCTION(char *, fgets, | ||
| (char *__restrict str, int count, | ||
| ::FILE *__restrict stream)) { | ||
| if (count < 1) | ||
| return nullptr; | ||
|
|
||
| // This implementation is very slow as it makes multiple RPC calls. | ||
| unsigned char c = '\0'; | ||
| int i = 0; | ||
| for (; i < count - 1 && c != '\n'; ++i) { | ||
| auto r = file::read(stream, &c, 1); | ||
| if (r != 1) | ||
| break; | ||
|
|
||
| str[i] = c; | ||
| } | ||
|
|
||
| bool has_error = __llvm_libc::ferror(stream); | ||
| bool has_eof = __llvm_libc::feof(stream); | ||
|
|
||
| if (has_error || (i == 0 && has_eof)) | ||
| return nullptr; | ||
|
|
||
| str[i] = '\0'; | ||
| return str; | ||
| } | ||
|
|
||
| } // namespace __llvm_libc |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,25 @@ | ||
| //===-- GPU implementation of getc ----------------------------------------===// | ||
| // | ||
| // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. | ||
| // See https://llvm.org/LICENSE.txt for license information. | ||
| // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception | ||
| // | ||
| //===----------------------------------------------------------------------===// | ||
|
|
||
| #include "src/stdio/getc.h" | ||
| #include "file.h" | ||
|
|
||
| #include <stdio.h> | ||
|
|
||
| namespace __llvm_libc { | ||
|
|
||
| LLVM_LIBC_FUNCTION(int, getc, (::FILE * stream)) { | ||
| unsigned char c; | ||
| size_t r = file::read(stream, &c, 1); | ||
|
|
||
| if (r != 1) | ||
| return EOF; | ||
| return c; | ||
| } | ||
|
|
||
| } // namespace __llvm_libc |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,25 @@ | ||
| //===-- GPU implementation of getchar -------------------------------------===// | ||
| // | ||
| // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. | ||
| // See https://llvm.org/LICENSE.txt for license information. | ||
| // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception | ||
| // | ||
| //===----------------------------------------------------------------------===// | ||
|
|
||
| #include "src/stdio/getchar.h" | ||
| #include "file.h" | ||
|
|
||
| #include <stdio.h> | ||
|
|
||
| namespace __llvm_libc { | ||
|
|
||
| LLVM_LIBC_FUNCTION(int, getchar, ()) { | ||
| unsigned char c; | ||
| size_t r = file::read(stdin, &c, 1); | ||
|
|
||
| if (r != 1) | ||
| return EOF; | ||
| return c; | ||
| } | ||
|
|
||
| } // namespace __llvm_libc |