summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNiels Provos <provos@cvs.openbsd.org>2000-12-18 18:40:48 +0000
committerNiels Provos <provos@cvs.openbsd.org>2000-12-18 18:40:48 +0000
commita8b6aa5f5bccdf6c3cb36f5284aabe4c8ccad225 (patch)
treea6f20225f61aaf65faa0c31a946912ff9d9b7aaf
parentf971ed7d9f1d39c805153c1ea90b958daad408e5 (diff)
strlcat and strlcpy into libkern.
-rw-r--r--sys/lib/libkern/arch/alpha/Makefile.inc5
-rw-r--r--sys/lib/libkern/arch/arm32/Makefile.inc5
-rw-r--r--sys/lib/libkern/arch/hppa/Makefile.inc5
-rw-r--r--sys/lib/libkern/arch/i386/Makefile.inc5
-rw-r--r--sys/lib/libkern/arch/m68k/Makefile.inc5
-rw-r--r--sys/lib/libkern/arch/m88k/Makefile.inc4
-rw-r--r--sys/lib/libkern/arch/mips/Makefile.inc5
-rw-r--r--sys/lib/libkern/arch/ns32k/Makefile.inc5
-rw-r--r--sys/lib/libkern/arch/powerpc/Makefile.inc5
-rw-r--r--sys/lib/libkern/arch/sparc/Makefile.inc5
-rw-r--r--sys/lib/libkern/arch/vax/Makefile.inc4
-rw-r--r--sys/lib/libkern/libkern.h4
-rw-r--r--sys/lib/libkern/strlcat.c76
-rw-r--r--sys/lib/libkern/strlcpy.c72
14 files changed, 182 insertions, 23 deletions
diff --git a/sys/lib/libkern/arch/alpha/Makefile.inc b/sys/lib/libkern/arch/alpha/Makefile.inc
index d8ec9e586aa..af056c8c99f 100644
--- a/sys/lib/libkern/arch/alpha/Makefile.inc
+++ b/sys/lib/libkern/arch/alpha/Makefile.inc
@@ -1,9 +1,10 @@
-# $OpenBSD: Makefile.inc,v 1.10 2000/06/26 12:15:55 millert Exp $
+# $OpenBSD: Makefile.inc,v 1.11 2000/12/18 18:40:45 provos Exp $
# $NetBSD: Makefile.inc,v 1.9 1996/08/27 00:44:24 cgd Exp $
SRCS+= __main.c imax.c imin.c lmax.c lmin.c max.c min.c ulmax.c ulmin.c \
memchr.c memcmp.c memset.c \
- bcmp.c bzero.S ffs.S strcat.c strcmp.c strcpy.c strlen.c strncmp.c \
+ bcmp.c bzero.S ffs.S strcat.c strcmp.c strcpy.c strlcat.c strlcpy.c \
+ strlen.c strncmp.c \
strncpy.c scanc.c skpc.c htonl.S htons.S ntohl.S ntohs.S \
random.c strncasecmp.c
diff --git a/sys/lib/libkern/arch/arm32/Makefile.inc b/sys/lib/libkern/arch/arm32/Makefile.inc
index f07fb93aadf..74717b8cfdf 100644
--- a/sys/lib/libkern/arch/arm32/Makefile.inc
+++ b/sys/lib/libkern/arch/arm32/Makefile.inc
@@ -1,7 +1,8 @@
-# $OpenBSD: Makefile.inc,v 1.4 2000/06/16 19:56:54 millert Exp $
+# $OpenBSD: Makefile.inc,v 1.5 2000/12/18 18:40:45 provos Exp $
SRCS+= __main.c imax.c imin.c lmax.c lmin.c max.c min.c ulmax.c ulmin.c \
memchr.c memcmp.c \
- bcmp.c bzero.c ffs.c strcat.c strcmp.c strcpy.c strlen.c strncmp.c \
+ bcmp.c bzero.c ffs.c strcat.c strcmp.c strcpy.c strlcat.c strlcpy.c \
+ strlen.c strncmp.c \
strncpy.c scanc.c skpc.c locc.c htonl.c htons.c ntohl.c ntohs.c \
div.S random.c strncasecmp.c
diff --git a/sys/lib/libkern/arch/hppa/Makefile.inc b/sys/lib/libkern/arch/hppa/Makefile.inc
index a76622bfc8c..3eda096c7ae 100644
--- a/sys/lib/libkern/arch/hppa/Makefile.inc
+++ b/sys/lib/libkern/arch/hppa/Makefile.inc
@@ -1,8 +1,9 @@
-# $OpenBSD: Makefile.inc,v 1.12 2000/07/02 01:05:11 mickey Exp $
+# $OpenBSD: Makefile.inc,v 1.13 2000/12/18 18:40:45 provos Exp $
SRCS+= __main.c imax.c imin.c lmax.c lmin.c max.c min.c ulmax.c ulmin.c \
random.c ashrdi3.c divdi3.c strncpy.c strncmp.c strcmp.c memchr.c \
- memcmp.c memset.c strlen.c strcpy.c strcat.c skpc.c strncasecmp.c \
+ memcmp.c memset.c strlen.c strcpy.c strlcat.c strlcpy.c \
+ strcat.c skpc.c strncasecmp.c \
bcmp.c scanc.c ffs.c
SRCS+= milli.S
diff --git a/sys/lib/libkern/arch/i386/Makefile.inc b/sys/lib/libkern/arch/i386/Makefile.inc
index 54e09fde511..00928bb3c2c 100644
--- a/sys/lib/libkern/arch/i386/Makefile.inc
+++ b/sys/lib/libkern/arch/i386/Makefile.inc
@@ -1,8 +1,9 @@
-# $OpenBSD: Makefile.inc,v 1.6 2000/06/16 19:56:54 millert Exp $
+# $OpenBSD: Makefile.inc,v 1.7 2000/12/18 18:40:46 provos Exp $
# $NetBSD: Makefile.inc,v 1.10 1996/04/13 01:17:41 cgd Exp $
SRCS+= __main.c imax.c imin.c lmax.c lmin.c max.c min.c ulmax.c ulmin.c \
memchr.S memcmp.S \
- bcmp.S ffs.S memset.S strcat.S strcmp.S strcpy.S strlen.S strncmp.c \
+ bcmp.S ffs.S memset.S strcat.S strcmp.S strcpy.S strlcat.c strlcpy.c \
+ strlen.S strncmp.c \
strncpy.c scanc.S skpc.S locc.S htonl.S htons.S ntohl.S ntohs.S \
strncasecmp.c
diff --git a/sys/lib/libkern/arch/m68k/Makefile.inc b/sys/lib/libkern/arch/m68k/Makefile.inc
index 3f55124d332..41329201e3e 100644
--- a/sys/lib/libkern/arch/m68k/Makefile.inc
+++ b/sys/lib/libkern/arch/m68k/Makefile.inc
@@ -1,8 +1,9 @@
-# $OpenBSD: Makefile.inc,v 1.6 2000/06/16 19:56:54 millert Exp $
+# $OpenBSD: Makefile.inc,v 1.7 2000/12/18 18:40:46 provos Exp $
# $NetBSD: Makefile.inc,v 1.7 1996/04/18 01:53:04 cgd Exp $
SRCS+= __main.c imax.c imin.c lmax.c lmin.c max.c min.c ulmax.c ulmin.c \
memchr.c memcmp.S memset.S \
- bcmp.S bzero.S ffs.S strcat.S strcmp.S strcpy.S strlen.S strncmp.S \
+ bcmp.S bzero.S ffs.S strcat.S strcmp.S strcpy.S strlcat.c strlcpy.c \
+ strlen.S strncmp.S \
strncpy.S htonl.S htons.S ntohl.S ntohs.S scanc.S skpc.S locc.S \
strncasecmp.c
diff --git a/sys/lib/libkern/arch/m88k/Makefile.inc b/sys/lib/libkern/arch/m88k/Makefile.inc
index d60183ac96a..335d21f799e 100644
--- a/sys/lib/libkern/arch/m88k/Makefile.inc
+++ b/sys/lib/libkern/arch/m88k/Makefile.inc
@@ -1,7 +1,7 @@
-# $OpenBSD: Makefile.inc,v 1.3 2000/06/16 19:56:55 millert Exp $
+# $OpenBSD: Makefile.inc,v 1.4 2000/12/18 18:40:46 provos Exp $
# $NetBSD: Makefile.inc,v 1.2 1996/04/13 01:17:58 cgd Exp $
SRCS+= __main.c imax.c imin.c lmax.c lmin.c max.c min.c ulmax.c ulmin.c \
memchr.c memcmp.c bcmp.c random.c \
- strcat.c strcmp.c strcpy.c strlen.c strncmp.c \
+ strcat.c strcmp.c strcpy.c strlcat.c strlcpy.c strlen.c strncmp.c \
strncpy.c scanc.c skpc.c strncasecmp.c ffs.c
diff --git a/sys/lib/libkern/arch/mips/Makefile.inc b/sys/lib/libkern/arch/mips/Makefile.inc
index a3fe509803b..d3b951e07b5 100644
--- a/sys/lib/libkern/arch/mips/Makefile.inc
+++ b/sys/lib/libkern/arch/mips/Makefile.inc
@@ -1,11 +1,12 @@
-# $OpenBSD: Makefile.inc,v 1.8 2000/08/15 01:06:12 imp Exp $
+# $OpenBSD: Makefile.inc,v 1.9 2000/12/18 18:40:46 provos Exp $
# $NetBSD: Makefile.inc,v 1.4 1996/04/13 01:17:46 cgd Exp $
#
# There are likely more that we will notice when we go native
SRCS+= __main.c imax.c imin.c lmax.c lmin.c max.c min.c ulmax.c ulmin.c \
memchr.c memcmp.c memset.c strcmp.c \
- bcmp.S bcopy.S bzero.S strcat.c strcmp.c strcpy.c ffs.S htonl.S \
+ bcmp.S bcopy.S bzero.S strcat.c strcmp.c strcpy.c strlcat.c strlcpy.c \
+ ffs.S htonl.S \
htons.S strcmp.S strlen.S strncmp.c random.c scanc.c skpc.c strncpy.c \
strncasecmp.c
diff --git a/sys/lib/libkern/arch/ns32k/Makefile.inc b/sys/lib/libkern/arch/ns32k/Makefile.inc
index 04849294d70..e4617579b19 100644
--- a/sys/lib/libkern/arch/ns32k/Makefile.inc
+++ b/sys/lib/libkern/arch/ns32k/Makefile.inc
@@ -1,8 +1,9 @@
-# $OpenBSD: Makefile.inc,v 1.5 2000/06/16 19:56:55 millert Exp $
+# $OpenBSD: Makefile.inc,v 1.6 2000/12/18 18:40:46 provos Exp $
# $NetBSD: Makefile.inc,v 1.7 1996/04/13 01:17:50 cgd Exp $
SRCS+= __main.c imax.c imin.c lmax.c lmin.c max.c min.c ulmax.c ulmin.c \
memchr.S memcmp.c \
- bcmp.c ffs.c strcat.c strcmp.c strcpy.c strlen.c strncmp.c strncpy.c \
+ bcmp.c ffs.c strcat.c strcmp.c strcpy.c strlcat.c strlcpy.c \
+ strlen.c strncmp.c strncpy.c \
scanc.c skpc.c locc.c strncasecmp.c \
htonl.S htons.S ntohl.S ntohs.S
diff --git a/sys/lib/libkern/arch/powerpc/Makefile.inc b/sys/lib/libkern/arch/powerpc/Makefile.inc
index f41665d1850..905dfad0f05 100644
--- a/sys/lib/libkern/arch/powerpc/Makefile.inc
+++ b/sys/lib/libkern/arch/powerpc/Makefile.inc
@@ -1,4 +1,4 @@
-# $OpenBSD: Makefile.inc,v 1.6 2000/06/16 19:56:55 millert Exp $
+# $OpenBSD: Makefile.inc,v 1.7 2000/12/18 18:40:47 provos Exp $
# $NetBSD: Makefile.inc,v 1.6 1994/10/26 06:39:03 cgd Exp $
CFLAGS += -D_KERNEL
@@ -6,7 +6,8 @@ CFLAGS += -D_KERNEL
SRCS+= __main.c __eabi.c \
imax.c imin.c lmax.c lmin.c max.c min.c ulmax.c ulmin.c \
memchr.c memcmp.c memset.c \
- bcmp.c bzero.c ffs.c strcat.c strcmp.c strcpy.c strlen.c strncmp.c \
+ bcmp.c bzero.c ffs.c strcat.c strcmp.c strcpy.c strlcat.c strlcpy.c \
+ strlen.c strncmp.c \
strncpy.c scanc.c skpc.c locc.c htonl.c htons.c ntohl.c ntohs.c \
memcpy.c random.c strncasecmp.c
# bcopy.c htolel.c letohl.c htoles.c letohs.c copystr.c \
diff --git a/sys/lib/libkern/arch/sparc/Makefile.inc b/sys/lib/libkern/arch/sparc/Makefile.inc
index 6aabd416334..5394131cefb 100644
--- a/sys/lib/libkern/arch/sparc/Makefile.inc
+++ b/sys/lib/libkern/arch/sparc/Makefile.inc
@@ -1,9 +1,10 @@
-# $OpenBSD: Makefile.inc,v 1.8 2000/06/16 19:56:55 millert Exp $
+# $OpenBSD: Makefile.inc,v 1.9 2000/12/18 18:40:47 provos Exp $
# $NetBSD: Makefile.inc,v 1.12 1996/04/23 23:05:22 christos Exp $
SRCS+= __main.c imax.c imin.c lmax.c lmin.c max.c min.c ulmax.c ulmin.c \
memchr.c memcmp.c memset.c \
- bcmp.c bzero.S strcat.c strcmp.c strcpy.c strlen.S strncmp.c \
+ bcmp.c bzero.S strcat.c strcmp.c strcpy.c strlcat.c strlcpy.c \
+ strlen.S strncmp.c \
strncpy.c htonl.S htons.S ntohl.S ntohs.S scanc.c skpc.c \
strncasecmp.c
diff --git a/sys/lib/libkern/arch/vax/Makefile.inc b/sys/lib/libkern/arch/vax/Makefile.inc
index 1aa7fdb673c..6ac2e2c903c 100644
--- a/sys/lib/libkern/arch/vax/Makefile.inc
+++ b/sys/lib/libkern/arch/vax/Makefile.inc
@@ -1,7 +1,7 @@
-# $OpenBSD: Makefile.inc,v 1.5 2000/06/16 19:56:56 millert Exp $
+# $OpenBSD: Makefile.inc,v 1.6 2000/12/18 18:40:47 provos Exp $
# $NetBSD: Makefile.inc,v 1.2 1996/04/13 01:17:58 cgd Exp $
SRCS+= __main.c imax.c imin.c lmax.c lmin.c max.c min.c ulmax.c ulmin.c \
memchr.c memcmp.c \
- strcat.c strcmp.c strcpy.c strlen.c strncmp.c \
+ strcat.c strcmp.c strcpy.c strlcat.c strlcpy.c strlen.c strncmp.c \
strncpy.c scanc.c skpc.c strncasecmp.c
diff --git a/sys/lib/libkern/libkern.h b/sys/lib/libkern/libkern.h
index fa21bee7c37..b6b147b9dc5 100644
--- a/sys/lib/libkern/libkern.h
+++ b/sys/lib/libkern/libkern.h
@@ -1,4 +1,4 @@
-/* $OpenBSD: libkern.h,v 1.15 2000/06/16 20:20:30 millert Exp $ */
+/* $OpenBSD: libkern.h,v 1.16 2000/12/18 18:40:44 provos Exp $ */
/* $NetBSD: libkern.h,v 1.7 1996/03/14 18:52:08 christos Exp $ */
/*-
@@ -167,6 +167,8 @@ size_t strlen __P((const char *));
char *strcat __P((char *, const char *));
char *strcpy __P((char *, const char *));
char *strncpy __P((char *, const char *, size_t));
+size_t strlcpy __P((char *, const char *, size_t));
+size_t strlcat __P((char *, const char *, size_t));
int strcmp __P((const char *, const char *));
int strncmp __P((const char *, const char *, size_t));
int strncasecmp __P((const char *, const char *, size_t));
diff --git a/sys/lib/libkern/strlcat.c b/sys/lib/libkern/strlcat.c
new file mode 100644
index 00000000000..a634c5d571d
--- /dev/null
+++ b/sys/lib/libkern/strlcat.c
@@ -0,0 +1,76 @@
+/* $OpenBSD: strlcat.c,v 1.1 2000/12/18 18:40:44 provos Exp $ */
+
+/*
+ * Copyright (c) 1998 Todd C. Miller <Todd.Miller@courtesan.com>
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. The name of the author may not be used to endorse or promote products
+ * derived from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
+ * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
+ * AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
+ * THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+ * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+ * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
+ * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
+ * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
+ * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
+ * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#if defined(LIBC_SCCS) && !defined(lint)
+static char *rcsid = "$OpenBSD: strlcat.c,v 1.1 2000/12/18 18:40:44 provos Exp $";
+#endif /* LIBC_SCCS and not lint */
+
+#if !defined(_KERNEL) && !defined(_STANDALONE)
+#include <sys/types.h>
+#include <string.h>
+#else
+#include <lib/libkern/libkern.h>
+#endif
+
+/*
+ * 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 == 0).
+ * Returns strlen(initial dst) + strlen(src); if retval >= siz,
+ * truncation occurred.
+ */
+size_t strlcat(dst, src, siz)
+ char *dst;
+ const char *src;
+ size_t siz;
+{
+ register char *d = dst;
+ register const char *s = src;
+ register size_t n = siz;
+ size_t dlen;
+
+ /* Find the end of dst and adjust bytes left but don't go past end */
+ while (*d != '\0' && n-- != 0)
+ d++;
+ dlen = d - dst;
+ n = siz - 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 */
+}
diff --git a/sys/lib/libkern/strlcpy.c b/sys/lib/libkern/strlcpy.c
new file mode 100644
index 00000000000..598220c7c98
--- /dev/null
+++ b/sys/lib/libkern/strlcpy.c
@@ -0,0 +1,72 @@
+/* $OpenBSD: strlcpy.c,v 1.1 2000/12/18 18:40:45 provos Exp $ */
+
+/*
+ * Copyright (c) 1998 Todd C. Miller <Todd.Miller@courtesan.com>
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. The name of the author may not be used to endorse or promote products
+ * derived from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
+ * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
+ * AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
+ * THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+ * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+ * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
+ * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
+ * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
+ * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
+ * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#if defined(LIBC_SCCS) && !defined(lint)
+static char *rcsid = "$OpenBSD: strlcpy.c,v 1.1 2000/12/18 18:40:45 provos Exp $";
+#endif /* LIBC_SCCS and not lint */
+
+#if !defined(_KERNEL) && !defined(_STANDALONE)
+#include <sys/types.h>
+#include <string.h>
+#else
+#include <lib/libkern/libkern.h>
+#endif
+
+/*
+ * 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(dst, src, siz)
+ char *dst;
+ const char *src;
+ size_t siz;
+{
+ register char *d = dst;
+ register const char *s = src;
+ register size_t n = siz;
+
+ /* 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 (siz != 0)
+ *d = '\0'; /* NUL-terminate dst */
+ while (*s++)
+ ;
+ }
+
+ return(s - src - 1); /* count does not include NUL */
+}