summaryrefslogtreecommitdiff
path: root/ttd.c
diff options
context:
space:
mode:
authortron <tron@openttd.org>2005-01-23 15:16:47 +0000
committertron <tron@openttd.org>2005-01-23 15:16:47 +0000
commit53d1c3f117142dd3ecae23c5fcdc069f393f1703 (patch)
tree60b41a28cf18bba61bcff993ba254ea2000a083c /ttd.c
parent9a96f5b64e08ec6c8043e4e389f172e8bf5c460d (diff)
downloadopenttd-53d1c3f117142dd3ecae23c5fcdc069f393f1703.tar.xz
(svn r1616) Introduce ttd_strlcat() and use it to de-uglify some piece of code in misc_cmd.
While here rename the len parameter of ttd_strlcpy() to size, because it is a buffer size and not a string length. Also add -Wwrite-strings to the Makefile, because the above mentioned piece of code was the only part which triggered this warning.
Diffstat (limited to 'ttd.c')
-rw-r--r--ttd.c18
1 files changed, 13 insertions, 5 deletions
diff --git a/ttd.c b/ttd.c
index 68b423d1d..70e8e6722 100644
--- a/ttd.c
+++ b/ttd.c
@@ -203,12 +203,20 @@ static const DriverDesc *ChooseDefaultDriver(const DriverDesc *dd)
return best;
}
-void ttd_strlcpy(char *dst, const char *src, size_t len)
+void ttd_strlcpy(char *dst, const char *src, size_t size)
{
- assert(len > 0);
- while (--len && *src)
- *dst++=*src++;
- *dst = 0;
+ assert(size > 0);
+ while (--size > 0 && *src != '\0') *dst++ = *src++;
+ *dst = '\0';
+}
+
+void ttd_strlcat(char *dst, const char *src, size_t size)
+{
+ assert(size > 0);
+ for (; size > 0 && *dst != '\0'; --size, ++dst) {}
+ assert(size > 0);
+ while (--size > 0 && *src != '\0') *dst++ = *src++;
+ *dst = '\0';
}
static char *strecpy(char *dst, const char *src)