Skip to content

Commit

Permalink
Fixed and improve FS and File class system call implementations.
Browse files Browse the repository at this point in the history
  • Loading branch information
nthnn committed Apr 14, 2024
1 parent 9baf03e commit 3e09503
Showing 1 changed file with 15 additions and 3 deletions.
18 changes: 15 additions & 3 deletions src/rishka_syscalls.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -467,7 +467,20 @@ uint8_t RishkaSyscall::FS::open(RishkaVM* vm) {
auto path = vm->getPointerParam<char*>(0);
auto mode = vm->getPointerParam<char*>(1);

vm->fileHandles.add(SD.open(path, mode));
if(strcmp(mode, "n") == 0)
vm->fileHandles.add(SD.open(path));
else vm->fileHandles.add(SD.open(path, mode));

File next = vm->fileHandles[vm->fileHandles.getSize() - 1];
while(true) {
vm->getTerminal()->println(next.name());

next = next.openNextFile();
if(!next)
break;
}
while(true);

return vm->fileHandles.getSize() - 1;
}

Expand Down Expand Up @@ -552,9 +565,8 @@ bool RishkaSyscall::FS::isOk(RishkaVM* vm) {

uint8_t RishkaSyscall::FS::next(RishkaVM* vm) {
auto handle = vm->getParam<uint8_t>(0);
auto mode = vm->getPointerParam<char*>(1);

File file = vm->fileHandles[handle].openNextFile(mode);
File file = vm->fileHandles[handle].openNextFile();
vm->fileHandles.add(file);

return vm->fileHandles.getSize();
Expand Down

0 comments on commit 3e09503

Please sign in to comment.