mirror of
https://github.com/wheremyfoodat/Panda3DS.git
synced 2025-04-07 06:35:40 +12:00
commit
6dc75db37f
2 changed files with 29 additions and 0 deletions
|
@ -148,6 +148,11 @@ void Kernel::writeFile(u32 messagePointer, Handle fileHandle) {
|
||||||
IOFile f(file->fd);
|
IOFile f(file->fd);
|
||||||
auto [success, bytesWritten] = f.writeBytes(data.get(), size);
|
auto [success, bytesWritten] = f.writeBytes(data.get(), size);
|
||||||
|
|
||||||
|
// TODO: Should this check only the byte?
|
||||||
|
if (writeOption) {
|
||||||
|
f.flush();
|
||||||
|
}
|
||||||
|
|
||||||
mem.write32(messagePointer, IPC::responseHeader(0x0803, 2, 2));
|
mem.write32(messagePointer, IPC::responseHeader(0x0803, 2, 2));
|
||||||
if (!success) {
|
if (!success) {
|
||||||
Helpers::panic("Kernel::WriteFile failed");
|
Helpers::panic("Kernel::WriteFile failed");
|
||||||
|
|
|
@ -179,6 +179,30 @@ u32 Kernel::getTLSPointer() {
|
||||||
// Result CloseHandle(Handle handle)
|
// Result CloseHandle(Handle handle)
|
||||||
void Kernel::svcCloseHandle() {
|
void Kernel::svcCloseHandle() {
|
||||||
logSVC("CloseHandle(handle = %d) (Unimplemented)\n", regs[0]);
|
logSVC("CloseHandle(handle = %d) (Unimplemented)\n", regs[0]);
|
||||||
|
const Handle handle = regs[0];
|
||||||
|
|
||||||
|
KernelObject* object = getObject(handle);
|
||||||
|
if (object != nullptr) {
|
||||||
|
switch (object->type) {
|
||||||
|
// Close file descriptor when closing a file to prevent leaks and properly flush file contents
|
||||||
|
case KernelObjectType::File: {
|
||||||
|
FileSession* file = object->getData<FileSession>();
|
||||||
|
if (file->isOpen) {
|
||||||
|
file->isOpen = false;
|
||||||
|
|
||||||
|
if (file->fd != nullptr) {
|
||||||
|
fclose(file->fd);
|
||||||
|
file->fd = nullptr;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
default: break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Stub to always succeed for now
|
||||||
regs[0] = Result::Success;
|
regs[0] = Result::Success;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue