summaryrefslogtreecommitdiff
path: root/src/doom/d_main.c
diff options
context:
space:
mode:
authorSimon Howard2014-03-29 20:08:31 -0400
committerSimon Howard2014-03-29 20:08:31 -0400
commit62b5c602821cee8ac703ebe6362f3e1fc6d9ad3c (patch)
tree3703b069d3d200e8c6edac3c99de00da34cbc7f3 /src/doom/d_main.c
parente85edb9e6fcdc77d69d1b4d9f14f705a03e753e1 (diff)
downloadchocolate-doom-62b5c602821cee8ac703ebe6362f3e1fc6d9ad3c.tar.gz
chocolate-doom-62b5c602821cee8ac703ebe6362f3e1fc6d9ad3c.tar.bz2
chocolate-doom-62b5c602821cee8ac703ebe6362f3e1fc6d9ad3c.zip
misc: Add string utility functions.
It's more readable to write "M_StringEndsWith(..." than doing a bunch of pointer arithmetic, and this is a common pattern. Also add M_StringStartsWith, M_StringJoin and M_StringCopy. The latter is a safe alternative for strcpy() that works the same as OpenBSD's strlcpy(). Use these functions in a few places where it makes sense.
Diffstat (limited to 'src/doom/d_main.c')
-rw-r--r--src/doom/d_main.c20
1 files changed, 9 insertions, 11 deletions
diff --git a/src/doom/d_main.c b/src/doom/d_main.c
index e6b993c4..fa84bc3b 100644
--- a/src/doom/d_main.c
+++ b/src/doom/d_main.c
@@ -1352,19 +1352,19 @@ void D_DoomMain (void)
if (p)
{
- if (!strcasecmp(myargv[p+1] + strlen(myargv[p+1]) - 4, ".lmp"))
+ if (M_StringEndsWith(myargv[p + 1], ".lmp"))
{
- strcpy(file, myargv[p + 1]);
+ M_StringCopy(file, myargv[p + 1], sizeof(file));
}
else
{
- sprintf (file,"%s.lmp", myargv[p+1]);
+ snprintf(file, sizeof(file), "%s.lmp", myargv[p+1]);
}
- if (D_AddFile (file))
+ if (D_AddFile(file))
{
- strncpy(demolumpname, lumpinfo[numlumps - 1].name, 8);
- demolumpname[8] = '\0';
+ M_StringCopy(demolumpname, lumpinfo[numlumps - 1].name,
+ sizeof(demolumpname));
printf("Playing demo %s.\n", file);
}
@@ -1374,10 +1374,8 @@ void D_DoomMain (void)
// the demo in the same way as Vanilla Doom. This makes
// tricks like "-playdemo demo1" possible.
- strncpy(demolumpname, myargv[p + 1], 8);
- demolumpname[8] = '\0';
+ M_StringCopy(demolumpname, myargv[p + 1], sizeof(demolumpname));
}
-
}
I_AtExit((atexit_func_t) G_CheckDemoStatus, true);
@@ -1686,8 +1684,8 @@ void D_DoomMain (void)
if (startloadgame >= 0)
{
- strcpy(file, P_SaveGameFile(startloadgame));
- G_LoadGame (file);
+ M_StringCopy(file, P_SaveGameFile(startloadgame), sizeof(file));
+ G_LoadGame(file);
}
if (gameaction != ga_loadgame )