Merge branch 'main' into feature/new-object-system

This commit is contained in:
2025-10-15 11:13:00 +01:00
227 changed files with 8252 additions and 2129 deletions

View File

@@ -274,6 +274,23 @@ static enum b_status stream_seek(
return b_file_cursor(file, &stream->s_cursor);
}
static enum b_status stream_tell(const struct b_stream *stream, size_t *pos)
{
const struct b_file *file = stream->s_ptr;
off_t v = lseek(file->fd, 0, SEEK_CUR);
if (v == (off_t)-1) {
return b_status_from_errno(errno, B_ERR_IO_FAILURE);
}
*pos = v;
return B_SUCCESS;
}
const struct b_path *b_file_path(const struct b_file *file)
{
return file->path;
}
enum b_status b_file_open_stream(struct b_file *file, struct b_stream **out)
{
struct b_stream *stream = malloc(sizeof *stream);
@@ -301,6 +318,7 @@ enum b_status b_file_open_stream(struct b_file *file, struct b_stream **out)
stream->s_read = stream_read;
stream->s_write = stream_write;
stream->s_seek = stream_seek;
stream->s_tell = stream_tell;
*out = stream;
@@ -382,11 +400,11 @@ enum b_status b_file_seek(
}
int err = lseek(file->fd, offset, whence);
if (err == 0) {
return B_SUCCESS;
if (err == (off_t)-1) {
return b_status_from_errno(errno, B_ERR_IO_FAILURE);
}
return b_status_from_errno(errno, B_ERR_IO_FAILURE);
return B_SUCCESS;
}
enum b_status b_file_swap_shadow(struct b_file *main_file, struct b_file *shadow_file)

View File

@@ -1,9 +1,9 @@
#include "posix.h"
#include <blue/core/stringstream.h>
#include <blue/ds/string.h>
#include <blue/io/file.h>
#include <blue/io/path.h>
#include <blue/ds/string.h>
#include <ctype.h>
#include <errno.h>
#include <fcntl.h>
@@ -18,7 +18,7 @@ struct b_path {
};
static void path_release(struct b_dsref *obj);
static void path_to_string(struct b_dsref *obj, struct b_stream *out);
static void path_to_string(const struct b_dsref *obj, struct b_stream *out);
static struct b_dsref_type path_type = {
.t_name = "corelib::path",
@@ -58,7 +58,7 @@ struct b_path *b_path_create_root()
b_string_append_cstr(path->pathstr, system_drive);
if (system_drive[system_drive_len - 1] != '\\') {
b_string_append_cstr(path->pathstr, "\\");
b_string_append_c(path->pathstr, '\\');
}
return path;
@@ -108,8 +108,7 @@ struct b_path *b_path_create_from_cstr(const char *cstr)
continue;
}
char s[] = {c, 0};
b_string_append_cstr(path->pathstr, s);
b_string_append_c(path->pathstr, c);
prev = c;
}
@@ -312,7 +311,7 @@ void path_release(struct b_dsref *obj)
b_string_release(path->pathstr);
}
void path_to_string(struct b_dsref *obj, struct b_stream *out)
void path_to_string(const struct b_dsref *obj, struct b_stream *out)
{
struct b_path *path = (struct b_path *)obj;