diff options
author | Simon Howard | 2014-03-29 20:08:31 -0400 |
---|---|---|
committer | Simon Howard | 2014-03-29 20:08:31 -0400 |
commit | 62b5c602821cee8ac703ebe6362f3e1fc6d9ad3c (patch) | |
tree | 3703b069d3d200e8c6edac3c99de00da34cbc7f3 /src/d_iwad.c | |
parent | e85edb9e6fcdc77d69d1b4d9f14f705a03e753e1 (diff) | |
download | chocolate-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/d_iwad.c')
-rw-r--r-- | src/d_iwad.c | 9 |
1 files changed, 4 insertions, 5 deletions
diff --git a/src/d_iwad.c b/src/d_iwad.c index f4155349..293553a2 100644 --- a/src/d_iwad.c +++ b/src/d_iwad.c @@ -423,7 +423,7 @@ static char *CheckDirectoryHasIWAD(char *dir, char *iwadname) // As a special case, the "directory" may refer directly to an // IWAD file if the path comes from DOOMWADDIR or DOOMWADPATH. - + if (DirIsFile(dir, iwadname) && M_FileExists(dir)) { return strdup(dir); @@ -432,15 +432,14 @@ static char *CheckDirectoryHasIWAD(char *dir, char *iwadname) // Construct the full path to the IWAD if it is located in // this directory, and check if it exists. - filename = malloc(strlen(dir) + strlen(iwadname) + 3); - if (!strcmp(dir, ".")) { - strcpy(filename, iwadname); + filename = strdup(iwadname); } else { - sprintf(filename, "%s%c%s", dir, DIR_SEPARATOR, iwadname); + char sep[] = {DIR_SEPARATOR, '\0'}; + filename = M_StringJoin(dir, sep, iwadname); } if (M_FileExists(filename)) |