test: io: update i/o api usage re: b_error
This commit is contained in:
21
io-test/mkdir.c
Normal file
21
io-test/mkdir.c
Normal file
@@ -0,0 +1,21 @@
|
|||||||
|
#include <blue/io/directory.h>
|
||||||
|
|
||||||
|
int main(int argc, const char **argv)
|
||||||
|
{
|
||||||
|
if (argc < 2) {
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
const char *path = argv[1];
|
||||||
|
|
||||||
|
b_directory *dir;
|
||||||
|
b_result result = b_directory_open(
|
||||||
|
NULL, B_RV_PATH(path), B_DIRECTORY_OPEN_CREATE_INTERMEDIATE, &dir);
|
||||||
|
if (b_result_is_error(result)) {
|
||||||
|
b_throw(result);
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
b_directory_release(dir);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
@@ -7,18 +7,17 @@ int main(int argc, const char **argv)
|
|||||||
{
|
{
|
||||||
b_file *dest;
|
b_file *dest;
|
||||||
b_path *path = b_path_create_from_cstr("data.txt");
|
b_path *path = b_path_create_from_cstr("data.txt");
|
||||||
b_status status = b_file_open(
|
b_result result = b_file_open(
|
||||||
NULL, path, B_FILE_WRITE_ONLY | B_FILE_CREATE, &dest);
|
NULL, path, B_FILE_WRITE_ONLY | B_FILE_CREATE, &dest);
|
||||||
if (!B_OK(status)) {
|
if (b_result_is_error(result)) {
|
||||||
fprintf(stderr, "cannot open file (%s)\n",
|
b_throw(result);
|
||||||
b_status_to_string(status));
|
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
size_t nr_read = 0;
|
size_t nr_read = 0;
|
||||||
b_stream *dest_stream;
|
b_stream *dest_stream;
|
||||||
b_stream_pipeline *pipeline;
|
b_stream_pipeline *pipeline;
|
||||||
status = b_file_open_stream(dest, &dest_stream);
|
b_status status = b_file_open_stream(dest, &dest_stream);
|
||||||
b_stream_pipeline_create(1024, &pipeline);
|
b_stream_pipeline_create(1024, &pipeline);
|
||||||
b_stream_read_all_bytes_s(b_stdin, dest_stream, pipeline, &nr_read);
|
b_stream_read_all_bytes_s(b_stdin, dest_stream, pipeline, &nr_read);
|
||||||
|
|
||||||
|
|||||||
@@ -13,11 +13,10 @@ int main(int argc, const char **argv)
|
|||||||
|
|
||||||
b_directory *dir = NULL;
|
b_directory *dir = NULL;
|
||||||
b_path *path = b_path_create_from_cstr(argv[1]);
|
b_path *path = b_path_create_from_cstr(argv[1]);
|
||||||
b_status status = b_directory_open(B_DIRECTORY_ROOT, path, &dir);
|
b_result result = b_directory_open(B_DIRECTORY_ROOT, path, 0, &dir);
|
||||||
|
|
||||||
if (!B_OK(status)) {
|
if (b_result_is_error(result)) {
|
||||||
printf("cannot open %s\n", b_path_ptr(path));
|
b_throw(result);
|
||||||
printf("%s\n", b_status_to_string(status));
|
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user