]> de.git.xonotic.org Git - xonotic/darkplaces.git/blobdiff - common.h
Added strlcat and strlcpy, from OpenBSD. They are smart replacements for strncat...
[xonotic/darkplaces.git] / common.h
index dad626ca71ebf8e339cf7274d0bcbfb99297fe54..5e3a0bd0884e4d374e2c409b22eef30aff9c5307 100644 (file)
--- a/common.h
+++ b/common.h
@@ -193,5 +193,28 @@ void freedirectory(stringlist_t *list);
 
 char *SearchInfostring(const char *infostring, const char *key);
 
+
+// strlcat and strlcpy, from OpenBSD
+// Most (all?) BSDs already have them
+#if !defined(__OpenBSD__) && !defined(__NetBSD__) && !defined(__FreeBSD__)
+
+/*
+ * Appends src to string dst of size siz (unlike strncat, siz is the
+ * full size of dst, not space left).  At most siz-1 characters
+ * will be copied.  Always NUL terminates (unless siz <= strlen(dst)).
+ * Returns strlen(src) + MIN(siz, strlen(initial dst)).
+ * If retval >= siz, truncation occurred.
+ */
+size_t strlcat(char *dst, const char *src, size_t siz);
+
+/*
+ * Copy src to string dst of size siz.  At most siz-1 characters
+ * will be copied.  Always NUL terminates (unless siz == 0).
+ * Returns strlen(src); if retval >= siz, truncation occurred.
+ */
+size_t strlcpy(char *dst, const char *src, size_t siz);
+
+#endif  // #if !defined(__OpenBSD__) && !defined(__NetBSD__) && !defined(__FreeBSD__)
+
 #endif