fx.io: update interface implementations
This commit is contained in:
+29
-29
@@ -64,8 +64,9 @@ static fx_result directory_delete(
|
||||
{
|
||||
enum fx_status status = FX_SUCCESS;
|
||||
|
||||
fx_iterator *it
|
||||
= fx_directory_begin(dir, FX_DIRECTORY_ITERATE_PARENT_LAST);
|
||||
fx_iterator *it = fx_directory_begin(
|
||||
dir,
|
||||
FX_DIRECTORY_ITERATE_PARENT_LAST);
|
||||
while (FX_OK(fx_iterator_get_status(it))) {
|
||||
fx_iterator_erase(it);
|
||||
}
|
||||
@@ -291,8 +292,9 @@ static fx_result directory_open(
|
||||
|
||||
fx_directory *dir = fx_object_create(FX_TYPE_DIRECTORY);
|
||||
fx_path *cwd = NULL;
|
||||
struct fx_directory_p *p
|
||||
= fx_object_get_private(dir, FX_TYPE_DIRECTORY);
|
||||
struct fx_directory_p *p = fx_object_get_private(
|
||||
dir,
|
||||
FX_TYPE_DIRECTORY);
|
||||
|
||||
if (!root) {
|
||||
cwd = fx_path_create_cwd();
|
||||
@@ -358,8 +360,9 @@ fx_result fx_directory_open_temp(fx_directory **out)
|
||||
rpath,
|
||||
FX_DIRECTORY_OPEN_CREATE,
|
||||
&dir);
|
||||
struct fx_directory_p *p
|
||||
= fx_object_get_private(dir, FX_TYPE_DIRECTORY);
|
||||
struct fx_directory_p *p = fx_object_get_private(
|
||||
dir,
|
||||
FX_TYPE_DIRECTORY);
|
||||
|
||||
if (fx_error_get_status_code(status) == FX_ERR_NAME_EXISTS) {
|
||||
fx_path_unref(rpath);
|
||||
@@ -408,8 +411,9 @@ const char *fx_directory_get_rel_path_cstr(const fx_directory *dir)
|
||||
|
||||
fx_result fx_directory_delete(fx_directory *dir)
|
||||
{
|
||||
struct fx_directory_p *p
|
||||
= fx_object_get_private(dir, FX_TYPE_DIRECTORY);
|
||||
struct fx_directory_p *p = fx_object_get_private(
|
||||
dir,
|
||||
FX_TYPE_DIRECTORY);
|
||||
p->d_flags |= DIRECTORY_DELETE_ON_CLOSE;
|
||||
/* TODO allow object release functions to return a fx_result value */
|
||||
fx_directory_unref(dir);
|
||||
@@ -555,8 +559,9 @@ fx_iterator *fx_directory_begin(
|
||||
enum fx_directory_iterator_flags flags)
|
||||
{
|
||||
fx_iterator *it_obj = fx_object_create(FX_TYPE_DIRECTORY_ITERATOR);
|
||||
struct fx_directory_iterator_p *it
|
||||
= fx_object_get_private(it_obj, FX_TYPE_DIRECTORY_ITERATOR);
|
||||
struct fx_directory_iterator_p *it = fx_object_get_private(
|
||||
it_obj,
|
||||
FX_TYPE_DIRECTORY_ITERATOR);
|
||||
|
||||
it->flags = flags;
|
||||
it->root = directory;
|
||||
@@ -628,8 +633,9 @@ static const fx_iterator *iterator_cbegin(const fx_object *obj)
|
||||
|
||||
static enum fx_status iterator_move_next(const fx_iterator *obj)
|
||||
{
|
||||
struct fx_directory_iterator_p *it
|
||||
= fx_object_get_private(obj, FX_TYPE_DIRECTORY_ITERATOR);
|
||||
struct fx_directory_iterator_p *it = fx_object_get_private(
|
||||
obj,
|
||||
FX_TYPE_DIRECTORY_ITERATOR);
|
||||
if (!it || !it->fts) {
|
||||
return FX_ERR_NO_DATA;
|
||||
}
|
||||
@@ -677,10 +683,12 @@ static enum fx_status iterator_move_next(const fx_iterator *obj)
|
||||
|
||||
static enum fx_status iterator_erase(fx_iterator *obj)
|
||||
{
|
||||
struct fx_directory_iterator_p *it
|
||||
= fx_object_get_private(obj, FX_TYPE_DIRECTORY_ITERATOR);
|
||||
fx_result result
|
||||
= fx_directory_path_unlink(it->root, it->entry.filepath);
|
||||
struct fx_directory_iterator_p *it = fx_object_get_private(
|
||||
obj,
|
||||
FX_TYPE_DIRECTORY_ITERATOR);
|
||||
fx_result result = fx_directory_path_unlink(
|
||||
it->root,
|
||||
it->entry.filepath);
|
||||
if (fx_result_is_error(result)) {
|
||||
enum fx_status status = fx_error_get_status_code(result);
|
||||
fx_error_discard(result);
|
||||
@@ -690,20 +698,13 @@ static enum fx_status iterator_erase(fx_iterator *obj)
|
||||
return iterator_move_next(obj);
|
||||
}
|
||||
|
||||
static fx_iterator_value iterator_get_value(fx_iterator *obj)
|
||||
static fx_value iterator_get_value(const fx_iterator *obj)
|
||||
{
|
||||
struct fx_directory_iterator_p *it
|
||||
= fx_object_get_private(obj, FX_TYPE_DIRECTORY_ITERATOR);
|
||||
struct fx_directory_iterator_p *it = fx_object_get_private(
|
||||
obj,
|
||||
FX_TYPE_DIRECTORY_ITERATOR);
|
||||
|
||||
return FX_ITERATOR_VALUE_PTR(&it->entry);
|
||||
}
|
||||
|
||||
static const fx_iterator_value iterator_get_cvalue(const fx_iterator *obj)
|
||||
{
|
||||
struct fx_directory_iterator_p *it
|
||||
= fx_object_get_private(obj, FX_TYPE_DIRECTORY_ITERATOR);
|
||||
|
||||
return FX_ITERATOR_VALUE_CPTR(&it->entry);
|
||||
return FX_POINTER(&it->entry);
|
||||
}
|
||||
|
||||
/*** CLASS DEFINITION *********************************************************/
|
||||
@@ -739,7 +740,6 @@ FX_TYPE_CLASS_BEGIN(fx_directory_iterator)
|
||||
FX_INTERFACE_ENTRY(it_move_next) = iterator_move_next;
|
||||
FX_INTERFACE_ENTRY(it_erase) = iterator_erase;
|
||||
FX_INTERFACE_ENTRY(it_get_value) = iterator_get_value;
|
||||
FX_INTERFACE_ENTRY(it_get_cvalue) = iterator_get_cvalue;
|
||||
FX_TYPE_VTABLE_INTERFACE_END(fx_iterator, FX_TYPE_ITERATOR)
|
||||
FX_TYPE_CLASS_END(fx_directory_iterator)
|
||||
|
||||
|
||||
+18
-9
@@ -6,6 +6,7 @@
|
||||
#include <fx/io/file.h>
|
||||
#include <fx/io/path.h>
|
||||
#include <fx/string.h>
|
||||
#include <fx/value.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <sys/stat.h>
|
||||
@@ -134,8 +135,8 @@ static enum fx_status path_get_directory(
|
||||
size_t dir_path_len = (size_t)(sep - path_cstr);
|
||||
fx_string *dir_path_s = fx_string_get_substr(path_str, 0, dir_path_len);
|
||||
|
||||
fx_path *dir_path
|
||||
= fx_path_create_from_cstr(fx_string_get_cstr(dir_path_s));
|
||||
fx_path *dir_path = fx_path_create_from_cstr(
|
||||
fx_string_get_cstr(dir_path_s));
|
||||
fx_string_unref(dir_path_s);
|
||||
|
||||
*out_dir_path = dir_path;
|
||||
@@ -284,13 +285,15 @@ fx_path *fx_path_join(const fx_path *paths[], size_t nr_paths)
|
||||
return NULL;
|
||||
}
|
||||
|
||||
struct fx_path_p *result_p
|
||||
= fx_object_get_private(result, FX_TYPE_PATH);
|
||||
struct fx_path_p *result_p = fx_object_get_private(
|
||||
result,
|
||||
FX_TYPE_PATH);
|
||||
|
||||
for (size_t i = 0; i < nr_paths; i++) {
|
||||
if (paths[i]) {
|
||||
struct fx_path_p *path_p
|
||||
= fx_object_get_private(paths[i], FX_TYPE_PATH);
|
||||
struct fx_path_p *path_p = fx_object_get_private(
|
||||
paths[i],
|
||||
FX_TYPE_PATH);
|
||||
append_path(result_p, path_p);
|
||||
}
|
||||
}
|
||||
@@ -385,18 +388,24 @@ static void path_init(fx_object *obj, void *priv)
|
||||
}
|
||||
}
|
||||
|
||||
void path_fini(fx_object *obj, void *priv)
|
||||
static void path_fini(fx_object *obj, void *priv)
|
||||
{
|
||||
struct fx_path_p *path = priv;
|
||||
|
||||
fx_string_unref(path->p_pathstr);
|
||||
}
|
||||
|
||||
void path_to_string(const fx_object *obj, fx_stream *out)
|
||||
static fx_status path_to_string(
|
||||
const fx_value *obj,
|
||||
fx_stream *out,
|
||||
const char *format)
|
||||
{
|
||||
struct fx_path_p *path = fx_object_get_private(obj, FX_TYPE_PATH);
|
||||
struct fx_path_p *path = fx_object_get_private(
|
||||
obj->v_object,
|
||||
FX_TYPE_PATH);
|
||||
|
||||
fx_stream_write_cstr(out, fx_string_get_cstr(path->p_pathstr), NULL);
|
||||
return FX_SUCCESS;
|
||||
}
|
||||
|
||||
/*** CLASS DEFINITION *********************************************************/
|
||||
|
||||
Reference in New Issue
Block a user