fx.io: expand path joining functionality to non-path strings

This commit is contained in:
2026-06-20 15:25:16 +01:00
parent 32d4d0abf2
commit ee11ff240f
10 changed files with 239 additions and 151 deletions
+25 -18
View File
@@ -86,13 +86,13 @@ static fx_result file_open_shadow(
= fx_path_create_from_cstr(fx_string_get_cstr(filename));
fx_string_unref(filename);
const fx_path *parts[] = {
dir,
shadow_filename,
const fx_value *parts[] = {
&FX_VALUE_OBJECT(dir),
&FX_VALUE_OBJECT(shadow_filename),
};
fx_path *shadow_filepath
= fx_path_join(parts, sizeof parts / sizeof parts[0]);
= fx_path_join_array(parts, sizeof parts / sizeof parts[0]);
fx_path_unref(dir);
fx_path_unref(shadow_filename);
@@ -229,12 +229,14 @@ static enum fx_status file_swap_shadow(
z__fx_io_generate_tmp_filename(tmp_name, sizeof tmp_name);
fx_path *tmp_name_p = fx_path_create_from_cstr(tmp_name);
const fx_path *parts[] = {
dir_path,
tmp_name_p,
const fx_value *parts[] = {
&FX_VALUE_OBJECT(dir_path),
&FX_VALUE_OBJECT(tmp_name_p),
};
tmp_path = fx_path_join(parts, sizeof parts / sizeof parts[0]);
tmp_path = fx_path_join_array(
parts,
sizeof parts / sizeof parts[0]);
fx_path_unref(tmp_name_p);
@@ -250,11 +252,15 @@ static enum fx_status file_swap_shadow(
int err;
err = rename(fx_path_ptr(main_file->path), fx_path_ptr(tmp_path));
err = rename(
fx_path_ptr(shadow_file->path),
fx_path_ptr(main_file->path));
err = rename(fx_path_ptr(tmp_path), fx_path_ptr(shadow_file->path));
fx_path_get_cstr(main_file->path),
fx_path_get_cstr(tmp_path));
err = rename(
fx_path_get_cstr(shadow_file->path),
fx_path_get_cstr(main_file->path));
err = rename(
fx_path_get_cstr(tmp_path),
fx_path_get_cstr(shadow_file->path));
fx_path_unref(tmp_path);
@@ -424,16 +430,17 @@ fx_result fx_file_open(
if (root) {
root_path = fx_directory_get_path(root);
} else {
root_path = fx_path_create_cwd();
root_path = fx_path_get_system(FX_PATH_CWD);
free_root_path = true;
}
const fx_path *parts[] = {
root_path,
file_path,
const fx_value *parts[] = {
&FX_VALUE_OBJECT(root_path),
&FX_VALUE_OBJECT(file_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 (free_root_path) {
fx_path_unref((fx_path *)root_path);
@@ -443,7 +450,7 @@ fx_result fx_file_open(
return FX_RESULT_ERR(NO_MEMORY);
}
int fd = open(fx_path_ptr(abs_path), flags, 0644);
int fd = open(fx_path_get_cstr(abs_path), flags, 0644);
if (fd == -1) {
fx_path_unref(abs_path);
return FX_RESULT_STATUS(