fx.io: expand path joining functionality to non-path strings
This commit is contained in:
+35
-29
@@ -53,12 +53,12 @@ static const fx_path *directory_get_rel_path(const struct fx_directory_p *dir)
|
||||
|
||||
static const char *directory_get_path_cstr(const struct fx_directory_p *dir)
|
||||
{
|
||||
return fx_path_ptr(dir->d_path_abs);
|
||||
return fx_path_get_cstr(dir->d_path_abs);
|
||||
}
|
||||
|
||||
static const char *directory_get_rel_path_cstr(const struct fx_directory_p *dir)
|
||||
{
|
||||
return fx_path_ptr(dir->d_path_rel);
|
||||
return fx_path_get_cstr(dir->d_path_rel);
|
||||
}
|
||||
|
||||
static fx_result directory_delete(
|
||||
@@ -90,12 +90,13 @@ static bool directory_path_exists(
|
||||
const struct fx_directory_p *root,
|
||||
const fx_path *path)
|
||||
{
|
||||
const fx_path *parts[] = {
|
||||
root ? root->d_path_abs : NULL,
|
||||
path,
|
||||
const fx_value *parts[] = {
|
||||
&FX_VALUE_OBJECT(root ? root->d_path_abs : NULL),
|
||||
&FX_VALUE_OBJECT(path),
|
||||
};
|
||||
|
||||
fx_path *abs_path = fx_path_join(parts, sizeof parts / sizeof parts[0]);
|
||||
fx_path *abs_path
|
||||
= fx_path_join_array(parts, sizeof parts / sizeof parts[0]);
|
||||
if (!abs_path) {
|
||||
return false;
|
||||
}
|
||||
@@ -110,12 +111,13 @@ static bool directory_path_is_file(
|
||||
const struct fx_directory_p *root,
|
||||
const fx_path *path)
|
||||
{
|
||||
const fx_path *parts[] = {
|
||||
root ? root->d_path_abs : NULL,
|
||||
path,
|
||||
const fx_value *parts[] = {
|
||||
&FX_VALUE_OBJECT(root ? root->d_path_abs : NULL),
|
||||
&FX_VALUE_OBJECT(path),
|
||||
};
|
||||
|
||||
fx_path *abs_path = fx_path_join(parts, sizeof parts / sizeof parts[0]);
|
||||
fx_path *abs_path
|
||||
= fx_path_join_array(parts, sizeof parts / sizeof parts[0]);
|
||||
if (!abs_path) {
|
||||
return false;
|
||||
}
|
||||
@@ -130,12 +132,13 @@ static bool directory_path_is_directory(
|
||||
const struct fx_directory_p *root,
|
||||
const fx_path *path)
|
||||
{
|
||||
const fx_path *parts[] = {
|
||||
root ? root->d_path_abs : NULL,
|
||||
path,
|
||||
const fx_value *parts[] = {
|
||||
&FX_VALUE_OBJECT(root ? root->d_path_abs : NULL),
|
||||
&FX_VALUE_OBJECT(path),
|
||||
};
|
||||
|
||||
fx_path *abs_path = fx_path_join(parts, sizeof parts / sizeof parts[0]);
|
||||
fx_path *abs_path
|
||||
= fx_path_join_array(parts, sizeof parts / sizeof parts[0]);
|
||||
if (!abs_path) {
|
||||
return false;
|
||||
}
|
||||
@@ -151,12 +154,13 @@ static fx_result directory_path_stat(
|
||||
const fx_path *path,
|
||||
struct fx_file_info *out)
|
||||
{
|
||||
const fx_path *parts[] = {
|
||||
root ? root->d_path_abs : NULL,
|
||||
path,
|
||||
const fx_value *parts[] = {
|
||||
&FX_VALUE_OBJECT(root ? root->d_path_abs : NULL),
|
||||
&FX_VALUE_OBJECT(path),
|
||||
};
|
||||
|
||||
fx_path *abs_path = fx_path_join(parts, sizeof parts / sizeof parts[0]);
|
||||
fx_path *abs_path
|
||||
= fx_path_join_array(parts, sizeof parts / sizeof parts[0]);
|
||||
if (!abs_path) {
|
||||
return FX_RESULT_ERR(NO_MEMORY);
|
||||
}
|
||||
@@ -171,12 +175,13 @@ static fx_result directory_path_unlink(
|
||||
const struct fx_directory_p *root,
|
||||
const fx_path *path)
|
||||
{
|
||||
const fx_path *parts[] = {
|
||||
root ? root->d_path_abs : NULL,
|
||||
path,
|
||||
const fx_value *parts[] = {
|
||||
&FX_VALUE_OBJECT(root ? root->d_path_abs : NULL),
|
||||
&FX_VALUE_OBJECT(path),
|
||||
};
|
||||
|
||||
fx_path *abs_path = fx_path_join(parts, sizeof parts / sizeof parts[0]);
|
||||
fx_path *abs_path
|
||||
= fx_path_join_array(parts, sizeof parts / sizeof parts[0]);
|
||||
if (!abs_path) {
|
||||
return FX_RESULT_ERR(NO_MEMORY);
|
||||
}
|
||||
@@ -264,7 +269,7 @@ static fx_result directory_open(
|
||||
|
||||
int root_fd = root ? root->d_fd : AT_FDCWD;
|
||||
|
||||
const char *path_cstr = fx_path_ptr(path);
|
||||
const char *path_cstr = fx_path_get_cstr(path);
|
||||
if (root) {
|
||||
while (*path_cstr == '/') {
|
||||
path_cstr++;
|
||||
@@ -298,15 +303,16 @@ static fx_result directory_open(
|
||||
= fx_object_get_private(dir, FX_TYPE_DIRECTORY);
|
||||
|
||||
if (!root) {
|
||||
cwd = fx_path_create_cwd();
|
||||
cwd = fx_path_get_system(FX_PATH_CWD);
|
||||
}
|
||||
|
||||
const fx_path *parts[] = {
|
||||
root ? root->d_path_abs : cwd,
|
||||
path,
|
||||
const fx_value *parts[] = {
|
||||
&FX_VALUE_OBJECT(root ? root->d_path_abs : cwd),
|
||||
&FX_VALUE_OBJECT(path),
|
||||
};
|
||||
|
||||
fx_path *new_path = fx_path_join(parts, sizeof parts / sizeof parts[0]);
|
||||
fx_path *new_path
|
||||
= fx_path_join_array(parts, sizeof parts / sizeof parts[0]);
|
||||
if (!new_path) {
|
||||
return FX_RESULT_ERR(NO_MEMORY);
|
||||
}
|
||||
@@ -570,7 +576,7 @@ fx_iterator *fx_directory_begin(
|
||||
int fts_flags = FTS_COMFOLLOW | FTS_NOCHDIR;
|
||||
|
||||
const char *path_list[] = {
|
||||
fx_path_ptr(it->_p->d_path_abs),
|
||||
fx_path_get_cstr(it->_p->d_path_abs),
|
||||
NULL,
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user