Permalink
Browse files

PSP2: Better truncate

  • Loading branch information...
endrift committed Jan 10, 2018
1 parent 36a0f43 commit 715efc63bd7178fc5a0058588b81de03fe74bc6d
Showing with 6 additions and 14 deletions.
  1. +6 −14 src/platform/psp2/sce-vfs.c
@@ -10,6 +10,10 @@
#include <mgba-util/vfs.h>
#include <mgba-util/memory.h>
+#ifndef SCE_CST_SIZE
+#define SCE_CST_SIZE 0x0004
+#endif
+
struct VFileSce {
struct VFile d;
@@ -120,20 +124,8 @@ static void _vfsceUnmap(struct VFile* vf, void* memory, size_t size) {
static void _vfsceTruncate(struct VFile* vf, size_t size) {
struct VFileSce* vfsce = (struct VFileSce*) vf;
- SceOff cur = sceIoLseek(vfsce->fd, 0, SEEK_CUR);
- SceOff end = sceIoLseek(vfsce->fd, 0, SEEK_END);
- if (end < size) {
- uint8_t buffer[2048] = {};
- size_t write = size - end;
- while (write >= sizeof(buffer)) {
- sceIoWrite(vfsce->fd, buffer, sizeof(buffer));
- write -= sizeof(buffer);
- }
- if (write) {
- sceIoWrite(vfsce->fd, buffer, write);
- }
- } // TODO: Else
- sceIoLseek(vfsce->fd, cur, SEEK_SET);
+ SceIoStat stat = { .st_size = size };
+ sceIoChstatByFd(vfsce->fd, &stat, SCE_CST_SIZE);
}
ssize_t _vfsceSize(struct VFile* vf) {

0 comments on commit 715efc6

Please sign in to comment.