summaryrefslogtreecommitdiff
path: root/source3/lib/replace.c
diff options
context:
space:
mode:
authorAndrew Tridgell <tridge@samba.org>2001-11-20 08:50:57 +0000
committerAndrew Tridgell <tridge@samba.org>2001-11-20 08:50:57 +0000
commit3db4421eba3269d0d5c31daddeded4f208a60095 (patch)
tree425bf813b26a3c677b4055f9365d518143d5f330 /source3/lib/replace.c
parentc32526441668d75a8acf452e55559f00d5b87ba2 (diff)
downloadsamba-3db4421eba3269d0d5c31daddeded4f208a60095.tar.gz
samba-3db4421eba3269d0d5c31daddeded4f208a60095.tar.bz2
samba-3db4421eba3269d0d5c31daddeded4f208a60095.zip
added strlcpy() and strlcat()
(This used to be commit 233fe71fbbb98fe1563f69565e16da1856360a26)
Diffstat (limited to 'source3/lib/replace.c')
-rw-r--r--source3/lib/replace.c36
1 files changed, 36 insertions, 0 deletions
diff --git a/source3/lib/replace.c b/source3/lib/replace.c
index 4dbcedc93a..54ad36e139 100644
--- a/source3/lib/replace.c
+++ b/source3/lib/replace.c
@@ -41,6 +41,42 @@ ftruncate for operating systems that don't have it
#endif /* HAVE_FTRUNCATE */
+#ifndef HAVE_STRLCPY
+/* like strncpy but does not 0 fill the buffer and always null
+ terminates. bufsize is the size of the destination buffer */
+ size_t strlcpy(char *d, const char *s, size_t bufsize)
+{
+ size_t len = strlen(s);
+ size_t ret = len;
+ if (bufsize <= 0) return 0;
+ if (len >= bufsize) len = bufsize-1;
+ memcpy(d, s, len);
+ d[len] = 0;
+ return ret;
+}
+#endif
+
+#ifndef HAVE_STRLCAT
+/* like strncat but does not 0 fill the buffer and always null
+ terminates. bufsize is the length of the buffer, which should
+ be one more than the maximum resulting string length */
+ size_t strlcat(char *d, const char *s, size_t bufsize)
+{
+ size_t len1 = strlen(d);
+ size_t len2 = strlen(s);
+ size_t ret = len1 + len2;
+
+ if (len1+len2 >= bufsize) {
+ len2 = bufsize - (len1+1);
+ }
+ if (len2 > 0) {
+ memcpy(d+len1, s, len2);
+ d[len1+len2] = 0;
+ }
+ return ret;
+}
+#endif
+
#ifndef HAVE_MKTIME
/*******************************************************************
a mktime() replacement for those who don't have it - contributed by