Skip to content

Commit

Permalink
Add PSP/Vita ifdefs to retro_file.c
Browse files Browse the repository at this point in the history
  • Loading branch information
inactive123 committed Sep 17, 2015
1 parent 4ed3d66 commit a6458d6
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 0 deletions.
1 change: 1 addition & 0 deletions Makefile.ps3.salamander
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ PPU_SRCS = frontend/frontend_salamander.c \
libretro-common/hash/rhash.c \
libretro-common/string/string_list.c \
libretro-common/compat/compat.c \
libretro-common/file/retro_file.c \
libretro-common/file/config_file.c

ifeq ($(HAVE_LOGGER), 1)
Expand Down
1 change: 1 addition & 0 deletions Makefile.psp1.salamander
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ OBJS = frontend/frontend_salamander.o \
libretro-common/file/retro_dirent.o \
libretro-common/compat/compat.o \
libretro-common/file/config_file.o \
libretro-common/file/retro_file.o \
libretro-common/hash/rhash.o \
psp1/kernel_functions.o

Expand Down
1 change: 1 addition & 0 deletions Makefile.wii.salamander
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ OBJ = frontend/frontend_salamander.o \
libretro-common/hash/rhash.o \
libretro-common/string/string_list.o \
libretro-common/file/dir_list.o \
libretro-common/file/retro_file.o \
libretro-common/file/retro_dirent.o \
libretro-common/compat/compat.o \
libretro-common/file/config_file.o \
Expand Down
32 changes: 32 additions & 0 deletions libretro-common/file/retro_file.c
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,11 @@

struct RFILE
{
#if defined(PSP) || defined(VITA)
SceUID fd;
#else
int fd;
#endif
};

RFILE *retro_fopen(const char *path, unsigned mode, ssize_t len)
Expand All @@ -53,16 +57,28 @@ RFILE *retro_fopen(const char *path, unsigned mode, ssize_t len)
switch (mode)
{
case RFILE_MODE_READ:
#if defined(VITA) || defined(PSP)
stream->fd = sceIoOpen(path, O_RDONLY, 0777);
#else
stream->fd = open(path, O_RDONLY);
#endif
break;
case RFILE_MODE_WRITE:
#if defined(VITA) || defined(PSP)
stream->fd = sceIoOpen(path, O_WRONLY | O_CREAT, 0777);
#else
stream->fd = open(path, O_WRONLY | O_CREAT | O_TRUNC, S_IRUSR | S_IWUSR);
#endif
break;
case RFILE_MODE_READ_WRITE:
#if defined(VITA) || defined(PSP)
stream->fd = sceIoOpen(path, O_RDWR, 0777);
#else
#ifdef _WIN32
stream->fd = open(path, O_RDWR | O_BINARY);
#else
stream->fd = open(path, O_RDWR);
#endif
#endif
break;
}
Expand All @@ -75,29 +91,45 @@ ssize_t retro_fseek(RFILE *stream, ssize_t offset, int whence)
if (!stream)
return -1;

#if defined(VITA) || defined(PSP)
return sceIoLseek(stream->fd, (SceOff)offset, whence);
#else
return lseek(stream->fd, offset, whence);
#endif
}

ssize_t retro_fread(RFILE *stream, void *s, size_t len)
{
if (!stream)
return -1;
#if defined(VITA) || defined(PSP)
return sceIoRead(stream->fd, s, len);
#else
return read(stream->fd, s, len);
#endif
}

ssize_t retro_fwrite(RFILE *stream, const void *s, size_t len)
{
if (!stream)
return -1;
#if defined(VITA) || defined(PSP)
return sceIoWrite(stream->fd, s, len);
#else
return write(stream->fd, s, len);
#endif
}

void retro_fclose(RFILE *stream)
{
if (!stream)
return;

#if defined(VITA) || defined(PSP)
sceIoClose(stream->fd);
#else
close(stream->fd);
#endif
free(stream);
}

Expand Down

0 comments on commit a6458d6

Please sign in to comment.