mirror of
https://github.com/libretro/beetle-pce-fast-libretro.git
synced 2024-11-23 07:50:03 +00:00
Cleanups
This commit is contained in:
parent
1ea41d26aa
commit
c2cc9e28a9
@ -26,7 +26,9 @@
|
||||
#include <stdarg.h>
|
||||
#include <string.h>
|
||||
|
||||
#ifdef __CELLOS_LV2__
|
||||
#ifdef _WIN32
|
||||
#include <io.h>
|
||||
#else
|
||||
#include <unistd.h>
|
||||
#endif
|
||||
|
||||
|
@ -23,7 +23,9 @@
|
||||
#include <stdarg.h>
|
||||
#include <string.h>
|
||||
|
||||
#ifdef __CELLOS_LV2__
|
||||
#ifdef _WIN32
|
||||
#include <io.h>
|
||||
#else
|
||||
#include <unistd.h>
|
||||
#endif
|
||||
|
||||
|
@ -24,8 +24,6 @@
|
||||
#include "file.h"
|
||||
#include "general.h"
|
||||
|
||||
#define MDFN_FILETYPE_PLAIN 0
|
||||
|
||||
bool MDFNFILE::ApplyIPS(void *unused)
|
||||
{
|
||||
(void)unused;
|
||||
@ -35,21 +33,19 @@ bool MDFNFILE::ApplyIPS(void *unused)
|
||||
|
||||
// This function should ALWAYS close the system file "descriptor"(gzip library, zip library, or FILE *) it's given,
|
||||
// even if it errors out.
|
||||
bool MDFNFILE::MakeMemWrapAndClose(void *tz)
|
||||
bool MDFNFILE::MakeMemWrapAndClose(void *fp)
|
||||
{
|
||||
bool ret = FALSE;
|
||||
|
||||
location = 0;
|
||||
|
||||
::fseek((FILE *)tz, 0, SEEK_END);
|
||||
f_size = ::ftell((FILE *)tz);
|
||||
::fseek((FILE *)tz, 0, SEEK_SET);
|
||||
::fseek((FILE *)fp, 0, SEEK_END);
|
||||
f_size = ::ftell((FILE *)fp);
|
||||
::fseek((FILE *)fp, 0, SEEK_SET);
|
||||
|
||||
if (!(f_data = (uint8*)MDFN_malloc(f_size, _("file read buffer"))))
|
||||
{
|
||||
goto doret;
|
||||
}
|
||||
if((int64)::fread(f_data, 1, f_size, (FILE *)tz) != f_size)
|
||||
if ((int64)::fread(f_data, 1, f_size, (FILE *)fp) != f_size)
|
||||
{
|
||||
ErrnoHolder ene(errno);
|
||||
MDFN_PrintError(_("Error reading file: %s"), ene.StrError());
|
||||
@ -61,9 +57,9 @@ bool MDFNFILE::MakeMemWrapAndClose(void *tz)
|
||||
ret = TRUE;
|
||||
|
||||
doret:
|
||||
fclose((FILE *)tz);
|
||||
fclose((FILE *)fp);
|
||||
|
||||
return(ret);
|
||||
return ret;
|
||||
}
|
||||
|
||||
MDFNFILE::MDFNFILE()
|
||||
@ -101,13 +97,13 @@ bool MDFNFILE::Open(const char *path, const void *known_ext, const char *purpose
|
||||
if (ene.Errno() != ENOENT || !suppress_notfound_pe)
|
||||
MDFN_PrintError(_("Error opening \"%s\": %s"), path, ene.StrError());
|
||||
|
||||
return(0);
|
||||
return 0;
|
||||
}
|
||||
|
||||
::fseek(fp, 0, SEEK_SET);
|
||||
|
||||
if (!MakeMemWrapAndClose(fp))
|
||||
return(0);
|
||||
return 0;
|
||||
|
||||
const char *ld = strrchr(path, '.');
|
||||
f_ext = strdup(ld ? ld + 1 : "");
|
||||
@ -165,17 +161,20 @@ int MDFNFILE::fseek(int64 offset, int whence)
|
||||
{
|
||||
switch(whence)
|
||||
{
|
||||
case SEEK_SET:if(offset >= f_size)
|
||||
return(-1);
|
||||
case SEEK_SET:
|
||||
if (offset >= f_size)
|
||||
return -1;
|
||||
|
||||
location = offset;
|
||||
break;
|
||||
|
||||
case SEEK_CUR:if((offset + location) > f_size)
|
||||
return(-1);
|
||||
case SEEK_CUR:
|
||||
if ((offset + location) > f_size)
|
||||
return -1;
|
||||
|
||||
location += offset;
|
||||
break;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
@ -188,7 +187,7 @@ int MDFNFILE::read16le(uint16 *val)
|
||||
|
||||
location += 2;
|
||||
|
||||
return(1);
|
||||
return 1;
|
||||
}
|
||||
|
||||
int MDFNFILE::read32le(uint32 *val)
|
||||
@ -200,7 +199,7 @@ int MDFNFILE::read32le(uint32 *val)
|
||||
|
||||
location += 4;
|
||||
|
||||
return(1);
|
||||
return 1;
|
||||
}
|
||||
|
||||
char *MDFNFILE::fgets(char *s, int buffer_size)
|
||||
@ -219,13 +218,14 @@ char *MDFNFILE::fgets(char *s, int buffer_size)
|
||||
s[pos] = v;
|
||||
location++;
|
||||
pos++;
|
||||
if(v == '\n') break;
|
||||
if (v == '\n')
|
||||
break;
|
||||
}
|
||||
|
||||
if (buffer_size)
|
||||
s[pos] = 0;
|
||||
|
||||
return(s);
|
||||
return s;
|
||||
}
|
||||
|
||||
static INLINE bool MDFN_DumpToFileReal(const char *filename, int compress, const std::vector<PtrLengthPair> &pearpairs)
|
||||
@ -233,7 +233,7 @@ static INLINE bool MDFN_DumpToFileReal(const char *filename, int compress, const
|
||||
FILE *fp = fopen(filename, "wb");
|
||||
|
||||
if (!fp)
|
||||
return(0);
|
||||
return 0;
|
||||
|
||||
for(unsigned int i = 0; i < pearpairs.size(); i++)
|
||||
{
|
||||
@ -243,14 +243,14 @@ static INLINE bool MDFN_DumpToFileReal(const char *filename, int compress, const
|
||||
if (fwrite(data, 1, length, fp) != length)
|
||||
{
|
||||
fclose(fp);
|
||||
return(0);
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
if (fclose(fp) == EOF)
|
||||
return(0);
|
||||
return 0;
|
||||
|
||||
return(1);
|
||||
return 1;
|
||||
}
|
||||
|
||||
bool MDFN_DumpToFile(const char *filename, int compress, const std::vector<PtrLengthPair> &pearpairs)
|
||||
|
@ -27,7 +27,9 @@
|
||||
|
||||
#include <ctype.h>
|
||||
|
||||
#ifdef __CELLOS_LV2__
|
||||
#ifdef _WIN32
|
||||
#include <io.h>
|
||||
#else
|
||||
#include <unistd.h>
|
||||
#endif
|
||||
|
||||
|
@ -30,7 +30,7 @@
|
||||
int32 smem_read(StateMem *st, void *buffer, uint32 len)
|
||||
{
|
||||
if ((len + st->loc) > st->len)
|
||||
return(0);
|
||||
return 0;
|
||||
|
||||
memcpy(buffer, st->data + st->loc, len);
|
||||
st->loc += len;
|
||||
@ -52,7 +52,8 @@ int32 smem_write(StateMem *st, void *buffer, uint32 len)
|
||||
memcpy(st->data + st->loc, buffer, len);
|
||||
st->loc += len;
|
||||
|
||||
if(st->loc > st->len) st->len = st->loc;
|
||||
if (st->loc > st->len)
|
||||
st->len = st->loc;
|
||||
|
||||
return(len);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user