]>
git.saurik.com Git - apple/boot.git/blob - i386/libsa/string.c
2 * Copyright (c) 1999-2003 Apple Computer, Inc. All rights reserved.
4 * @APPLE_LICENSE_HEADER_START@
6 * Portions Copyright (c) 1999-2003 Apple Computer, Inc. All Rights
7 * Reserved. This file contains Original Code and/or Modifications of
8 * Original Code as defined in and that are subject to the Apple Public
9 * Source License Version 2.0 (the "License"). You may not use this file
10 * except in compliance with the License. Please obtain a copy of the
11 * License at http://www.apple.com/publicsource and read it before using
14 * The Original Code and all software distributed under the License are
15 * distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, EITHER
16 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
17 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
18 * FITNESS FOR A PARTICULAR PURPOSE OR NON- INFRINGEMENT. Please see the
19 * License for the specific language governing rights and limitations
22 * @APPLE_LICENSE_HEADER_END@
24 /* string operations */
28 void * memset(void * dst
, int val
, size_t len
)
30 asm volatile ( "rep; stosb"
31 : "=c" (len
), "=D" (dst
)
32 : "0" (len
), "1" (dst
), "a" (val
)
39 void * memcpy(void * dst
, const void * src
, size_t len
)
41 asm volatile ( "rep; movsb"
42 : "=c" (len
), "=D" (dst
), "=S" (src
)
43 : "0" (len
), "1" (dst
), "2" (src
)
49 void bcopy(const void * src
, void * dst
, size_t len
)
51 memcpy(dst
, src
, len
);
54 void bzero(void * dst
, size_t len
)
60 void * memcpy(void * dst
, const void * src
, size_t len
)
62 asm volatile ( "cld \n\t"
63 "movl %%ecx, %%edx \n\t"
66 "movl %%edx, %%ecx \n\t"
70 : "c" (len
), "D" (dst
), "S" (src
)
76 void bcopy(const void * src
, void * dst
, size_t len
)
78 asm volatile ( "cld \n\t"
79 "movl %%ecx, %%edx \n\t"
82 "movl %%edx, %%ecx \n\t"
86 : "c" (len
), "D" (dst
), "S" (src
)
90 void bzero(void * dst
, size_t len
)
92 asm volatile ( "xorl %%eax, %%eax \n\t"
94 "movl %%ecx, %%edx \n\t"
97 "movl %%edx, %%ecx \n\t"
101 : "c" (len
), "D" (dst
)
102 : "memory", "%eax" );
106 /* #if DONT_USE_GCC_BUILT_IN_STRLEN */
108 #define tolower(c) ((int)((c) & ~0x20))
109 #define toupper(c) ((int)((c) | 0x20))
111 int strlen(const char * s
)
121 strcmp(const char * s1
, const char * s2
)
123 while (*s1
&& (*s1
== *s2
)) {
130 int strncmp(const char * s1
, const char * s2
, size_t len
)
132 register int n
= len
;
133 while (--n
>= 0 && *s1
== *s2
++)
136 return(n
<0 ? 0 : *s1
- *--s2
);
140 strcpy(char * s1
, const char * s2
)
142 register char *ret
= s1
;
143 while (*s1
++ = *s2
++)
149 strncpy(char * s1
, const char * s2
, size_t n
)
151 register char *ret
= s1
;
152 while (n
&& (*s1
++ = *s2
++))
158 strlcpy(char * s1
, const char * s2
, size_t n
)
160 register char *ret
= s1
;
161 while (n
&& (*s1
++ = *s2
++))
168 ptol(const char *str
)
170 register int c
= *str
;
172 if (c
<= '7' && c
>= '0')
174 else if (c
<= 'h' && c
>= 'a')
181 atoi(const char *str
)
183 register int sum
= 0;
184 while (*str
== ' ' || *str
== '\t')
186 while (*str
>= '0' && *str
<= '9') {
193 char *strncat(char *s1
, const char *s2
, size_t n
)
195 register char *ret
= s1
;
204 char *strcat(char *s1
, const char *s2
)
206 return(strncat(s1
, s2
, strlen(s2
)));
210 int strncasecmp(const char *s1
, const char *s2
, size_t len
)
212 register int n
= len
;
213 while (--n
>= 0 && tolower(*s1
) == tolower(*s2
++))
216 return(n
<0 ? 0 : tolower(*s1
) - tolower(*--s2
));