summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorTodd C. Miller <millert@cvs.openbsd.org>1999-04-25 00:10:08 +0000
committerTodd C. Miller <millert@cvs.openbsd.org>1999-04-25 00:10:08 +0000
commitc48bf4c6f93698bb9611df3c3d4b9fc6b133c4bc (patch)
tree3e59fec2c24a8fc9133c8e952dd3bc45e527199e /lib
parentc0a834999d2cacf20cd9faa9e14bafa87bd7b550 (diff)
m68k assembler version of strlcpy(3)
Diffstat (limited to 'lib')
-rw-r--r--lib/libc/arch/m68k/string/Makefile.inc6
-rw-r--r--lib/libc/arch/m68k/string/strlcpy.S60
-rw-r--r--lib/libc/string/Makefile.inc6
3 files changed, 66 insertions, 6 deletions
diff --git a/lib/libc/arch/m68k/string/Makefile.inc b/lib/libc/arch/m68k/string/Makefile.inc
index a7deb2b10ee..1b3e8a05a9b 100644
--- a/lib/libc/arch/m68k/string/Makefile.inc
+++ b/lib/libc/arch/m68k/string/Makefile.inc
@@ -1,9 +1,9 @@
-# $OpenBSD: Makefile.inc,v 1.4 1996/08/19 08:15:05 tholo Exp $
+# $OpenBSD: Makefile.inc,v 1.5 1999/04/25 00:10:06 millert Exp $
SRCS+= bcmp.S bcopy.S bzero.S ffs.S index.S memchr.c memcmp.S memset.S \
- rindex.S strcat.S strcmp.S strcpy.S strcspn.c strlen.S \
+ rindex.S strcat.S strcmp.S strcpy.S strcspn.c strlen.S strlcpy.S \
strncat.c strncmp.S strncpy.S strpbrk.c strsep.c \
strspn.c strstr.c swab.S
SRCS+= memcpy.S memmove.S strchr.S strrchr.S
LSRCS+= bcmp.c bcopy.c bzero.c ffs.c index.c memcmp.c memset.c rindex.c \
- strcmp.c strcpy.c strlen.c strncmp.c strncpy.c swab.c
+ strcmp.c strcpy.c strlen.c strlcpy.c strncmp.c strncpy.c swab.c
diff --git a/lib/libc/arch/m68k/string/strlcpy.S b/lib/libc/arch/m68k/string/strlcpy.S
new file mode 100644
index 00000000000..6857a422d69
--- /dev/null
+++ b/lib/libc/arch/m68k/string/strlcpy.S
@@ -0,0 +1,60 @@
+/*
+ * Copyright (c) 1999 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.
+ */
+
+#include "DEFS.h"
+
+#if defined(LIBC_SCCS)
+ .text
+ .asciz "$OpenBSD: strlcpy.S,v 1.1 1999/04/25 00:10:06 millert Exp $"
+#endif /* LIBC_SCCS */
+
+ENTRY(strlcpy)
+ movl sp@(4),a0 | a0 = dst
+ movl sp@(8),a1 | a1 = src
+ movl a1,a2 | a2 = orig_src
+ movl sp@(12),a3 | a3 = orig_count
+ movl a3,d1 | d1 = count
+ beq slcloop | don't let count wrap...
+ subql #1,d1 | subtract one for the NUL
+slcloop:
+ tstb a1@ | got a NUL?
+ beq slcnul | if so, add NUL to dst and we're done
+ tstl d1 | only copy bytes if count is non-zero
+ beq slcinc | (else just increment src ptr)
+ movb a1@,a0@+ | copy a byte but only increment dst
+ subql #1,d1 | decrement count
+slcinc:
+ addql #1,a1 | increment src ptr
+ jra slcloop | keep going...
+slcnul:
+ tstl a3 | make sure we had a non-zero orig_count
+ beq slcdone
+ clrb a0@ | clear last byte
+slcdone:
+ movl a1,d0
+ subl a2,d0 | return value
+ rts
diff --git a/lib/libc/string/Makefile.inc b/lib/libc/string/Makefile.inc
index 78eee7efa57..ff11ecac6c5 100644
--- a/lib/libc/string/Makefile.inc
+++ b/lib/libc/string/Makefile.inc
@@ -1,16 +1,16 @@
-# $OpenBSD: Makefile.inc,v 1.6 1998/11/20 11:18:51 d Exp $
+# $OpenBSD: Makefile.inc,v 1.7 1999/04/25 00:10:07 millert Exp $
# string sources
.PATH: ${LIBCSRCDIR}/arch/${MACHINE_ARCH}/string ${LIBCSRCDIR}/string
SRCS+= bm.c memccpy.c strcasecmp.c strcoll.c strdup.c strerror.c \
- strlcat.c strlcpy.c strmode.c strsignal.c strtok.c strxfrm.c \
+ strlcat.c strmode.c strsignal.c strtok.c strxfrm.c \
__strerror.c __strsignal.c
# machine-dependent net sources
# m-d Makefile.inc must include sources for:
# bcmp() bcopy() bzero() ffs() index() memchr() memcmp() memset()
-# rindex() strcat() strcmp() strcpy() strcspn() strlen()
+# rindex() strcat() strcmp() strcpy() strcspn() strlen() strlcpy()
# strncat() strncmp() strncpy() strpbrk() strsep()
# strspn() strstr() swav()
# m-d Makefile.inc may include sources for: