fx.io: convert to assembly build system
This commit is contained in:
+104
-36
@@ -1,12 +1,12 @@
|
||||
#include "misc.h"
|
||||
#include "posix.h"
|
||||
|
||||
#include <fx/core/error.h>
|
||||
#include <fx/ds/string.h>
|
||||
#include <fx/io/directory.h>
|
||||
#include <errno.h>
|
||||
#include <fcntl.h>
|
||||
#include <fts.h>
|
||||
#include <fx/error.h>
|
||||
#include <fx/io/directory.h>
|
||||
#include <fx/string.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <sys/stat.h>
|
||||
@@ -58,11 +58,14 @@ static const char *directory_get_rel_path_cstr(const struct fx_directory_p *dir)
|
||||
return fx_path_ptr(dir->d_path_rel);
|
||||
}
|
||||
|
||||
static fx_result directory_delete(fx_directory *dir, struct fx_directory_p *dir_p)
|
||||
static fx_result directory_delete(
|
||||
fx_directory *dir,
|
||||
struct fx_directory_p *dir_p)
|
||||
{
|
||||
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);
|
||||
}
|
||||
@@ -81,7 +84,8 @@ static fx_result directory_delete(fx_directory *dir, struct fx_directory_p *dir_
|
||||
}
|
||||
|
||||
static bool directory_path_exists(
|
||||
const struct fx_directory_p *root, const fx_path *path)
|
||||
const struct fx_directory_p *root,
|
||||
const fx_path *path)
|
||||
{
|
||||
const fx_path *parts[] = {
|
||||
root ? root->d_path_abs : NULL,
|
||||
@@ -100,7 +104,8 @@ static bool directory_path_exists(
|
||||
}
|
||||
|
||||
static bool directory_path_is_file(
|
||||
const struct fx_directory_p *root, const fx_path *path)
|
||||
const struct fx_directory_p *root,
|
||||
const fx_path *path)
|
||||
{
|
||||
const fx_path *parts[] = {
|
||||
root ? root->d_path_abs : NULL,
|
||||
@@ -119,7 +124,8 @@ static bool directory_path_is_file(
|
||||
}
|
||||
|
||||
static bool directory_path_is_directory(
|
||||
const struct fx_directory_p *root, const fx_path *path)
|
||||
const struct fx_directory_p *root,
|
||||
const fx_path *path)
|
||||
{
|
||||
const fx_path *parts[] = {
|
||||
root ? root->d_path_abs : NULL,
|
||||
@@ -138,7 +144,8 @@ static bool directory_path_is_directory(
|
||||
}
|
||||
|
||||
static fx_result directory_path_stat(
|
||||
const struct fx_directory_p *root, const fx_path *path,
|
||||
const struct fx_directory_p *root,
|
||||
const fx_path *path,
|
||||
struct fx_file_info *out)
|
||||
{
|
||||
const fx_path *parts[] = {
|
||||
@@ -158,7 +165,8 @@ static fx_result directory_path_stat(
|
||||
}
|
||||
|
||||
static fx_result directory_path_unlink(
|
||||
const struct fx_directory_p *root, const fx_path *path)
|
||||
const struct fx_directory_p *root,
|
||||
const fx_path *path)
|
||||
{
|
||||
const fx_path *parts[] = {
|
||||
root ? root->d_path_abs : NULL,
|
||||
@@ -192,11 +200,15 @@ static fx_result create_directory(struct fx_directory_p *root, const char *path)
|
||||
}
|
||||
|
||||
return fx_result_from_errno_with_subfilepath(
|
||||
errno, path, directory_get_rel_path_cstr(root), FX_ERR_IO_FAILURE);
|
||||
errno,
|
||||
path,
|
||||
directory_get_rel_path_cstr(root),
|
||||
FX_ERR_IO_FAILURE);
|
||||
}
|
||||
|
||||
static fx_result create_directory_hierarchy(
|
||||
struct fx_directory_p *root, const char *path)
|
||||
struct fx_directory_p *root,
|
||||
const char *path)
|
||||
{
|
||||
int root_fd = root ? root->d_fd : AT_FDCWD;
|
||||
|
||||
@@ -216,7 +228,9 @@ static fx_result create_directory_hierarchy(
|
||||
int err = mkdirat(root_fd, path_buf, 0755);
|
||||
if (err != 0 && errno != EEXIST) {
|
||||
result = fx_result_from_errno_with_subfilepath(
|
||||
errno, path_buf, directory_get_rel_path_cstr(root),
|
||||
errno,
|
||||
path_buf,
|
||||
directory_get_rel_path_cstr(root),
|
||||
FX_ERR_IO_FAILURE);
|
||||
break;
|
||||
}
|
||||
@@ -227,7 +241,9 @@ static fx_result create_directory_hierarchy(
|
||||
int err = mkdirat(root_fd, path_buf, 0755);
|
||||
if (err != 0 && errno != EEXIST) {
|
||||
result = fx_result_from_errno_with_subfilepath(
|
||||
errno, path_buf, directory_get_rel_path_cstr(root),
|
||||
errno,
|
||||
path_buf,
|
||||
directory_get_rel_path_cstr(root),
|
||||
FX_ERR_IO_FAILURE);
|
||||
}
|
||||
|
||||
@@ -236,8 +252,10 @@ static fx_result create_directory_hierarchy(
|
||||
}
|
||||
|
||||
static fx_result directory_open(
|
||||
struct fx_directory_p *root, const fx_path *path,
|
||||
fx_directory_open_flags flags, fx_directory **out)
|
||||
struct fx_directory_p *root,
|
||||
const fx_path *path,
|
||||
fx_directory_open_flags flags,
|
||||
fx_directory **out)
|
||||
{
|
||||
enum fx_status status = FX_SUCCESS;
|
||||
|
||||
@@ -254,7 +272,9 @@ static fx_result directory_open(
|
||||
if ((flags & FX_DIRECTORY_OPEN_CREATE_INTERMEDIATE)
|
||||
== FX_DIRECTORY_OPEN_CREATE_INTERMEDIATE) {
|
||||
result = create_directory_hierarchy(root, path_cstr);
|
||||
} else if ((flags & FX_DIRECTORY_OPEN_CREATE) == FX_DIRECTORY_OPEN_CREATE) {
|
||||
} else if (
|
||||
(flags & FX_DIRECTORY_OPEN_CREATE)
|
||||
== FX_DIRECTORY_OPEN_CREATE) {
|
||||
result = create_directory(root, path_cstr);
|
||||
}
|
||||
|
||||
@@ -271,7 +291,8 @@ 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();
|
||||
@@ -307,11 +328,18 @@ static fx_result directory_open(
|
||||
/*** PUBLIC FUNCTIONS *********************************************************/
|
||||
|
||||
fx_result fx_directory_open(
|
||||
fx_directory *root, const fx_path *path, fx_directory_open_flags flags,
|
||||
fx_directory *root,
|
||||
const fx_path *path,
|
||||
fx_directory_open_flags flags,
|
||||
fx_directory **out)
|
||||
{
|
||||
FX_CLASS_DISPATCH_STATIC(
|
||||
FX_TYPE_DIRECTORY, directory_open, root, path, flags, out);
|
||||
FX_TYPE_DIRECTORY,
|
||||
directory_open,
|
||||
root,
|
||||
path,
|
||||
flags,
|
||||
out);
|
||||
}
|
||||
|
||||
fx_result fx_directory_open_temp(fx_directory **out)
|
||||
@@ -326,7 +354,10 @@ fx_result fx_directory_open_temp(fx_directory **out)
|
||||
|
||||
fx_directory *dir = NULL;
|
||||
fx_result status = fx_directory_open(
|
||||
FX_DIRECTORY_ROOT, rpath, FX_DIRECTORY_OPEN_CREATE, &dir);
|
||||
FX_DIRECTORY_ROOT,
|
||||
rpath,
|
||||
FX_DIRECTORY_OPEN_CREATE,
|
||||
&dir);
|
||||
struct fx_directory_p *p
|
||||
= fx_object_get_private(dir, FX_TYPE_DIRECTORY);
|
||||
|
||||
@@ -353,23 +384,32 @@ const fx_path *fx_directory_get_path(const fx_directory *dir)
|
||||
|
||||
const fx_path *fx_directory_get_rel_path(const fx_directory *dir)
|
||||
{
|
||||
FX_CLASS_DISPATCH_STATIC_0(FX_TYPE_DIRECTORY, directory_get_rel_path, dir);
|
||||
FX_CLASS_DISPATCH_STATIC_0(
|
||||
FX_TYPE_DIRECTORY,
|
||||
directory_get_rel_path,
|
||||
dir);
|
||||
}
|
||||
|
||||
const char *fx_directory_get_path_cstr(const fx_directory *dir)
|
||||
{
|
||||
FX_CLASS_DISPATCH_STATIC_0(FX_TYPE_DIRECTORY, directory_get_path_cstr, dir);
|
||||
FX_CLASS_DISPATCH_STATIC_0(
|
||||
FX_TYPE_DIRECTORY,
|
||||
directory_get_path_cstr,
|
||||
dir);
|
||||
}
|
||||
|
||||
const char *fx_directory_get_rel_path_cstr(const fx_directory *dir)
|
||||
{
|
||||
FX_CLASS_DISPATCH_STATIC_0(
|
||||
FX_TYPE_DIRECTORY, directory_get_rel_path_cstr, dir);
|
||||
FX_TYPE_DIRECTORY,
|
||||
directory_get_rel_path_cstr,
|
||||
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);
|
||||
@@ -378,31 +418,55 @@ fx_result fx_directory_delete(fx_directory *dir)
|
||||
|
||||
bool fx_directory_path_exists(const fx_directory *root, const fx_path *path)
|
||||
{
|
||||
FX_CLASS_DISPATCH_STATIC(FX_TYPE_DIRECTORY, directory_path_exists, root, path);
|
||||
FX_CLASS_DISPATCH_STATIC(
|
||||
FX_TYPE_DIRECTORY,
|
||||
directory_path_exists,
|
||||
root,
|
||||
path);
|
||||
}
|
||||
|
||||
bool fx_directory_path_is_file(const fx_directory *root, const fx_path *path)
|
||||
{
|
||||
FX_CLASS_DISPATCH_STATIC(
|
||||
FX_TYPE_DIRECTORY, directory_path_is_file, root, path);
|
||||
FX_TYPE_DIRECTORY,
|
||||
directory_path_is_file,
|
||||
root,
|
||||
path);
|
||||
}
|
||||
|
||||
bool fx_directory_path_is_directory(const fx_directory *root, const fx_path *path)
|
||||
bool fx_directory_path_is_directory(
|
||||
const fx_directory *root,
|
||||
const fx_path *path)
|
||||
{
|
||||
FX_CLASS_DISPATCH_STATIC(
|
||||
FX_TYPE_DIRECTORY, directory_path_is_directory, root, path);
|
||||
FX_TYPE_DIRECTORY,
|
||||
directory_path_is_directory,
|
||||
root,
|
||||
path);
|
||||
}
|
||||
|
||||
fx_result fx_directory_path_stat(
|
||||
const fx_directory *root, const fx_path *path, struct fx_file_info *out)
|
||||
const fx_directory *root,
|
||||
const fx_path *path,
|
||||
struct fx_file_info *out)
|
||||
{
|
||||
FX_CLASS_DISPATCH_STATIC(
|
||||
FX_TYPE_DIRECTORY, directory_path_stat, root, path, out);
|
||||
FX_TYPE_DIRECTORY,
|
||||
directory_path_stat,
|
||||
root,
|
||||
path,
|
||||
out);
|
||||
}
|
||||
|
||||
fx_result fx_directory_path_unlink(const fx_directory *root, const fx_path *path)
|
||||
fx_result fx_directory_path_unlink(
|
||||
const fx_directory *root,
|
||||
const fx_path *path)
|
||||
{
|
||||
FX_CLASS_DISPATCH_STATIC(FX_TYPE_DIRECTORY, directory_path_unlink, root, path);
|
||||
FX_CLASS_DISPATCH_STATIC(
|
||||
FX_TYPE_DIRECTORY,
|
||||
directory_path_unlink,
|
||||
root,
|
||||
path);
|
||||
}
|
||||
|
||||
/*** VIRTUAL FUNCTIONS ********************************************************/
|
||||
@@ -487,7 +551,8 @@ static void iterator_fini(fx_object *obj, void *priv)
|
||||
}
|
||||
|
||||
fx_iterator *fx_directory_begin(
|
||||
fx_directory *directory, enum fx_directory_iterator_flags flags)
|
||||
fx_directory *directory,
|
||||
enum fx_directory_iterator_flags flags)
|
||||
{
|
||||
fx_iterator *it_obj = fx_object_create(FX_TYPE_DIRECTORY_ITERATOR);
|
||||
struct fx_directory_iterator_p *it
|
||||
@@ -556,7 +621,9 @@ static fx_iterator *iterator_begin(fx_object *obj)
|
||||
|
||||
static const fx_iterator *iterator_cbegin(const fx_object *obj)
|
||||
{
|
||||
return fx_directory_begin((fx_object *)obj, FX_DIRECTORY_ITERATE_PARENT_FIRST);
|
||||
return fx_directory_begin(
|
||||
(fx_object *)obj,
|
||||
FX_DIRECTORY_ITERATE_PARENT_FIRST);
|
||||
}
|
||||
|
||||
static enum fx_status iterator_move_next(const fx_iterator *obj)
|
||||
@@ -612,7 +679,8 @@ 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);
|
||||
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);
|
||||
|
||||
Reference in New Issue
Block a user