Compare commits
1 Commits
24d245c09b
...
3633516f62
Author | SHA1 | Date | |
---|---|---|---|
|
3633516f62 |
@@ -538,6 +538,20 @@ pub fn writeFile(pathname: [*:0]const u8, offset: u64, buffer: []u8) !u32 {
|
||||
};
|
||||
}
|
||||
|
||||
pub fn fileGetSize(pathname: [*:0]const u8) !u64 {
|
||||
var ret: [10]u32 = undefined;
|
||||
const info: FileInfo = .{
|
||||
.subfn = 5,
|
||||
.offset = 0,
|
||||
.size = 0,
|
||||
.buffer = @intFromPtr(&ret),
|
||||
.pathptr = @ptrCast(pathname),
|
||||
};
|
||||
if (syscall1(SYS.file, @intFromPtr(&info)) != 0)
|
||||
return error.Unexpected;
|
||||
return ret[8] | (@as(u64, ret[9]) << 32);
|
||||
}
|
||||
|
||||
pub fn deleteFile(pathname: [*:0]const u8) !void {
|
||||
const info: FileInfo = .{
|
||||
.subfn = 8,
|
||||
|
@@ -98,7 +98,8 @@ const emu = struct {
|
||||
const buffer = getFilePortSlice(dev, ports.write);
|
||||
var ret: u32 = 0;
|
||||
if (append) {
|
||||
ret = kos.writeFile(pathname, file_offsets[idx], buffer) catch |err| blk: {
|
||||
const offset: u32 = @intCast(kos.fileGetSize(pathname) catch 0);
|
||||
ret = kos.writeFile(pathname, offset, buffer) catch |err| blk: {
|
||||
if (err == error.FileNotFound) {
|
||||
break :blk kos.createFile(pathname, buffer) catch 0;
|
||||
} else {
|
||||
|
Reference in New Issue
Block a user