Revert retro_file.c

This commit is contained in:
twinaphex 2015-09-18 02:38:48 +02:00
parent 93e73b7ac0
commit 35bd6e6ec8

View File

@ -38,16 +38,16 @@
#include <fcntl.h>
#endif
#if 1
#if 0
#define HAVE_BUFFERED_IO 1
#endif
struct RFILE
{
#if defined(PSP) || defined(VITA)
SceUID sfd;
SceUID fd;
#elif defined(HAVE_BUFFERED_IO)
FILE *file;
FILE *fd;
#else
int fd;
#endif
@ -64,27 +64,27 @@ RFILE *retro_fopen(const char *path, unsigned mode, ssize_t len)
{
case RFILE_MODE_READ:
#if defined(VITA) || defined(PSP)
stream->sfd = sceIoOpen(path, O_RDONLY, 0777);
stream->fd = sceIoOpen(path, O_RDONLY, 0777);
#elif defined(HAVE_BUFFERED_IO)
stream->file = fopen(path, "rb");
stream->fd = fopen(path, "rb");
#else
stream->fd = open(path, O_RDONLY);
#endif
break;
case RFILE_MODE_WRITE:
#if defined(VITA) || defined(PSP)
stream->sfd = sceIoOpen(path, O_WRONLY | O_CREAT, 0777);
stream->fd = sceIoOpen(path, O_WRONLY | O_CREAT, 0777);
#elif defined(HAVE_BUFFERED_IO)
stream->file = fopen(path, "wb");
stream->fd = fopen(path, "wb");
#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->sfd = sceIoOpen(path, O_RDWR, 0777);
stream->fd = sceIoOpen(path, O_RDWR, 0777);
#elif defined(HAVE_BUFFERED_IO)
stream->file = fopen(path, "w+b");
stream->fd = fopen(path, "w+");
#else
#ifdef _WIN32
stream->fd = open(path, O_RDWR | O_BINARY);
@ -95,10 +95,8 @@ RFILE *retro_fopen(const char *path, unsigned mode, ssize_t len)
break;
}
#if defined(VITA) || defined(PSP)
if (stream->sfd == -1)
#elif defined(HAVE_BUFFERED_IO)
if (!stream->file)
#if defined(HAVE_BUFFERED_IO)
if (!stream->fd)
#else
if (stream->fd == -1)
#endif
@ -117,9 +115,9 @@ ssize_t retro_fseek(RFILE *stream, ssize_t offset, int whence)
return -1;
#if defined(VITA) || defined(PSP)
return sceIoLseek(stream->sfd, (SceOff)offset, whence);
return sceIoLseek(stream->fd, (SceOff)offset, whence);
#elif defined(HAVE_BUFFERED_IO)
return fseek(stream->file, (long)offset, whence);
return fseek(stream->fd, (long)offset, whence);
#else
return lseek(stream->fd, offset, whence);
#endif
@ -130,9 +128,9 @@ ssize_t retro_fread(RFILE *stream, void *s, size_t len)
if (!stream)
return -1;
#if defined(VITA) || defined(PSP)
return sceIoRead(stream->sfd, s, len);
return sceIoRead(stream->fd, s, len);
#elif defined(HAVE_BUFFERED_IO)
return fread(s, 1, len, stream->file);
return fread(s, len, 1, stream->fd);
#else
return read(stream->fd, s, len);
#endif
@ -143,9 +141,9 @@ ssize_t retro_fwrite(RFILE *stream, const void *s, size_t len)
if (!stream)
return -1;
#if defined(VITA) || defined(PSP)
return sceIoWrite(stream->sfd, s, len);
return sceIoWrite(stream->fd, s, len);
#elif defined(HAVE_BUFFERED_IO)
return fwrite(s, 1, len, stream->file);
return fwrite(s, len, 1, stream->fd);
#else
return write(stream->fd, s, len);
#endif
@ -157,11 +155,11 @@ void retro_fclose(RFILE *stream)
return;
#if defined(VITA) || defined(PSP)
if (stream->sfd > 0)
sceIoClose(stream->sfd);
if (stream->fd > 0)
sceIoClose(stream->fd);
#elif defined(HAVE_BUFFERED_IO)
if (stream->file)
fclose(stream->file);
if (stream->fd)
fclose(stream->fd);
#else
if (stream->fd > 0)
close(stream->fd);
@ -185,7 +183,7 @@ bool retro_fmemcpy(const char *path, char *s, size_t len, ssize_t *bytes_written
if (!stream)
return false;
while(retro_fread_iterate(stream, s, len-1, bytes_written));
while(retro_fread_iterate(stream, s, len, bytes_written));
retro_fclose(stream);
if (*bytes_written < 0)