Fix errno behavior of sceKernelFsync

This commit is contained in:
Stephen Miller 2025-02-17 21:11:59 -06:00
parent 74b513ddcd
commit 1858214d51

View file

@ -764,26 +764,31 @@ s64 PS4_SYSV_ABI sceKernelPread(s32 fd, void* buf, size_t nbytes, s64 offset) {
return sceKernelPreadv(fd, &iovec, 1, offset); return sceKernelPreadv(fd, &iovec, 1, offset);
} }
s32 PS4_SYSV_ABI sceKernelFsync(int fd) { s32 PS4_SYSV_ABI posix_fsync(s32 fd) {
auto* h = Common::Singleton<Core::FileSys::HandleTable>::Instance(); auto* h = Common::Singleton<Core::FileSys::HandleTable>::Instance();
auto* file = h->GetFile(fd); auto* file = h->GetFile(fd);
if (file == nullptr) { if (file == nullptr) {
return ORBIS_KERNEL_ERROR_EBADF; *__Error() = POSIX_EBADF;
return -1;
} }
if (file->type == Core::FileSys::FileType::Device) { if (file->type == Core::FileSys::FileType::Device) {
return file->device->fsync(); s32 result = file->device->fsync();
if (result < 0) {
ErrSceToPosix(result);
return -1;
}
return result;
} }
file->f.Flush(); file->f.Flush();
return ORBIS_OK; return ORBIS_OK;
} }
s32 PS4_SYSV_ABI posix_fsync(int fd) { s32 PS4_SYSV_ABI sceKernelFsync(s32 fd) {
s32 result = sceKernelFsync(fd); s32 result = posix_fsync(fd);
if (result < 0) { if (result < 0) {
LOG_ERROR(Kernel_Pthread, "posix_fsync: error = {}", result); LOG_ERROR(Kernel_Fs, "error = {}", *__Error());
ErrSceToPosix(result); return ErrnoToSceKernelError(*__Error());
return -1;
} }
return result; return result;
} }