mirror of
https://github.com/libretro/pcsx2.git
synced 2024-12-29 13:13:31 +00:00
gcc-warning: check c function return. Print error when bad.
v2: properly check return code of fread/getcwd function
This commit is contained in:
parent
22b65489e2
commit
58077c63a7
@ -146,7 +146,9 @@ struct PluginConf
|
||||
int value = defval;
|
||||
std::string buf = item + " = %d\n";
|
||||
|
||||
if (ConfFile) fscanf(ConfFile, buf.c_str(), &value);
|
||||
if (ConfFile)
|
||||
if (fscanf(ConfFile, buf.c_str(), &value) < 0)
|
||||
SysMessage("Somethings got wrong when option was read\n");
|
||||
|
||||
return value;
|
||||
}
|
||||
|
@ -1415,6 +1415,18 @@ inline unsigned long timeGetTime()
|
||||
return (unsigned long)(t.time*1000 + t.millitm);
|
||||
}
|
||||
|
||||
void _fread(void *ptr, size_t size, size_t nmemb, FILE *stream)
|
||||
{
|
||||
static uint32 read_cnt = 0;
|
||||
read_cnt++;
|
||||
|
||||
size_t result = fread(ptr, size, nmemb, stream);
|
||||
if (result != nmemb) {
|
||||
fprintf(stderr, "Read error\n");
|
||||
exit(read_cnt);
|
||||
}
|
||||
}
|
||||
|
||||
// Note
|
||||
EXPORT_C GSReplay(char* lpszCmdLine, int renderer)
|
||||
{
|
||||
@ -1471,17 +1483,17 @@ EXPORT_C GSReplay(char* lpszCmdLine, int renderer)
|
||||
if (s_gs->m_wnd == NULL) return;
|
||||
|
||||
uint32 crc;
|
||||
fread(&crc, 4, 1, fp);
|
||||
_fread(&crc, 4, 1, fp);
|
||||
GSsetGameCRC(crc, 0);
|
||||
|
||||
GSFreezeData fd;
|
||||
fread(&fd.size, 4, 1, fp);
|
||||
_fread(&fd.size, 4, 1, fp);
|
||||
fd.data = new uint8[fd.size];
|
||||
fread(fd.data, fd.size, 1, fp);
|
||||
_fread(fd.data, fd.size, 1, fp);
|
||||
GSfreeze(FREEZE_LOAD, &fd);
|
||||
delete [] fd.data;
|
||||
|
||||
fread(regs, 0x2000, 1, fp);
|
||||
_fread(regs, 0x2000, 1, fp);
|
||||
|
||||
GSvsync(1);
|
||||
|
||||
@ -1503,20 +1515,20 @@ EXPORT_C GSReplay(char* lpszCmdLine, int renderer)
|
||||
|
||||
p->param = (uint8)fgetc(fp);
|
||||
|
||||
fread(&p->size, 4, 1, fp);
|
||||
_fread(&p->size, 4, 1, fp);
|
||||
|
||||
switch(p->param)
|
||||
{
|
||||
case 0:
|
||||
p->buff.resize(0x4000);
|
||||
p->addr = 0x4000 - p->size;
|
||||
fread(&p->buff[p->addr], p->size, 1, fp);
|
||||
_fread(&p->buff[p->addr], p->size, 1, fp);
|
||||
break;
|
||||
case 1:
|
||||
case 2:
|
||||
case 3:
|
||||
p->buff.resize(p->size);
|
||||
fread(&p->buff[0], p->size, 1, fp);
|
||||
_fread(&p->buff[0], p->size, 1, fp);
|
||||
break;
|
||||
}
|
||||
|
||||
@ -1530,7 +1542,7 @@ EXPORT_C GSReplay(char* lpszCmdLine, int renderer)
|
||||
|
||||
case 2:
|
||||
|
||||
fread(&p->size, 4, 1, fp);
|
||||
_fread(&p->size, 4, 1, fp);
|
||||
|
||||
break;
|
||||
|
||||
@ -1538,7 +1550,7 @@ EXPORT_C GSReplay(char* lpszCmdLine, int renderer)
|
||||
|
||||
p->buff.resize(0x2000);
|
||||
|
||||
fread(&p->buff[0], 0x2000, 1, fp);
|
||||
_fread(&p->buff[0], 0x2000, 1, fp);
|
||||
|
||||
break;
|
||||
}
|
||||
|
@ -228,7 +228,7 @@ public:
|
||||
}
|
||||
|
||||
void Set() {pthread_cond_signal(&m_cv);}
|
||||
bool Wait(IGSLock* l) {pthread_cond_wait(&m_cv, *(GSCondVarLock*)l) == 0; return true;}
|
||||
bool Wait(IGSLock* l) {return pthread_cond_wait(&m_cv, *(GSCondVarLock*)l) == 0;}
|
||||
|
||||
operator pthread_cond_t* () {return &m_cv;}
|
||||
};
|
||||
|
@ -642,6 +642,17 @@ EXPORT_C_(s32) GSfreeze(int mode, freezeData *data)
|
||||
}
|
||||
|
||||
#ifdef __LINUX__
|
||||
void _fread(void *ptr, size_t size, size_t nmemb, FILE *stream)
|
||||
{
|
||||
static uint32 read_cnt = 0;
|
||||
read_cnt++;
|
||||
|
||||
size_t result = fread(ptr, size, nmemb, stream);
|
||||
if (result != nmemb) {
|
||||
fprintf(stderr, "Read error\n");
|
||||
exit(read_cnt);
|
||||
}
|
||||
}
|
||||
|
||||
struct Packet
|
||||
{
|
||||
@ -664,21 +675,21 @@ EXPORT_C_(void) GSReplay(char* lpszCmdLine)
|
||||
|
||||
void* hWnd = NULL;
|
||||
|
||||
//_GSopen((void**)&hWnd, "", renderer);
|
||||
GSopen((void**)&hWnd, "", 0);
|
||||
const char* title = "replayer";
|
||||
GSopen((void**)&hWnd, (char*)title, 0);
|
||||
|
||||
u32 crc;
|
||||
fread(&crc, 4, 1, fp);
|
||||
_fread(&crc, 4, 1, fp);
|
||||
GSsetGameCRC(crc, 0);
|
||||
|
||||
freezeData fd;
|
||||
fread(&fd.size, 4, 1, fp);
|
||||
_fread(&fd.size, 4, 1, fp);
|
||||
fd.data = new s8[fd.size];
|
||||
fread(fd.data, fd.size, 1, fp);
|
||||
_fread(fd.data, fd.size, 1, fp);
|
||||
GSfreeze(FREEZE_LOAD, &fd);
|
||||
delete [] fd.data;
|
||||
|
||||
fread(regs, 0x2000, 1, fp);
|
||||
_fread(regs, 0x2000, 1, fp);
|
||||
|
||||
GSvsync(1);
|
||||
|
||||
@ -698,8 +709,8 @@ EXPORT_C_(void) GSReplay(char* lpszCmdLine)
|
||||
|
||||
p->param = (u8)fgetc(fp);
|
||||
|
||||
fread(&p->size, 4, 1, fp);
|
||||
fread(&p->real_size, 4, 1, fp);
|
||||
_fread(&p->size, 4, 1, fp);
|
||||
_fread(&p->real_size, 4, 1, fp);
|
||||
|
||||
switch(p->param)
|
||||
{
|
||||
@ -707,13 +718,13 @@ EXPORT_C_(void) GSReplay(char* lpszCmdLine)
|
||||
p->buff.resize(0x4000);
|
||||
//p->addr = 0x4000 - p->size;
|
||||
//fread(&p->buff[p->addr], p->size, 1, fp);
|
||||
fread(&p->buff[0], p->size, 1, fp);
|
||||
_fread(&p->buff[0], p->size, 1, fp);
|
||||
break;
|
||||
case 1:
|
||||
case 2:
|
||||
case 3:
|
||||
p->buff.resize(p->size);
|
||||
fread(&p->buff[0], p->size, 1, fp);
|
||||
_fread(&p->buff[0], p->size, 1, fp);
|
||||
break;
|
||||
}
|
||||
|
||||
@ -721,14 +732,14 @@ EXPORT_C_(void) GSReplay(char* lpszCmdLine)
|
||||
|
||||
case 1:
|
||||
|
||||
fread(&p->param, 4, 1, fp);
|
||||
_fread(&p->param, 4, 1, fp);
|
||||
//p->param = (u8)fgetc(fp);
|
||||
|
||||
break;
|
||||
|
||||
case 2:
|
||||
|
||||
fread(&p->size, 4, 1, fp);
|
||||
_fread(&p->size, 4, 1, fp);
|
||||
|
||||
break;
|
||||
|
||||
@ -736,7 +747,7 @@ EXPORT_C_(void) GSReplay(char* lpszCmdLine)
|
||||
|
||||
p->buff.resize(0x2000);
|
||||
|
||||
fread(&p->buff[0], 0x2000, 1, fp);
|
||||
_fread(&p->buff[0], 0x2000, 1, fp);
|
||||
|
||||
break;
|
||||
|
||||
|
@ -435,7 +435,10 @@ void DisplayDialog()
|
||||
EXPORT_C_(void) GSconfigure()
|
||||
{
|
||||
char strcurdir[256];
|
||||
getcwd(strcurdir, 256);
|
||||
if (getcwd(strcurdir, 256) == NULL) {
|
||||
fprintf(stderr, "Failed to get current working directory\n");
|
||||
return;
|
||||
}
|
||||
|
||||
if (!(conf.loaded())) LoadConfig();
|
||||
|
||||
|
@ -270,7 +270,9 @@ __forceinline bool LoadShadersFromDat()
|
||||
size_t s = ftell(fres);
|
||||
s_lpShaderResources = new u8[s+1];
|
||||
fseek(fres, 0, SEEK_SET);
|
||||
fread(s_lpShaderResources, s, 1, fres);
|
||||
if (fread(s_lpShaderResources, s, 1, fres) == 0)
|
||||
fprintf(stderr, "Failed to read ps2hw.dat. Corrupted file?\n");
|
||||
|
||||
s_lpShaderResources[s] = 0;
|
||||
|
||||
return true;
|
||||
|
@ -221,7 +221,8 @@ bool ZZshCreateOpenShadersFile() {
|
||||
size_t s = ftell(fres);
|
||||
s_lpShaderResources = new u8[s+1];
|
||||
fseek(fres, 0, SEEK_SET);
|
||||
fread(s_lpShaderResources, s, 1, fres);
|
||||
if (fread(s_lpShaderResources, s, 1, fres) == 0)
|
||||
ZZLog::Error_Log("Cannot read ps2hw.dat in working directory.");
|
||||
s_lpShaderResources[s] = 0;
|
||||
# endif // _WIN32
|
||||
#else // NOT RELEASE_TO_PUBLIC
|
||||
|
Loading…
Reference in New Issue
Block a user