Closed glebm closed 2 years ago
I think stormlib requires ftruncate
and the project uses ::truncate
I believe ftruncate can be implemented through a combination of SceIoGetStat and SceIoChStat.
This issue should really be on the newlib repo though.
I implemented it for Rust and forgot :sweat_smile:
pub fn truncate(&self, size: u64) -> io::Result<()> {
let mut stat: libc::SceIoStat = unsafe { core::mem::zeroed() };
stat.st_size = size as i64;
let result = unsafe { libc::sceIoChstat(self.path.as_c_str().as_ptr() as *const u8, &mut stat, 0x0004) };
if result < 0 {
return Err(cvt_io_error(result));
} else {
Ok(())
}
}
https://github.com/overdrivenpotato/rust/blob/psp_std_saj/library/std/src/sys/psp/fs.rs#L283
In C, that's roughly
int truncate(char* path, size_t size) {
SceIoStat stat;
stat.st_size = size;
int result = sceIoChstat(path, &stat, 0x0004);
return result;
}
@sajattack just fyi @glebm isn't the guy who wouldn't build with SDL1 :D
He was just using glebm's repo as a base.
@sajattack While you're at it could you please also do ftruncate
? I see there is sceIoChstatByFd
I see there is sceIoChstatByFd
I believe that's a vita function, not sure if psp has it.
I guess we can stub out ftruncate
for Diablo because it's used in a code path that we probably never invoke, so we should be OK with just truncate
You could probably do ftruncate similarly to fstat https://github.com/pspdev/newlib/blob/7b50ff4d76f58e26fb33f6a4ea5f3a067ffe95be/newlib/libc/sys/psp/libcglue.c#L586
@fjtrujy Is this also fixed in the latest newlib?
truncate
is for sure, ftruncate
, I'm not sure, but it is easily doable.
Please check it, and if it is not implemented, create the issue in pspssdk
because is over there where we will implement it
We no longer use ftruncate
in DevilutionX, only truncate
, so we can close this one
Would it be possible to implement
truncate
?@AJenbo is looking into trying to build DevilutionX (for Diablo 1) and this function is used to size save files correctly.