diff --git a/test/cat1.c b/test/cat1.c new file mode 100644 index 0000000..f133a7e --- /dev/null +++ b/test/cat1.c @@ -0,0 +1,39 @@ +#include +#include +#include +#include +#include +#include + +int main(int argc, const char **argv) +{ + if (argc < 2) { + return -1; + } + + const char *path_cstr = argv[1]; + b_path *path = b_path_create_from_cstr(path_cstr); + + b_file *src = NULL; + b_result result = b_file_open(NULL, path, B_FILE_READ_ONLY, &src); + if (b_result_is_error(result)) { + b_throw(result); + return -1; + } + + b_wchar c; + + size_t nr_read; + b_status status = b_stream_read_char(src, &c); + if (!B_OK(status)) { + printf("read error: %s\n", b_status_description(status)); + b_file_unref(src); + return -1; + } + + b_stream_write_char(b_stdout, c); + b_stream_write_char(b_stdout, '\n'); + + b_file_unref(src); + return 0; +}