meta: rename to fx

This commit is contained in:
2026-03-16 10:35:43 +00:00
parent 84df46489a
commit e9d0e323f0
233 changed files with 12875 additions and 12869 deletions

View File

@@ -1,8 +1,8 @@
#include "posix.h"
#include <blue/ds/string.h>
#include <blue/io/file.h>
#include <blue/io/path.h>
#include <fx/ds/string.h>
#include <fx/io/file.h>
#include <fx/io/path.h>
#include <ctype.h>
#include <errno.h>
#include <fcntl.h>
@@ -13,142 +13,142 @@
/*** PRIVATE DATA *************************************************************/
struct b_path_p {
b_string *p_pathstr;
struct fx_path_p {
fx_string *p_pathstr;
};
/*** PRIVATE FUNCTIONS ********************************************************/
static b_path *path_make_absolute(const struct b_path_p *in)
static fx_path *path_make_absolute(const struct fx_path_p *in)
{
return NULL;
}
static b_path *path_make_relative(const struct b_path_p *in)
static fx_path *path_make_relative(const struct fx_path_p *in)
{
return NULL;
}
static b_path *path_make_canonical(const struct b_path_p *in)
static fx_path *path_make_canonical(const struct fx_path_p *in)
{
return NULL;
}
static bool path_is_absolute(const struct b_path_p *path)
static bool path_is_absolute(const struct fx_path_p *path)
{
const char *s = b_string_ptr(path->p_pathstr);
const char *s = fx_string_ptr(path->p_pathstr);
return s[0] == '/';
}
static const char *path_ptr(const struct b_path_p *path)
static const char *path_ptr(const struct fx_path_p *path)
{
return b_string_ptr(path->p_pathstr);
return fx_string_ptr(path->p_pathstr);
}
static enum b_status path_stat(const struct b_path_p *path, struct b_file_info *out)
static enum fx_status path_stat(const struct fx_path_p *path, struct fx_file_info *out)
{
struct stat st;
int err = stat(path_ptr(path), &st);
if (err != 0) {
return b_status_from_errno(errno, B_ERR_IO_FAILURE);
return fx_status_from_errno(errno, FX_ERR_IO_FAILURE);
}
memset(out, 0x0, sizeof *out);
return b_file_info_from_stat(&st, out);
return fx_file_info_from_stat(&st, out);
}
static bool path_exists(const struct b_path_p *path)
static bool path_exists(const struct fx_path_p *path)
{
b_file_info info;
if (!B_OK(path_stat(path, &info))) {
fx_file_info info;
if (!FX_OK(path_stat(path, &info))) {
return false;
}
return true;
}
static bool path_is_file(const struct b_path_p *path)
static bool path_is_file(const struct fx_path_p *path)
{
b_file_info info;
if (!B_OK(path_stat(path, &info))) {
fx_file_info info;
if (!FX_OK(path_stat(path, &info))) {
return false;
}
return (info.attrib & B_FILE_ATTRIB_NORMAL) != 0;
return (info.attrib & FX_FILE_ATTRIB_NORMAL) != 0;
}
static bool path_is_directory(const struct b_path_p *path)
static bool path_is_directory(const struct fx_path_p *path)
{
b_file_info info;
if (!B_OK(path_stat(path, &info))) {
fx_file_info info;
if (!FX_OK(path_stat(path, &info))) {
return false;
}
return (info.attrib & B_FILE_ATTRIB_DIRECTORY) != 0;
return (info.attrib & FX_FILE_ATTRIB_DIRECTORY) != 0;
}
static void append_path(struct b_path_p *dest, const struct b_path_p *src)
static void append_path(struct fx_path_p *dest, const struct fx_path_p *src)
{
if (path_is_absolute(src)) {
b_string_clear(dest->p_pathstr);
b_string_append_s(dest->p_pathstr, src->p_pathstr);
fx_string_clear(dest->p_pathstr);
fx_string_append_s(dest->p_pathstr, src->p_pathstr);
return;
}
if (b_string_get_size(dest->p_pathstr, B_STRLEN_NORMAL) > 0
&& b_string_back(dest->p_pathstr) != '/'
&& b_string_front(src->p_pathstr) != '/') {
if (fx_string_get_size(dest->p_pathstr, FX_STRLEN_NORMAL) > 0
&& fx_string_back(dest->p_pathstr) != '/'
&& fx_string_front(src->p_pathstr) != '/') {
char s[] = {'/', 0};
b_string_append_cstr(dest->p_pathstr, s);
fx_string_append_cstr(dest->p_pathstr, s);
}
b_string_append_s(dest->p_pathstr, src->p_pathstr);
fx_string_append_s(dest->p_pathstr, src->p_pathstr);
}
static enum b_status path_unlink(const struct b_path_p *path)
static enum fx_status path_unlink(const struct fx_path_p *path)
{
int err = remove(b_string_ptr(path->p_pathstr));
return err == 0 ? B_SUCCESS : b_status_from_errno(errno, B_ERR_IO_FAILURE);
int err = remove(fx_string_ptr(path->p_pathstr));
return err == 0 ? FX_SUCCESS : fx_status_from_errno(errno, FX_ERR_IO_FAILURE);
}
static enum b_status path_get_directory(
const struct b_path_p *path, b_path **out_dir_path)
static enum fx_status path_get_directory(
const struct fx_path_p *path, fx_path **out_dir_path)
{
b_string *path_str = path->p_pathstr;
long len = b_string_get_size(path_str, B_STRLEN_NORMAL);
fx_string *path_str = path->p_pathstr;
long len = fx_string_get_size(path_str, FX_STRLEN_NORMAL);
const char *path_cstr = b_string_ptr(path_str);
const char *path_cstr = fx_string_ptr(path_str);
char *sep = strrchr(path_cstr, '/');
if (!sep) {
*out_dir_path = b_path_create();
return B_SUCCESS;
*out_dir_path = fx_path_create();
return FX_SUCCESS;
}
size_t dir_path_len = (size_t)(sep - path_cstr);
b_string *dir_path_s = b_string_substr(path_str, 0, dir_path_len);
fx_string *dir_path_s = fx_string_substr(path_str, 0, dir_path_len);
b_path *dir_path = b_path_create_from_cstr(b_string_ptr(dir_path_s));
b_string_unref(dir_path_s);
fx_path *dir_path = fx_path_create_from_cstr(fx_string_ptr(dir_path_s));
fx_string_unref(dir_path_s);
*out_dir_path = dir_path;
return B_SUCCESS;
return FX_SUCCESS;
}
static enum b_status path_get_filename(
const struct b_path_p *path, b_string *out_name)
static enum fx_status path_get_filename(
const struct fx_path_p *path, fx_string *out_name)
{
b_string *path_str = path->p_pathstr;
long len = b_string_get_size(path_str, B_STRLEN_NORMAL);
fx_string *path_str = path->p_pathstr;
long len = fx_string_get_size(path_str, FX_STRLEN_NORMAL);
char *sep = strrchr(b_string_ptr(path_str), '/');
char *sep = strrchr(fx_string_ptr(path_str), '/');
if (!sep) {
b_string_append_s(out_name, path_str);
return B_SUCCESS;
fx_string_append_s(out_name, path_str);
return FX_SUCCESS;
}
const char *filename = sep;
@@ -157,43 +157,43 @@ static enum b_status path_get_filename(
}
if (*filename == '\0') {
b_string_clear(out_name);
return B_SUCCESS;
fx_string_clear(out_name);
return FX_SUCCESS;
}
b_string_append_cstr(out_name, filename);
fx_string_append_cstr(out_name, filename);
return B_SUCCESS;
return FX_SUCCESS;
}
static size_t path_length(const struct b_path_p *path)
static size_t path_length(const struct fx_path_p *path)
{
return b_string_get_size(path->p_pathstr, B_STRLEN_NORMAL);
return fx_string_get_size(path->p_pathstr, FX_STRLEN_NORMAL);
}
/*** PUBLIC FUNCTIONS *********************************************************/
b_path *b_path_create_root()
fx_path *fx_path_create_root()
{
const char *system_drive = "/";
size_t system_drive_len = strlen(system_drive);
b_path *path = b_path_create();
fx_path *path = fx_path_create();
if (!path) {
return NULL;
}
struct b_path_p *p = b_object_get_private(path, B_TYPE_PATH);
struct fx_path_p *p = fx_object_get_private(path, FX_TYPE_PATH);
b_string_append_cstr(p->p_pathstr, system_drive);
fx_string_append_cstr(p->p_pathstr, system_drive);
if (system_drive[system_drive_len - 1] != '\\') {
b_string_append_c(p->p_pathstr, '\\');
fx_string_append_c(p->p_pathstr, '\\');
}
return path;
}
b_path *b_path_create_cwd()
fx_path *fx_path_create_cwd()
{
const long buf_len = 2048;
char *buf = malloc(buf_len);
@@ -206,28 +206,28 @@ b_path *b_path_create_cwd()
return NULL;
}
b_path *path = b_path_create();
fx_path *path = fx_path_create();
if (!path) {
free(buf);
return NULL;
}
struct b_path_p *p = b_object_get_private(path, B_TYPE_PATH);
struct fx_path_p *p = fx_object_get_private(path, FX_TYPE_PATH);
b_string_append_cstr(p->p_pathstr, buf);
fx_string_append_cstr(p->p_pathstr, buf);
free(buf);
return path;
}
b_path *b_path_create_from_cstr(const char *cstr)
fx_path *fx_path_create_from_cstr(const char *cstr)
{
b_path *path = b_path_create();
fx_path *path = fx_path_create();
if (!path) {
return NULL;
}
struct b_path_p *p = b_object_get_private(path, B_TYPE_PATH);
struct fx_path_p *p = fx_object_get_private(path, FX_TYPE_PATH);
char prev = 0;
@@ -241,49 +241,49 @@ b_path *b_path_create_from_cstr(const char *cstr)
continue;
}
b_string_append_c(p->p_pathstr, c);
fx_string_append_c(p->p_pathstr, c);
prev = c;
}
while (b_string_back(p->p_pathstr) == '/') {
b_string_pop_back(p->p_pathstr);
while (fx_string_back(p->p_pathstr) == '/') {
fx_string_pop_back(p->p_pathstr);
}
return path;
}
b_path *b_path_duplicate(const b_path *path)
fx_path *fx_path_duplicate(const fx_path *path)
{
b_path *new_path = b_path_create();
fx_path *new_path = fx_path_create();
if (!path) {
return NULL;
}
struct b_path_p *old_p = b_object_get_private(path, B_TYPE_PATH);
struct b_path_p *new_p = b_object_get_private(new_path, B_TYPE_PATH);
struct fx_path_p *old_p = fx_object_get_private(path, FX_TYPE_PATH);
struct fx_path_p *new_p = fx_object_get_private(new_path, FX_TYPE_PATH);
new_p->p_pathstr = b_string_duplicate(old_p->p_pathstr);
new_p->p_pathstr = fx_string_duplicate(old_p->p_pathstr);
if (!new_p->p_pathstr) {
b_path_unref(new_path);
fx_path_unref(new_path);
return NULL;
}
return new_path;
}
b_path *b_path_join(const b_path *paths[], size_t nr_paths)
fx_path *fx_path_join(const fx_path *paths[], size_t nr_paths)
{
b_path *result = b_path_create();
fx_path *result = fx_path_create();
if (!result) {
return NULL;
}
struct b_path_p *result_p = b_object_get_private(result, B_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 b_path_p *path_p
= b_object_get_private(paths[i], B_TYPE_PATH);
struct fx_path_p *path_p
= fx_object_get_private(paths[i], FX_TYPE_PATH);
append_path(result_p, path_p);
}
}
@@ -291,109 +291,109 @@ b_path *b_path_join(const b_path *paths[], size_t nr_paths)
return result;
}
b_path *b_path_make_absolute(const b_path *in)
fx_path *fx_path_make_absolute(const fx_path *in)
{
B_CLASS_DISPATCH_STATIC_0(B_TYPE_PATH, path_make_absolute, in);
FX_CLASS_DISPATCH_STATIC_0(FX_TYPE_PATH, path_make_absolute, in);
}
b_path *b_path_make_relative(const b_path *in)
fx_path *fx_path_make_relative(const fx_path *in)
{
B_CLASS_DISPATCH_STATIC_0(B_TYPE_PATH, path_make_relative, in);
FX_CLASS_DISPATCH_STATIC_0(FX_TYPE_PATH, path_make_relative, in);
}
b_path *b_path_make_canonical(const b_path *in)
fx_path *fx_path_make_canonical(const fx_path *in)
{
B_CLASS_DISPATCH_STATIC_0(B_TYPE_PATH, path_make_canonical, in);
FX_CLASS_DISPATCH_STATIC_0(FX_TYPE_PATH, path_make_canonical, in);
}
bool b_path_is_absolute(const b_path *path)
bool fx_path_is_absolute(const fx_path *path)
{
B_CLASS_DISPATCH_STATIC_0(B_TYPE_PATH, path_is_absolute, path);
FX_CLASS_DISPATCH_STATIC_0(FX_TYPE_PATH, path_is_absolute, path);
}
bool b_path_exists(const b_path *path)
bool fx_path_exists(const fx_path *path)
{
B_CLASS_DISPATCH_STATIC_0(B_TYPE_PATH, path_exists, path);
FX_CLASS_DISPATCH_STATIC_0(FX_TYPE_PATH, path_exists, path);
}
bool b_path_is_file(const b_path *path)
bool fx_path_is_file(const fx_path *path)
{
B_CLASS_DISPATCH_STATIC_0(B_TYPE_PATH, path_is_file, path);
FX_CLASS_DISPATCH_STATIC_0(FX_TYPE_PATH, path_is_file, path);
}
bool b_path_is_directory(const b_path *path)
bool fx_path_is_directory(const fx_path *path)
{
B_CLASS_DISPATCH_STATIC_0(B_TYPE_PATH, path_is_directory, path);
FX_CLASS_DISPATCH_STATIC_0(FX_TYPE_PATH, path_is_directory, path);
}
enum b_status b_path_stat(const b_path *path, struct b_file_info *out)
enum fx_status fx_path_stat(const fx_path *path, struct fx_file_info *out)
{
B_CLASS_DISPATCH_STATIC(B_TYPE_PATH, path_stat, path, out);
FX_CLASS_DISPATCH_STATIC(FX_TYPE_PATH, path_stat, path, out);
}
enum b_status b_path_unlink(const b_path *path)
enum fx_status fx_path_unlink(const fx_path *path)
{
B_CLASS_DISPATCH_STATIC_0(B_TYPE_PATH, path_unlink, path);
FX_CLASS_DISPATCH_STATIC_0(FX_TYPE_PATH, path_unlink, path);
}
enum b_status b_path_get_directory(const b_path *path, b_path **out_dir_path)
enum fx_status fx_path_get_directory(const fx_path *path, fx_path **out_dir_path)
{
B_CLASS_DISPATCH_STATIC(B_TYPE_PATH, path_get_directory, path, out_dir_path);
FX_CLASS_DISPATCH_STATIC(FX_TYPE_PATH, path_get_directory, path, out_dir_path);
}
enum b_status b_path_get_filename(const b_path *path, b_string *out_name)
enum fx_status fx_path_get_filename(const fx_path *path, fx_string *out_name)
{
B_CLASS_DISPATCH_STATIC(B_TYPE_PATH, path_get_filename, path, out_name);
FX_CLASS_DISPATCH_STATIC(FX_TYPE_PATH, path_get_filename, path, out_name);
}
const char *b_path_ptr(const b_path *path)
const char *fx_path_ptr(const fx_path *path)
{
B_CLASS_DISPATCH_STATIC_0(B_TYPE_PATH, path_ptr, path);
FX_CLASS_DISPATCH_STATIC_0(FX_TYPE_PATH, path_ptr, path);
}
size_t b_path_length(const b_path *path)
size_t fx_path_length(const fx_path *path)
{
B_CLASS_DISPATCH_STATIC_0(B_TYPE_PATH, path_length, path);
FX_CLASS_DISPATCH_STATIC_0(FX_TYPE_PATH, path_length, path);
}
/*** VIRTUAL FUNCTIONS ********************************************************/
static void path_init(b_object *obj, void *priv)
static void path_init(fx_object *obj, void *priv)
{
struct b_path_p *path = priv;
struct fx_path_p *path = priv;
path->p_pathstr = b_string_create();
path->p_pathstr = fx_string_create();
if (!path->p_pathstr) {
/* TODO return error */
}
}
void path_fini(b_object *obj, void *priv)
void path_fini(fx_object *obj, void *priv)
{
struct b_path_p *path = priv;
struct fx_path_p *path = priv;
b_string_unref(path->p_pathstr);
fx_string_unref(path->p_pathstr);
}
void path_to_string(const b_object *obj, b_stream *out)
void path_to_string(const fx_object *obj, fx_stream *out)
{
struct b_path_p *path = b_object_get_private(obj, B_TYPE_PATH);
struct fx_path_p *path = fx_object_get_private(obj, FX_TYPE_PATH);
b_stream_write_string(out, b_string_ptr(path->p_pathstr), NULL);
fx_stream_write_string(out, fx_string_ptr(path->p_pathstr), NULL);
}
/*** CLASS DEFINITION *********************************************************/
B_TYPE_CLASS_DEFINITION_BEGIN(b_path)
B_TYPE_CLASS_INTERFACE_BEGIN(b_object, B_TYPE_OBJECT)
B_INTERFACE_ENTRY(to_string) = path_to_string;
B_TYPE_CLASS_INTERFACE_END(b_object, B_TYPE_OBJECT)
B_TYPE_CLASS_DEFINITION_END(b_path)
FX_TYPE_CLASS_DEFINITION_BEGIN(fx_path)
FX_TYPE_CLASS_INTERFACE_BEGIN(fx_object, FX_TYPE_OBJECT)
FX_INTERFACE_ENTRY(to_string) = path_to_string;
FX_TYPE_CLASS_INTERFACE_END(fx_object, FX_TYPE_OBJECT)
FX_TYPE_CLASS_DEFINITION_END(fx_path)
B_TYPE_DEFINITION_BEGIN(b_path)
B_TYPE_ID(0x56dc32eb, 0xea96, 0x46ed, 0x85d3, 0x760fa4ad61f4);
B_TYPE_CLASS(b_path_class);
B_TYPE_INSTANCE_PRIVATE(struct b_path_p);
B_TYPE_INSTANCE_INIT(path_init);
B_TYPE_INSTANCE_FINI(path_fini);
B_TYPE_DEFINITION_END(b_path)
FX_TYPE_DEFINITION_BEGIN(fx_path)
FX_TYPE_ID(0x56dc32eb, 0xea96, 0x46ed, 0x85d3, 0x760fa4ad61f4);
FX_TYPE_CLASS(fx_path_class);
FX_TYPE_INSTANCE_PRIVATE(struct fx_path_p);
FX_TYPE_INSTANCE_INIT(path_init);
FX_TYPE_INSTANCE_FINI(path_fini);
FX_TYPE_DEFINITION_END(fx_path)