diff options
author | Simon Howard | 2014-03-29 21:38:11 -0400 |
---|---|---|
committer | Simon Howard | 2014-03-29 21:38:11 -0400 |
commit | 1e5e0a565cbcaf4f8aafa5a12c84e987aa822e13 (patch) | |
tree | c8e3345077d254cd42d7483e4762fd129b765a37 | |
parent | 2e6e43c4a706e3670f131c7b2d5a5525f9bf0d7b (diff) | |
download | chocolate-doom-1e5e0a565cbcaf4f8aafa5a12c84e987aa822e13.tar.gz chocolate-doom-1e5e0a565cbcaf4f8aafa5a12c84e987aa822e13.tar.bz2 chocolate-doom-1e5e0a565cbcaf4f8aafa5a12c84e987aa822e13.zip |
misc: Make arguments to string functions const.
Where a pointer is to a buffer that does not need to be mutable for
the operation of the function, use const char * instead. This avoids
some type errors where constant string are passed.
-rw-r--r-- | src/hexen/r_data.c | 1 | ||||
-rw-r--r-- | src/m_misc.c | 24 | ||||
-rw-r--r-- | src/m_misc.h | 13 |
3 files changed, 21 insertions, 17 deletions
diff --git a/src/hexen/r_data.c b/src/hexen/r_data.c index 903eb316..da1244e2 100644 --- a/src/hexen/r_data.c +++ b/src/hexen/r_data.c @@ -26,6 +26,7 @@ #include "h2def.h" #include "i_system.h" #include "i_swap.h" +#include "m_misc.h" #include "r_local.h" #include "p_local.h" diff --git a/src/m_misc.c b/src/m_misc.c index 02031213..d48a82e5 100644 --- a/src/m_misc.c +++ b/src/m_misc.c @@ -300,10 +300,11 @@ char *M_StrCaseStr(char *haystack, char *needle) // String replace function. // -char *M_StringReplace(char *haystack, char *needle, char *replacement) +char *M_StringReplace(const char *haystack, const char *needle, + const char *replacement) { - char *result, *p; - char *dst; + char *result, *dst; + const char *p; size_t needle_len = strlen(needle); size_t result_len, dst_len; @@ -359,7 +360,7 @@ char *M_StringReplace(char *haystack, char *needle, char *replacement) // Safe string copy function that works like OpenBSD's strlcpy(). // Returns true if the string was not truncated. -boolean M_StringCopy(char *dest, char *src, size_t dest_size) +boolean M_StringCopy(char *dest, const char *src, size_t dest_size) { strncpy(dest, src, dest_size); dest[dest_size - 1] = '\0'; @@ -369,7 +370,7 @@ boolean M_StringCopy(char *dest, char *src, size_t dest_size) // Safe string concat function that works like OpenBSD's strlcat(). // Returns true if string not truncated. -boolean M_StringConcat(char *dest, char *src, size_t dest_size) +boolean M_StringConcat(char *dest, const char *src, size_t dest_size) { size_t offset; @@ -387,7 +388,7 @@ boolean M_StringConcat(char *dest, char *src, size_t dest_size) // Returns true if 's' begins with the specified prefix. -boolean M_StringStartsWith(char *s, char *prefix) +boolean M_StringStartsWith(const char *s, const char *prefix) { return strlen(s) > strlen(prefix) && strncmp(s, prefix, strlen(prefix)) == 0; @@ -395,7 +396,7 @@ boolean M_StringStartsWith(char *s, char *prefix) // Returns true if 's' ends with the specified suffix. -boolean M_StringEndsWith(char *s, char *suffix) +boolean M_StringEndsWith(const char *s, const char *suffix) { return strlen(s) >= strlen(suffix) && strcmp(s + strlen(s) - strlen(suffix), suffix) == 0; @@ -404,9 +405,10 @@ boolean M_StringEndsWith(char *s, char *suffix) // Return a newly-malloced string with all the strings given as arguments // concatenated together. -char *M_StringJoin(char *s, ...) +char *M_StringJoin(const char *s, ...) { - char *result, *v; + char *result; + const char *v; va_list args; size_t result_len; @@ -415,7 +417,7 @@ char *M_StringJoin(char *s, ...) va_start(args, s); for (;;) { - v = va_arg(args, char *); + v = va_arg(args, const char *); if (v == NULL) { break; @@ -438,7 +440,7 @@ char *M_StringJoin(char *s, ...) va_start(args, s); for (;;) { - v = va_arg(args, char *); + v = va_arg(args, const char *); if (v == NULL) { break; diff --git a/src/m_misc.h b/src/m_misc.h index 66035b5b..cb3dc8f6 100644 --- a/src/m_misc.h +++ b/src/m_misc.h @@ -43,12 +43,13 @@ boolean M_StrToInt(const char *str, int *result); void M_ExtractFileBase(char *path, char *dest); void M_ForceUppercase(char *text); char *M_StrCaseStr(char *haystack, char *needle); -boolean M_StringCopy(char *dest, char *src, size_t dest_size); -boolean M_StringConcat(char *dest, char *src, size_t dest_size); -char *M_StringReplace(char *haystack, char *needle, char *replacement); -char *M_StringJoin(char *s, ...); -boolean M_StringStartsWith(char *s, char *prefix); -boolean M_StringEndsWith(char *s, char *suffix); +boolean M_StringCopy(char *dest, const char *src, size_t dest_size); +boolean M_StringConcat(char *dest, const char *src, size_t dest_size); +char *M_StringReplace(const char *haystack, const char *needle, + const char *replacement); +char *M_StringJoin(const char *s, ...); +boolean M_StringStartsWith(const char *s, const char *prefix); +boolean M_StringEndsWith(const char *s, const char *suffix); char *M_OEMToUTF8(const char *ansi); #endif |