summaryrefslogtreecommitdiff
path: root/usr.sbin/bind/lib
diff options
context:
space:
mode:
authorJakob Schlyter <jakob@cvs.openbsd.org>2003-04-10 05:55:25 +0000
committerJakob Schlyter <jakob@cvs.openbsd.org>2003-04-10 05:55:25 +0000
commitb1f85f5a56647c81d74f9e4ea0a3797f387c7355 (patch)
tree94f3db2532abe1c57afbe54a1979334cb8196931 /usr.sbin/bind/lib
parente8841630cf27b9e74e3e4bf8b33fa5538f1eff28 (diff)
provide strlcat() and strlcpy() for platform without them. although
this is not needed in OpenBSD, we'll keep the code here to stay in sync. license change for strlcat/strlcpy ok millert@.
Diffstat (limited to 'usr.sbin/bind/lib')
-rw-r--r--usr.sbin/bind/lib/isc/include/isc/platform.h.in10
-rw-r--r--usr.sbin/bind/lib/isc/include/isc/string.h16
-rw-r--r--usr.sbin/bind/lib/isc/string.c54
3 files changed, 80 insertions, 0 deletions
diff --git a/usr.sbin/bind/lib/isc/include/isc/platform.h.in b/usr.sbin/bind/lib/isc/include/isc/platform.h.in
index 065a35a5531..40e430991f4 100644
--- a/usr.sbin/bind/lib/isc/include/isc/platform.h.in
+++ b/usr.sbin/bind/lib/isc/include/isc/platform.h.in
@@ -102,6 +102,16 @@
@ISC_PLATFORM_NEEDSTRSEP@
/*
+ * If the system needs strlcpy(), ISC_PLATFORM_NEEDSTRLCPY will be defined.
+ */
+@ISC_PLATFORM_NEEDSTRLCPY@
+
+/*
+ * If the system needs strlcat(), ISC_PLATFORM_NEEDSTRLCAT will be defined.
+ */
+@ISC_PLATFORM_NEEDSTRLCAT@
+
+/*
* Define either ISC_PLATFORM_BSD44MSGHDR or ISC_PLATFORM_BSD43MSGHDR.
*/
@ISC_PLATFORM_MSGHDRFLAVOR@
diff --git a/usr.sbin/bind/lib/isc/include/isc/string.h b/usr.sbin/bind/lib/isc/include/isc/string.h
index 9b578fd91f2..bef1a17c6d7 100644
--- a/usr.sbin/bind/lib/isc/include/isc/string.h
+++ b/usr.sbin/bind/lib/isc/include/isc/string.h
@@ -51,6 +51,22 @@ isc_string_separate(char **stringp, const char *delim);
#define strsep isc_string_separate
#endif
+size_t
+isc_string_strlcpy(char *dst, const char *src, size_t size);
+
+
+#ifdef ISC_PLATFORM_NEEDSTRLCPY
+#define strlcpy isc_string_strlcpy
+#endif
+
+
+size_t
+isc_string_strlcat(char *dst, const char *src, size_t size);
+
+#ifdef ISC_PLATFORM_NEEDSTRLCAT
+#define strlcat isc_string_strlcat
+#endif
+
ISC_LANG_ENDDECLS
#endif /* ISC_STRING_H */
diff --git a/usr.sbin/bind/lib/isc/string.c b/usr.sbin/bind/lib/isc/string.c
index 5222142e536..50a4680fd15 100644
--- a/usr.sbin/bind/lib/isc/string.c
+++ b/usr.sbin/bind/lib/isc/string.c
@@ -109,3 +109,57 @@ isc_string_separate(char **stringp, const char *delim) {
*stringp = NULL;
return (string);
}
+
+size_t
+strlcpy(char *dst, const char *src, size_t size)
+{
+ char *d = dst;
+ const char *s = src;
+ size_t n = size;
+
+ /* Copy as many bytes as will fit */
+ if (n != 0 && --n != 0) {
+ do {
+ if ((*d++ = *s++) == 0)
+ break;
+ } while (--n != 0);
+ }
+
+ /* Not enough room in dst, add NUL and traverse rest of src */
+ if (n == 0) {
+ if (size != 0)
+ *d = '\0'; /* NUL-terminate dst */
+ while (*s++)
+ ;
+ }
+
+ return(s - src - 1); /* count does not include NUL */
+}
+
+size_t
+strlcat(char *dst, const char *src, size_t size)
+{
+ char *d = dst;
+ const char *s = src;
+ size_t n = size;
+ size_t dlen;
+
+ /* Find the end of dst and adjust bytes left but don't go past end */
+ while (n-- != 0 && *d != '\0')
+ d++;
+ dlen = d - dst;
+ n = size - dlen;
+
+ if (n == 0)
+ return(dlen + strlen(s));
+ while (*s != '\0') {
+ if (n != 1) {
+ *d++ = *s;
+ n--;
+ }
+ s++;
+ }
+ *d = '\0';
+
+ return(dlen + (s - src)); /* count does not include NUL */
+}