test: add a test that reads one utf8 codepoint from a file
This commit is contained in:
39
test/cat1.c
Normal file
39
test/cat1.c
Normal file
@@ -0,0 +1,39 @@
|
|||||||
|
#include <blue/core/stream.h>
|
||||||
|
#include <blue/core/stringstream.h>
|
||||||
|
#include <blue/ds/string.h>
|
||||||
|
#include <blue/io/file.h>
|
||||||
|
#include <blue/io/path.h>
|
||||||
|
#include <stdio.h>
|
||||||
|
|
||||||
|
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;
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user