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
@@ -1,13 +1,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>
@@ -20,7 +20,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 *************************************************************/
@@ -63,7 +66,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;
@@ -75,7 +80,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[] = {
@@ -94,7 +100,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)) {
@@ -110,7 +119,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);
@@ -167,7 +178,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) {
@@ -193,7 +206,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;
@@ -235,7 +249,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);
@@ -248,7 +264,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);
@@ -267,7 +287,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) {
@@ -314,7 +337,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);
@@ -325,7 +351,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);
@@ -336,7 +365,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) {
@@ -360,7 +391,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);
@@ -373,7 +405,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);
@@ -456,7 +491,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);
@@ -470,9 +508,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)
@@ -500,30 +546,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 ********************************************************/