|
10 | 10 | #include "hdr/types/FILE.h" |
11 | 11 | #include "src/__support/CPP/string_view.h" |
12 | 12 | #include "src/__support/OSUtil/io.h" |
| 13 | +#include "src/__support/libc_errno.h" |
13 | 14 | #include "src/__support/macros/config.h" |
14 | | -#include "src/stdio/printf_core/core_structs.h" // For printf_core::WRITE_OK |
| 15 | +#include "src/stdio/baremetal/write_hooks.h" |
15 | 16 |
|
16 | 17 | namespace LIBC_NAMESPACE_DECL { |
17 | 18 | namespace write_utils { |
18 | 19 |
|
19 | | -LIBC_INLINE int stdout_write_hook(cpp::string_view new_str, void *) { |
20 | | - write_to_stdout(new_str); |
21 | | - return printf_core::WRITE_OK; |
22 | | -} |
23 | | - |
24 | | -LIBC_INLINE int stderr_write_hook(cpp::string_view new_str, void *) { |
25 | | - write_to_stderr(new_str); |
26 | | - return printf_core::WRITE_OK; |
27 | | -} |
28 | | - |
29 | 20 | LIBC_INLINE void write(::FILE *f, cpp::string_view new_str) { |
30 | 21 | if (f == stdout) { |
31 | 22 | write_to_stdout(new_str); |
32 | | - } else { |
| 23 | + } else if (f == stderr) { |
33 | 24 | write_to_stderr(new_str); |
| 25 | + } else { |
| 26 | + libc_errno = 1; |
34 | 27 | } |
35 | 28 | } |
36 | 29 |
|
37 | 30 | using StreamWriter = int (*)(cpp::string_view, void *); |
38 | 31 | LIBC_INLINE StreamWriter get_write_hook(::FILE *f) { |
39 | | - if (f == stdout) |
| 32 | + if (f == stdout) { |
40 | 33 | return &stdout_write_hook; |
| 34 | + } else if (f == stderr) { |
| 35 | + return &stderr_write_hook; |
| 36 | + } |
41 | 37 |
|
42 | | - return &stderr_write_hook; |
| 38 | + libc_errno = 1; |
| 39 | + return NULL; |
43 | 40 | } |
44 | 41 |
|
45 | 42 | } // namespace write_utils |
|
0 commit comments