Handling of return values of filesystem functions (fread, write etc) by printing to console when the return value isn't equal to size of the data being read/written
git-svn-id: https://svn.code.sf.net/p/fteqw/code/branches/wip@3801 fc73d0e0-1445-4013-8a0c-d673dee63da5
This commit is contained in:
parent
afa29b36fb
commit
4b93855ff8
10 changed files with 50 additions and 9 deletions
|
@ -22,6 +22,7 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||||
#include "quakedef.h"
|
#include "quakedef.h"
|
||||||
|
|
||||||
#include "winquake.h"
|
#include "winquake.h"
|
||||||
|
#include "errno.h"
|
||||||
|
|
||||||
int cache_full_cycle;
|
int cache_full_cycle;
|
||||||
|
|
||||||
|
@ -806,6 +807,10 @@ sfxcache_t *S_LoadSound (sfx_t *s)
|
||||||
com_filesize = COM_filelength(f);
|
com_filesize = COM_filelength(f);
|
||||||
data = Hunk_TempAlloc (com_filesize);
|
data = Hunk_TempAlloc (com_filesize);
|
||||||
result = fread(data, 1, com_filesize, f); //do something with result
|
result = fread(data, 1, com_filesize, f); //do something with result
|
||||||
|
|
||||||
|
if (result != com_filesize)
|
||||||
|
Con_SafePrintf("S_LoadSound() fread: Filename: %s, expected %i, result was %i (%i)\n",name,com_filesize,result,errno);
|
||||||
|
|
||||||
fclose(f);
|
fclose(f);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
|
|
@ -355,6 +355,10 @@ int Sys_DebugLog(char *file, char *fmt, ...)
|
||||||
if (fd)
|
if (fd)
|
||||||
{
|
{
|
||||||
result = write(fd, data, strlen(data)); // do something with result
|
result = write(fd, data, strlen(data)); // do something with result
|
||||||
|
|
||||||
|
if (result != strlen(data))
|
||||||
|
Con_SafePrintf("Sys_DebugLog() write: Filename: %s, expected %i, result was %i (%i)\n",file,strlen(data),result,errno);
|
||||||
|
|
||||||
close(fd);
|
close(fd);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
|
@ -20,6 +20,7 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||||
// cmd.c -- Quake script command processing module
|
// cmd.c -- Quake script command processing module
|
||||||
|
|
||||||
#include "quakedef.h"
|
#include "quakedef.h"
|
||||||
|
#include "errno.h"
|
||||||
|
|
||||||
cvar_t com_fs_cache = SCVARF("fs_cache", IFMINIMAL("2","1"), CVAR_ARCHIVE);
|
cvar_t com_fs_cache = SCVARF("fs_cache", IFMINIMAL("2","1"), CVAR_ARCHIVE);
|
||||||
cvar_t rcon_level = SCVAR("rcon_level", "20");
|
cvar_t rcon_level = SCVAR("rcon_level", "20");
|
||||||
|
@ -1119,6 +1120,10 @@ char *Cmd_ExpandCvar(char *cvarname, int maxaccesslevel, int *len)
|
||||||
}
|
}
|
||||||
|
|
||||||
result = strtol(cvarname, &end, 10); // do something with result
|
result = strtol(cvarname, &end, 10); // do something with result
|
||||||
|
|
||||||
|
if (result == 0)
|
||||||
|
Con_DPrintf("Cmd_ExpandCvar() strtol returned zero cvar: %s (%i)\n", cvarname, errno);
|
||||||
|
|
||||||
if (fixval && *end == '\0') //only expand $0 if its actually ${0} - this avoids conflicting with the $0 macro
|
if (fixval && *end == '\0') //only expand $0 if its actually ${0} - this avoids conflicting with the $0 macro
|
||||||
{ //purely numerical
|
{ //purely numerical
|
||||||
ret = Cmd_Argv(atoi(cvarname));
|
ret = Cmd_Argv(atoi(cvarname));
|
||||||
|
|
|
@ -22,6 +22,7 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||||
#include "quakedef.h"
|
#include "quakedef.h"
|
||||||
|
|
||||||
#include <ctype.h>
|
#include <ctype.h>
|
||||||
|
#include <errno.h>
|
||||||
|
|
||||||
// These 4 libraries required for the version command
|
// These 4 libraries required for the version command
|
||||||
|
|
||||||
|
@ -3032,6 +3033,10 @@ void COM_InitArgv (int argc, const char **argv) //not allowed to tprint
|
||||||
|
|
||||||
buffer = (char*)malloc(len+1);
|
buffer = (char*)malloc(len+1);
|
||||||
result = fread(buffer, 1, len, f); // do something with result
|
result = fread(buffer, 1, len, f); // do something with result
|
||||||
|
|
||||||
|
if (result != len)
|
||||||
|
Con_SafePrintf("COM_InitArgv() fread: Filename: %s, expected %i, result was %i (%i)\n",va("%s_p.txt", argv[0]),len,result,errno);
|
||||||
|
|
||||||
buffer[len] = '\0';
|
buffer[len] = '\0';
|
||||||
|
|
||||||
while (*buffer && (argc < MAX_NUM_ARGVS))
|
while (*buffer && (argc < MAX_NUM_ARGVS))
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
#include "quakedef.h"
|
#include "quakedef.h"
|
||||||
#include "fs.h"
|
#include "fs.h"
|
||||||
|
#include "errno.h"
|
||||||
|
|
||||||
#ifdef WEBSVONLY
|
#ifdef WEBSVONLY
|
||||||
#define Z_Free free
|
#define Z_Free free
|
||||||
|
@ -221,6 +222,10 @@ static void FSSTDIO_ReadFile(void *handle, flocation_t *loc, char *buffer)
|
||||||
return;
|
return;
|
||||||
fseek(f, loc->offset, SEEK_SET);
|
fseek(f, loc->offset, SEEK_SET);
|
||||||
result = fread(buffer, 1, loc->len, f); // do soemthing with result
|
result = fread(buffer, 1, loc->len, f); // do soemthing with result
|
||||||
|
|
||||||
|
if (result != loc->len)
|
||||||
|
Con_SafePrintf("FSSTDIO_ReadFile() fread: Filename: %s, expected %i, result was %i (%i)\n",loc->rawname,loc->len,result,errno);
|
||||||
|
|
||||||
fclose(f);
|
fclose(f);
|
||||||
}
|
}
|
||||||
static int FSSTDIO_EnumerateFiles (void *handle, const char *match, int (*func)(const char *, int, void *), void *parm)
|
static int FSSTDIO_EnumerateFiles (void *handle, const char *match, int (*func)(const char *, int, void *), void *parm)
|
||||||
|
|
|
@ -3,6 +3,7 @@
|
||||||
#include "glquake.h"
|
#include "glquake.h"
|
||||||
#endif
|
#endif
|
||||||
#include "com_mesh.h"
|
#include "com_mesh.h"
|
||||||
|
#include "errno.h"
|
||||||
|
|
||||||
#define MAX_Q3MAP_INDICES 0x80000
|
#define MAX_Q3MAP_INDICES 0x80000
|
||||||
#define MAX_Q3MAP_VERTEXES 0x80000
|
#define MAX_Q3MAP_VERTEXES 0x80000
|
||||||
|
@ -5663,6 +5664,10 @@ void CM_ReadPortalState (FILE *f)
|
||||||
size_t result;
|
size_t result;
|
||||||
|
|
||||||
result = fread (portalopen, 1, sizeof(portalopen), f); // do something with result
|
result = fread (portalopen, 1, sizeof(portalopen), f); // do something with result
|
||||||
|
|
||||||
|
if (result != sizeof(portalopen))
|
||||||
|
Con_SafePrintf("CM_ReadPortalState() fread: expected %i, result was %i (%i)\n",sizeof(portalopen),result,errno);
|
||||||
|
|
||||||
FloodAreaConnections ();
|
FloodAreaConnections ();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
#include "quakedef.h"
|
#include "quakedef.h"
|
||||||
|
#include "errno.h"
|
||||||
|
|
||||||
#undef malloc
|
#undef malloc
|
||||||
#undef free
|
#undef free
|
||||||
|
@ -582,6 +583,10 @@ void TL_LoadLanguage (char *name, char *shortname, int num) //this is one of the
|
||||||
buffer = malloc(size+1);
|
buffer = malloc(size+1);
|
||||||
buffer[size] = '\0';
|
buffer[size] = '\0';
|
||||||
result = fread(buffer, 1, size, f); // do something with result
|
result = fread(buffer, 1, size, f); // do something with result
|
||||||
|
|
||||||
|
if (result != size)
|
||||||
|
Con_SafePrintf("TL_LoadLanguage() fread: Filename: %s, expected %i, result was %i (%i)\n",va("%s.trl", shortname),size,result,errno);
|
||||||
|
|
||||||
fclose(f);
|
fclose(f);
|
||||||
|
|
||||||
TL_ParseLanguage(name, buffer, num);
|
TL_ParseLanguage(name, buffer, num);
|
||||||
|
|
|
@ -7,6 +7,8 @@
|
||||||
#include <direct.h>
|
#include <direct.h>
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#include "errno.h"
|
||||||
|
|
||||||
char QCC_copyright[1024];
|
char QCC_copyright[1024];
|
||||||
int QCC_packid;
|
int QCC_packid;
|
||||||
char QCC_Packname[5][128];
|
char QCC_Packname[5][128];
|
||||||
|
@ -296,6 +298,9 @@ void QCC_BspModels (void)
|
||||||
name[strlen(m)-4] = 0;
|
name[strlen(m)-4] = 0;
|
||||||
sprintf (cmd, "qbsp %s/%s ; light -extra %s/%s", gamedir, name, gamedir, name);
|
sprintf (cmd, "qbsp %s/%s ; light -extra %s/%s", gamedir, name, gamedir, name);
|
||||||
result = system (cmd); // do something with the result
|
result = system (cmd); // do something with the result
|
||||||
|
|
||||||
|
if (result != 0)
|
||||||
|
QCC_Error(ERR_INTERNAL, "QCC_BspModels() system returned non zero (failure) with: qbsp %s/%s ; light -extra %s/%s (%i)\n", gamedir, name, gamedir, name, errno);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
#include "qwsvdef.h"
|
#include "qwsvdef.h"
|
||||||
|
#include "errno.h"
|
||||||
|
|
||||||
#ifndef CLIENTONLY
|
#ifndef CLIENTONLY
|
||||||
|
|
||||||
|
@ -41,9 +42,8 @@ void inline READ_PLAYERSTATS(int x, rankstats_t *os)
|
||||||
fseek(rankfile, sizeof(rankfileheader_t)+sizeof(rankheader_t)+((x-1)*sizeof(rankinfo_t)), SEEK_SET);
|
fseek(rankfile, sizeof(rankfileheader_t)+sizeof(rankheader_t)+((x-1)*sizeof(rankinfo_t)), SEEK_SET);
|
||||||
result = fread(os, sizeof(rankstats_t), 1, rankfile);
|
result = fread(os, sizeof(rankstats_t), 1, rankfile);
|
||||||
|
|
||||||
// ignoring return value of ‘fread’, declared with attribute warn_unused_result
|
if (result != sizeof(rankstats_t))
|
||||||
if (result != 1)
|
Con_SafePrintf("READ_PLAYERSTATS() fread: expected %i, result was %i (%i)\n",sizeof(rankstats_t),result,errno);
|
||||||
fprintf(stderr, "fread() error in READ_PLAYERSTATS\n");
|
|
||||||
|
|
||||||
os->kills = swaplong(os->kills);
|
os->kills = swaplong(os->kills);
|
||||||
os->deaths = swaplong(os->deaths);
|
os->deaths = swaplong(os->deaths);
|
||||||
|
@ -84,9 +84,8 @@ void inline READ_PLAYERHEADER(int x, rankheader_t *oh)
|
||||||
|
|
||||||
result = fread(oh, sizeof(rankheader_t), 1, rankfile);
|
result = fread(oh, sizeof(rankheader_t), 1, rankfile);
|
||||||
|
|
||||||
// ignoring return value of ‘fread’, declared with attribute warn_unused_result
|
if (result != sizeof(rankheader_t))
|
||||||
if (result != 1)
|
Con_SafePrintf("READ_PLAYERHEADER() fread: expected %i, result was %i (%i)\n",sizeof(rankheader_t),result,errno);
|
||||||
fprintf(stderr, "fread() error in WRITE_PLAYERSTATS\n");
|
|
||||||
|
|
||||||
oh->prev = swaplong(oh->prev); //score is held for convineance.
|
oh->prev = swaplong(oh->prev); //score is held for convineance.
|
||||||
oh->next = swaplong(oh->next);
|
oh->next = swaplong(oh->next);
|
||||||
|
@ -164,9 +163,8 @@ qboolean Rank_OpenRankings(void)
|
||||||
fseek(rankfile, 0, SEEK_SET);
|
fseek(rankfile, 0, SEEK_SET);
|
||||||
result = fread(&rankfileheader, sizeof(rankfileheader_t), 1, rankfile);
|
result = fread(&rankfileheader, sizeof(rankfileheader_t), 1, rankfile);
|
||||||
|
|
||||||
// ignoring return value of ‘fread’, declared with attribute warn_unused_result
|
if (result != sizeof(rankfileheader_t))
|
||||||
if (result != 1)
|
Con_SafePrintf("Rank_OpenRankings() fread: expected %i, result was %i (%i)\n",sizeof(rankfileheader_t),result,errno);
|
||||||
fprintf(stderr, "fread() error in Rank_OpenRankings\n");
|
|
||||||
|
|
||||||
rankfileheader.version = swaplong(rankfileheader.version);
|
rankfileheader.version = swaplong(rankfileheader.version);
|
||||||
rankfileheader.usedslots = swaplong(rankfileheader.usedslots);
|
rankfileheader.usedslots = swaplong(rankfileheader.usedslots);
|
||||||
|
|
|
@ -117,6 +117,10 @@ int Sys_DebugLog(char *file, char *fmt, ...)
|
||||||
if (fd)
|
if (fd)
|
||||||
{
|
{
|
||||||
result = write(fd, data, strlen(data)); // do something with the result
|
result = write(fd, data, strlen(data)); // do something with the result
|
||||||
|
|
||||||
|
if (result != strlen(data))
|
||||||
|
Con_SafePrintf("Sys_DebugLog() write: Filename: %s, expected %i, result was %i (%i)\n",file,strlen(data),result,errno);
|
||||||
|
|
||||||
close(fd);
|
close(fd);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue