]>
git.saurik.com Git - apple/boot.git/blob - i386/libsa/string.c
4ed67cd4ca7fc23f64dbc450244678a3e37d6c70
2 * Copyright (c) 1999 Apple Computer, Inc. All rights reserved.
4 * @APPLE_LICENSE_HEADER_START@
6 * Portions Copyright (c) 1999 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 1.1 (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
)
31 : "=c" (len
), "=D" (dst
)
32 : "0" (len
), "1" (dst
), "a" (val
)
38 void * memcpy(void * dst
, const void * src
, size_t len
)
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
)
58 /* #if DONT_USE_GCC_BUILT_IN_STRLEN */
60 #define tolower(c) ((int)((c) & ~0x20))
61 #define toupper(c) ((int)((c) | 0x20))
63 int strlen(const char * s
)
73 strcmp(const char * s1
, const char * s2
)
75 while (*s1
&& (*s1
== *s2
)) {
82 int strncmp(const char * s1
, const char * s2
, size_t len
)
85 while (--n
>= 0 && *s1
== *s2
++)
88 return(n
<0 ? 0 : *s1
- *--s2
);
92 strcpy(char * s1
, const char * s2
)
94 register char *ret
= s1
;
101 strncpy(char * s1
, const char * s2
, size_t n
)
103 register char *ret
= s1
;
104 while (n
&& (*s1
++ = *s2
++))
110 strlcpy(char * s1
, const char * s2
, size_t n
)
112 register char *ret
= s1
;
113 while (n
&& (*s1
++ = *s2
++))
120 ptol(const char *str
)
122 register int c
= *str
;
124 if (c
<= '7' && c
>= '0')
126 else if (c
<= 'h' && c
>= 'a')
133 atoi(const char *str
)
135 register int sum
= 0;
136 while (*str
== ' ' || *str
== '\t')
138 while (*str
>= '0' && *str
<= '9') {
145 char *strncat(char *s1
, const char *s2
, size_t n
)
147 register char *ret
= s1
;
156 char *strcat(char *s1
, const char *s2
)
158 return(strncat(s1
, s2
, strlen(s2
)));
162 int strncasecmp(const char *s1
, const char *s2
, size_t len
)
164 register int n
= len
;
165 while (--n
>= 0 && tolower(*s1
) == tolower(*s2
++))
168 return(n
<0 ? 0 : tolower(*s1
) - tolower(*--s2
));