mirror of
https://github.com/ZDoom/raze-gles.git
synced 2024-11-11 07:11:39 +00:00
Factor out snprintf'ing a maybe-modDir'd file name into macro G_ModDirSnprintf().
... and use it in three places. In two of these uses, 1) CON {read,write}arrayfromfile and 2) G_SavePlayer, display an error message if the file name such generated is too long. In the CON commands of 1), also error out if the file couldn't be opened. git-svn-id: https://svn.eduke32.com/eduke32@2997 1a8010ca-5511-0410-912e-c29ae57300e0
This commit is contained in:
parent
e417274c1e
commit
bb5d3496ee
4 changed files with 28 additions and 18 deletions
|
@ -173,22 +173,17 @@ void G_OpenDemoWrite(void)
|
|||
|
||||
do
|
||||
{
|
||||
int32_t nch;
|
||||
|
||||
if (demonum == 10000)
|
||||
return;
|
||||
|
||||
if (g_modDir[0] != '/')
|
||||
nch=Bsnprintf(demofn, sizeof(demofn), "%s/edemo%d.edm", g_modDir, demonum++);
|
||||
else nch=Bsnprintf(demofn, sizeof(demofn), "edemo%d.edm", demonum++);
|
||||
|
||||
if ((unsigned)nch >= sizeof(demofn)-1)
|
||||
if (G_ModDirSnprintf(demofn, sizeof(demofn), "edemo%d.edm", demonum))
|
||||
{
|
||||
// TODO: factor out this out and use everywhere else.
|
||||
initprintf("Couldn't start demo writing: INTERNAL ERROR: file name too long\n");
|
||||
goto error_wopen_demo;
|
||||
}
|
||||
|
||||
demonum++;
|
||||
|
||||
g_demo_filePtr = Bfopen(demofn, "rb");
|
||||
if (g_demo_filePtr == NULL)
|
||||
break;
|
||||
|
|
|
@ -372,4 +372,13 @@ enum {
|
|||
ST_31_TWO_WAY_TRAIN = 31,
|
||||
};
|
||||
|
||||
# define G_ModDirSnprintf(buf, size, basename, ...) \
|
||||
( \
|
||||
( \
|
||||
(g_modDir[0] != '/') ? \
|
||||
Bsnprintf(buf, size, "%s/" basename, g_modDir, ## __VA_ARGS__) : \
|
||||
Bsnprintf(buf, size, basename, ## __VA_ARGS__) \
|
||||
) >= ((int32_t)size)-1 \
|
||||
)
|
||||
|
||||
#endif
|
||||
|
|
|
@ -4224,11 +4224,18 @@ nullquote:
|
|||
FILE *fil;
|
||||
char temp[BMAX_PATH];
|
||||
|
||||
if (g_modDir[0] != '/')
|
||||
Bsprintf(temp,"%s/%s",g_modDir,ScriptQuotes[q]);
|
||||
else Bsprintf(temp,"%s",ScriptQuotes[q]);
|
||||
if (G_ModDirSnprintf(temp, sizeof(temp), "%s", ScriptQuotes[q]))
|
||||
{
|
||||
OSD_Printf(CON_ERROR "file name too long\n",g_errorLineNum,keyw[g_tw]);
|
||||
continue;
|
||||
}
|
||||
|
||||
if ((fil = fopen(temp,"wb")) == 0) continue;
|
||||
fil = fopen(temp,"wb");
|
||||
if (fil == NULL)
|
||||
{
|
||||
OSD_Printf(CON_ERROR "couldn't open file",g_errorLineNum,keyw[g_tw]);
|
||||
continue;
|
||||
}
|
||||
|
||||
fwrite(aGameArrays[j].plValues,1,sizeof(int) * aGameArrays[j].size,fil);
|
||||
fclose(fil);
|
||||
|
|
|
@ -319,12 +319,11 @@ int32_t G_SavePlayer(int32_t spot)
|
|||
{
|
||||
char temp[BMAX_PATH];
|
||||
|
||||
// TODO: factor this out someday...
|
||||
if (g_modDir[0] != '/')
|
||||
Bsnprintf(temp, sizeof(temp), "%s/%s", g_modDir, fn);
|
||||
else
|
||||
Bsnprintf(temp, sizeof(temp), "%s", fn);
|
||||
temp[sizeof(temp)-1] = 0;
|
||||
if (G_ModDirSnprintf(temp, sizeof(temp), "%s", fn))
|
||||
{
|
||||
OSD_Printf("G_SavePlayer: file name \"%s\" too long\n", fn);
|
||||
return -1;
|
||||
}
|
||||
|
||||
errno = 0;
|
||||
fil = fopen(temp, "wb");
|
||||
|
|
Loading…
Reference in a new issue