/*
- * Copyright (c) 1999 Apple Computer, Inc. All rights reserved.
+ * Copyright (c) 1999-2003 Apple Computer, Inc. All rights reserved.
*
* @APPLE_LICENSE_HEADER_START@
*
- * Portions Copyright (c) 1999 Apple Computer, Inc. All Rights
+ * Portions Copyright (c) 1999-2003 Apple Computer, Inc. All Rights
* Reserved. This file contains Original Code and/or Modifications of
* Original Code as defined in and that are subject to the Apple Public
- * Source License Version 1.1 (the "License"). You may not use this file
+ * Source License Version 2.0 (the "License"). You may not use this file
* except in compliance with the License. Please obtain a copy of the
* License at http://www.apple.com/publicsource and read it before using
* this file.
void * memset(void * dst, int val, size_t len)
{
- asm( "rep; stosb"
+ asm volatile ( "rep; stosb"
: "=c" (len), "=D" (dst)
: "0" (len), "1" (dst), "a" (val)
: "memory" );
return dst;
}
+#if 0
void * memcpy(void * dst, const void * src, size_t len)
{
- asm( "rep; movsb"
+ asm volatile ( "rep; movsb"
: "=c" (len), "=D" (dst), "=S" (src)
: "0" (len), "1" (dst), "2" (src)
: "memory" );
memset(dst, 0, len);
}
+#else
+void * memcpy(void * dst, const void * src, size_t len)
+{
+ asm volatile ( "cld \n\t"
+ "movl %%ecx, %%edx \n\t"
+ "shrl $2, %%ecx \n\t"
+ "rep; movsl \n\t"
+ "movl %%edx, %%ecx \n\t"
+ "andl $3, %%ecx \n\t"
+ "rep; movsb \n\t"
+ : "=D" (dst)
+ : "c" (len), "D" (dst), "S" (src)
+ : "memory", "%edx" );
+
+ return dst;
+}
+
+void bcopy(const void * src, void * dst, size_t len)
+{
+ asm volatile ( "cld \n\t"
+ "movl %%ecx, %%edx \n\t"
+ "shrl $2, %%ecx \n\t"
+ "rep; movsl \n\t"
+ "movl %%edx, %%ecx \n\t"
+ "andl $3, %%ecx \n\t"
+ "rep; movsb \n\t"
+ :
+ : "c" (len), "D" (dst), "S" (src)
+ : "memory", "%edx" );
+}
+
+void bzero(void * dst, size_t len)
+{
+ asm volatile ( "xorl %%eax, %%eax \n\t"
+ "cld \n\t"
+ "movl %%ecx, %%edx \n\t"
+ "shrl $2, %%ecx \n\t"
+ "rep; stosl \n\t"
+ "movl %%edx, %%ecx \n\t"
+ "andl $3, %%ecx \n\t"
+ "rep; stosb \n\t"
+ :
+ : "c" (len), "D" (dst)
+ : "memory", "%eax" );
+}
+#endif
+
/* #if DONT_USE_GCC_BUILT_IN_STRLEN */
#define tolower(c) ((int)((c) & ~0x20))
register char *ret = s1;
while (n && (*s1++ = *s2++))
n--;
- if (!n) *s1=0;
+ return ret;
+}
+
+char *
+strlcpy(char * s1, const char * s2, size_t n)
+{
+ register char *ret = s1;
+ while (n && (*s1++ = *s2++))
+ n--;
+ if (!n) *--s1=0;
return ret;
}