fx.io: convert to assembly build system

This commit is contained in:
2026-05-03 14:51:11 +01:00
parent 55ba15b1fa
commit cefb548824
18 changed files with 657 additions and 258 deletions
+100 -29
View File
@@ -3,13 +3,13 @@
#include "misc.h"
#include "posix.h"
#include <fx/core/random.h>
#include <fx/ds/string.h>
#include <errno.h>
#include <fcntl.h>
#include <fx/io/directory.h>
#include <fx/io/file.h>
#include <fx/io/path.h>
#include <errno.h>
#include <fcntl.h>
#include <fx/random.h>
#include <fx/string.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
@@ -22,7 +22,10 @@ static enum fx_status stream_close(fx_stream *);
static enum fx_status stream_getc(fx_stream *, int *);
static enum fx_status stream_read(fx_stream *, void *, size_t, size_t *);
static enum fx_status stream_write(fx_stream *, const void *, size_t, size_t *);
static enum fx_status stream_seek(fx_stream *, long long, fx_stream_seek_origin);
static enum fx_status stream_seek(
fx_stream *,
long long,
fx_stream_seek_origin);
static enum fx_status stream_tell(const fx_stream *, size_t *);
/*** PRIVATE DATA *************************************************************/
@@ -65,7 +68,9 @@ static unsigned int fx_mode_to_unix_mode(enum fx_file_mode mode)
}
static fx_result file_open_shadow(
struct fx_file_p *original, enum fx_file_mode mode, fx_file **out)
struct fx_file_p *original,
enum fx_file_mode mode,
fx_file **out)
{
mode |= FX_FILE_SHADOW | FX_FILE_DELETE_ON_CLOSE | FX_FILE_CREATE;
@@ -77,7 +82,8 @@ static fx_result file_open_shadow(
fx_string_prepend_cstr(filename, ".~");
fx_path *shadow_filename = fx_path_create_from_cstr(fx_string_get_cstr(filename));
fx_path *shadow_filename
= fx_path_create_from_cstr(fx_string_get_cstr(filename));
fx_string_unref(filename);
const fx_path *parts[] = {
@@ -96,7 +102,10 @@ static fx_result file_open_shadow(
fx_file *shadow_file;
fx_result status = fx_file_open(
FX_DIRECTORY_ROOT, shadow_filepath, mode, &shadow_file);
FX_DIRECTORY_ROOT,
shadow_filepath,
mode,
&shadow_file);
fx_path_unref(shadow_filepath);
if (fx_result_is_error(status)) {
@@ -112,7 +121,9 @@ static const fx_path *file_path(const struct fx_file_p *file)
return file->path;
}
static enum fx_status file_stat(struct fx_file_p *file, struct fx_file_info *out)
static enum fx_status file_stat(
struct fx_file_p *file,
struct fx_file_info *out)
{
struct stat st;
int err = fstat(file->fd, &st);
@@ -169,7 +180,9 @@ static enum fx_status file_resize(struct fx_file_p *file, size_t len)
}
static enum fx_status file_seek(
struct fx_file_p *file, long long offset, enum fx_seek_basis basis)
struct fx_file_p *file,
long long offset,
enum fx_seek_basis basis)
{
int whence;
switch (basis) {
@@ -195,7 +208,8 @@ static enum fx_status file_seek(
}
static enum fx_status file_swap_shadow(
struct fx_file_p *main_file, struct fx_file_p *shadow_file)
struct fx_file_p *main_file,
struct fx_file_p *shadow_file)
{
if (main_file->mode & FX_FILE_SHADOW) {
return FX_ERR_NOT_SUPPORTED;
@@ -237,7 +251,9 @@ 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(shadow_file->path),
fx_path_ptr(main_file->path));
err = rename(fx_path_ptr(tmp_path), fx_path_ptr(shadow_file->path));
fx_path_unref(tmp_path);
@@ -250,7 +266,11 @@ static enum fx_status file_swap_shadow(
}
static enum fx_status file_read(
struct fx_file_p *file, size_t offset, size_t len, void *buf, size_t *nr_read)
struct fx_file_p *file,
size_t offset,
size_t len,
void *buf,
size_t *nr_read)
{
if (offset != FX_OFFSET_CURRENT) {
lseek(file->fd, offset, SEEK_SET);
@@ -269,7 +289,10 @@ static enum fx_status file_read(
}
static enum fx_status file_write(
struct fx_file_p *file, size_t offset, size_t len, const void *buf,
struct fx_file_p *file,
size_t offset,
size_t len,
const void *buf,
size_t *nr_written)
{
if (offset != FX_OFFSET_CURRENT) {
@@ -316,7 +339,10 @@ static enum fx_status stream_getc(fx_stream *stream, int *out)
}
static enum fx_status stream_read(
fx_stream *stream, void *buf, size_t max, size_t *nr_read)
fx_stream *stream,
void *buf,
size_t max,
size_t *nr_read)
{
struct fx_file_p *file = fx_object_get_private(stream, FX_TYPE_FILE);
@@ -327,7 +353,10 @@ static enum fx_status stream_read(
}
static enum fx_status stream_write(
fx_stream *stream, const void *buf, size_t count, size_t *nr_written)
fx_stream *stream,
const void *buf,
size_t count,
size_t *nr_written)
{
struct fx_file_p *file = fx_object_get_private(stream, FX_TYPE_FILE);
@@ -338,7 +367,9 @@ static enum fx_status stream_write(
}
static enum fx_status stream_seek(
fx_stream *stream, long long offset, fx_stream_seek_origin origin)
fx_stream *stream,
long long offset,
fx_stream_seek_origin origin)
{
fx_seek_basis basis;
switch (origin) {
@@ -362,7 +393,8 @@ static enum fx_status stream_seek(
static enum fx_status stream_tell(const fx_stream *stream, size_t *pos)
{
const struct fx_file_p *file = fx_object_get_private(stream, FX_TYPE_FILE);
const struct fx_file_p *file
= fx_object_get_private(stream, FX_TYPE_FILE);
off_t v = lseek(file->fd, 0, SEEK_CUR);
if (v == (off_t)-1) {
return fx_status_from_errno(errno, FX_ERR_IO_FAILURE);
@@ -375,7 +407,10 @@ static enum fx_status stream_tell(const fx_stream *stream, size_t *pos)
/*** PUBLIC FUNCTIONS *********************************************************/
fx_result fx_file_open(
fx_directory *root, const fx_path *path, enum fx_file_mode mode, fx_file **out)
fx_directory *root,
const fx_path *path,
enum fx_file_mode mode,
fx_file **out)
{
const fx_path *file_path = path;
unsigned int flags = fx_mode_to_unix_mode(mode);
@@ -458,7 +493,10 @@ fx_result fx_file_open_temp(enum fx_file_mode mode, fx_file **out)
fx_path *rpath = fx_path_create_from_cstr(path);
fx_result status = fx_file_open(
FX_DIRECTORY_ROOT, rpath, mode | FX_FILE_CREATE_ONLY, out);
FX_DIRECTORY_ROOT,
rpath,
mode | FX_FILE_CREATE_ONLY,
out);
if (fx_error_get_status_code(status) == FX_ERR_NAME_EXISTS) {
fx_path_unref(rpath);
@@ -472,9 +510,17 @@ fx_result fx_file_open_temp(enum fx_file_mode mode, fx_file **out)
}
}
fx_result fx_file_open_shadow(fx_file *original, enum fx_file_mode mode, fx_file **out)
fx_result fx_file_open_shadow(
fx_file *original,
enum fx_file_mode mode,
fx_file **out)
{
FX_CLASS_DISPATCH_STATIC(FX_TYPE_FILE, file_open_shadow, original, mode, out);
FX_CLASS_DISPATCH_STATIC(
FX_TYPE_FILE,
file_open_shadow,
original,
mode,
out);
}
const fx_path *fx_file_path(const fx_file *file)
@@ -502,30 +548,55 @@ enum fx_status fx_file_resize(fx_file *file, size_t len)
FX_CLASS_DISPATCH_STATIC(FX_TYPE_FILE, file_resize, file, len);
}
enum fx_status fx_file_seek(fx_file *file, long long offset, enum fx_seek_basis basis)
enum fx_status fx_file_seek(
fx_file *file,
long long offset,
enum fx_seek_basis basis)
{
FX_CLASS_DISPATCH_STATIC(FX_TYPE_FILE, file_seek, file, offset, basis);
}
enum fx_status fx_file_swap_shadow(fx_file *main_file, fx_file *shadow_file)
{
struct fx_file_p *main_p = fx_object_get_private(main_file, FX_TYPE_FILE);
struct fx_file_p *shadow_p = fx_object_get_private(main_file, FX_TYPE_FILE);
struct fx_file_p *main_p
= fx_object_get_private(main_file, FX_TYPE_FILE);
struct fx_file_p *shadow_p
= fx_object_get_private(main_file, FX_TYPE_FILE);
return file_swap_shadow(main_p, shadow_p);
}
enum fx_status fx_file_read(
fx_file *file, size_t offset, size_t len, void *buf, size_t *nr_read)
fx_file *file,
size_t offset,
size_t len,
void *buf,
size_t *nr_read)
{
FX_CLASS_DISPATCH_STATIC(
FX_TYPE_FILE, file_read, file, offset, len, buf, nr_read);
FX_TYPE_FILE,
file_read,
file,
offset,
len,
buf,
nr_read);
}
enum fx_status fx_file_write(
fx_file *file, size_t offset, size_t len, const void *buf, size_t *nr_written)
fx_file *file,
size_t offset,
size_t len,
const void *buf,
size_t *nr_written)
{
FX_CLASS_DISPATCH_STATIC(
FX_TYPE_FILE, file_write, file, offset, len, buf, nr_written);
FX_TYPE_FILE,
file_write,
file,
offset,
len,
buf,
nr_written);
}
/*** VIRTUAL FUNCTIONS ********************************************************/