]>
git.saurik.com Git - apple/boot.git/blob - i386/boot1u/string.c
4abdb72896137d92e8a701524c7cae971dcd7fde
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
)
38 void * memcpy(void * dst
, const void * src
, size_t len
)
40 asm volatile ( "rep; movsb"
41 : "=c" (len
), "=D" (dst
), "=S" (src
)
42 : "0" (len
), "1" (dst
), "2" (src
)
48 void bcopy(const void * src
, void * dst
, size_t len
)
50 memcpy(dst
, src
, len
);
53 void bzero(void * dst
, size_t len
)
59 /* #if DONT_USE_GCC_BUILT_IN_STRLEN */
61 #define tolower(c) ((int)((c) & ~0x20))
62 #define toupper(c) ((int)((c) | 0x20))
64 int strlen(const char * s
)
75 strcmp(const char * s1
, const char * s2
)
77 while (*s1
&& (*s1
== *s2
)) {
85 int strncmp(const char * s1
, const char * s2
, size_t len
)
88 while (--n
>= 0 && *s1
== *s2
++)
91 return(n
<0 ? 0 : *s1
- *--s2
);
95 strcpy(char * s1
, const char * s2
)
97 register char *ret
= s1
;
105 strncpy(char * s1
, const char * s2
, size_t n
)
107 register char *ret
= s1
;
108 while (n
&& (*s1
++ = *s2
++))
114 strlcpy(char * s1
, const char * s2
, size_t n
)
116 register char *ret
= s1
;
117 while (n
&& (*s1
++ = *s2
++))
125 ptol(const char *str
)
127 register int c
= *str
;
129 if (c
<= '7' && c
>= '0')
131 else if (c
<= 'h' && c
>= 'a')
139 atoi(const char *str
)
141 register int sum
= 0;
142 while (*str
== ' ' || *str
== '\t')
144 while (*str
>= '0' && *str
<= '9') {
152 char *strncat(char *s1
, const char *s2
, size_t n
)
154 register char *ret
= s1
;
163 char *strcat(char *s1
, const char *s2
)
165 return(strncat(s1
, s2
, strlen(s2
)));
169 int strncasecmp(const char *s1
, const char *s2
, size_t len
)
171 register int n
= len
;
172 while (--n
>= 0 && tolower(*s1
) == tolower(*s2
++))
175 return(n
<0 ? 0 : tolower(*s1
) - tolower(*--s2
));