summaryrefslogtreecommitdiffstats
path: root/sys/lib
diff options
context:
space:
mode:
authorderaadt <deraadt@openbsd.org>2019-04-20 22:59:03 +0000
committerderaadt <deraadt@openbsd.org>2019-04-20 22:59:03 +0000
commit7a2189da75c696c4404ba58cd970151833ffe027 (patch)
tree8ed98a3e248346d83f1e2aed4bcb9035ef714558 /sys/lib
parentarmv7 RAMDISK is now compiled with -Oz (just to be like other ramdisks), (diff)
downloadwireguard-openbsd-7a2189da75c696c4404ba58cd970151833ffe027.tar.xz
wireguard-openbsd-7a2189da75c696c4404ba58cd970151833ffe027.zip
libsa's memcpy() is actually memmove(). make a proper memmove(), and give
memcpy() correct behaviour. This also brings the bcopy() macro into line.
Diffstat (limited to 'sys/lib')
-rw-r--r--sys/lib/libsa/Makefile4
-rw-r--r--sys/lib/libsa/memcpy.c12
-rw-r--r--sys/lib/libsa/memmove.c55
-rw-r--r--sys/lib/libsa/stand.h5
4 files changed, 63 insertions, 13 deletions
diff --git a/sys/lib/libsa/Makefile b/sys/lib/libsa/Makefile
index 5e722d49328..a4b9fdcf26b 100644
--- a/sys/lib/libsa/Makefile
+++ b/sys/lib/libsa/Makefile
@@ -1,4 +1,4 @@
-# $OpenBSD: Makefile,v 1.28 2015/11/16 19:33:52 miod Exp $
+# $OpenBSD: Makefile,v 1.29 2019/04/20 22:59:04 deraadt Exp $
# $NetBSD: Makefile,v 1.13 1996/10/02 16:19:51 ws Exp $
LIB= sa
@@ -24,7 +24,7 @@ CPPFLAGS+= -D__INTERNAL_LIBSA_CREAD
.endif
# stand routines
-SRCS+= alloc.c memcpy.c exit.c getfile.c getchar.c getln.c globals.c \
+SRCS+= alloc.c memcpy.c memmove.c exit.c getfile.c getchar.c getln.c globals.c \
printf.c putchar.c snprintf.c strerror.c strcmp.c memset.c memcmp.c \
strncpy.c strncmp.c strchr.c
diff --git a/sys/lib/libsa/memcpy.c b/sys/lib/libsa/memcpy.c
index 15425355490..65e95d66cef 100644
--- a/sys/lib/libsa/memcpy.c
+++ b/sys/lib/libsa/memcpy.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: memcpy.c,v 1.5 2003/08/08 03:36:07 deraadt Exp $ */
+/* $OpenBSD: memcpy.c,v 1.6 2019/04/20 22:59:04 deraadt Exp $ */
/* $NetBSD: bcopy.c,v 1.5 1995/04/22 13:46:50 cgd Exp $ */
/*-
@@ -44,13 +44,7 @@ memcpy(void *s1, const void *s2, size_t n)
const char *f = s2;
char *t = s1;
- if (f < t) {
- f += n;
- t += n;
- while (n-- > 0)
- *--t = *--f;
- } else
- while (n-- > 0)
- *t++ = *f++;
+ while (n-- > 0)
+ *t++ = *f++;
return s1;
}
diff --git a/sys/lib/libsa/memmove.c b/sys/lib/libsa/memmove.c
new file mode 100644
index 00000000000..6c1d6273895
--- /dev/null
+++ b/sys/lib/libsa/memmove.c
@@ -0,0 +1,55 @@
+/* $OpenBSD: memmove.c,v 1.1 2019/04/20 22:59:04 deraadt Exp $ */
+
+/*-
+ * Copyright (c) 1993
+ * The Regents of the University of California. 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. Neither the name of the University nor the names of its contributors
+ * may be used to endorse or promote products derived from this software
+ * without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``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 REGENTS OR CONTRIBUTORS 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.
+ */
+
+#include <sys/types.h>
+#include <sys/systm.h>
+
+#undef memmove
+
+/*
+ * This is designed to be small, not fast.
+ */
+void *
+memmove(void *s1, const void *s2, size_t n)
+{
+ const char *f = s2;
+ char *t = s1;
+
+ if (f < t) {
+ f += n;
+ t += n;
+ while (n-- > 0)
+ *--t = *--f;
+ } else
+ while (n-- > 0)
+ *t++ = *f++;
+ return s1;
+}
diff --git a/sys/lib/libsa/stand.h b/sys/lib/libsa/stand.h
index f8147ecad8f..5e78f153770 100644
--- a/sys/lib/libsa/stand.h
+++ b/sys/lib/libsa/stand.h
@@ -1,4 +1,4 @@
-/* $OpenBSD: stand.h,v 1.65 2017/10/08 00:57:19 guenther Exp $ */
+/* $OpenBSD: stand.h,v 1.66 2019/04/20 22:59:04 deraadt Exp $ */
/* $NetBSD: stand.h,v 1.18 1996/11/30 04:35:51 gwr Exp $ */
/*-
@@ -143,9 +143,10 @@ __dead void panic(const char *, ...) __attribute__((noreturn));
__dead void _rtt(void) __attribute__((noreturn));
#define bzero(s,n) ((void)memset((s),0,(n)))
#define bcmp(s1,s2,n) (memcmp((s2),(s1),(n)))
-#define bcopy(s1,s2,n) ((void)memcpy((s2),(s1),(n)))
+#define bcopy(s1,s2,n) ((void)memmove((s2),(s1),(n)))
void explicit_bzero(void *, size_t);
void *memcpy(void *, const void *, size_t);
+void *memmove(void *, const void *, size_t);
int memcmp(const void *, const void *, size_t);
char *strncpy(char *, const char *, size_t);
int strncmp(const char *, const char *, size_t);