]> git.saurik.com Git - apple/boot.git/blob - i386/boot1u/string.c
boot-132.tar.gz
[apple/boot.git] / i386 / boot1u / string.c
1 /*
2 * Copyright (c) 1999-2003 Apple Computer, Inc. All rights reserved.
3 *
4 * @APPLE_LICENSE_HEADER_START@
5 *
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
12 * this file.
13 *
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
20 * under the License.
21 *
22 * @APPLE_LICENSE_HEADER_END@
23 */
24 /* string operations */
25
26 #include "libsa.h"
27
28 void * memset(void * dst, int val, size_t len)
29 {
30 asm volatile ( "rep; stosb"
31 : "=c" (len), "=D" (dst)
32 : "0" (len), "1" (dst), "a" (val)
33 : "memory" );
34
35 return dst;
36 }
37
38 void * memcpy(void * dst, const void * src, size_t len)
39 {
40 asm volatile ( "rep; movsb"
41 : "=c" (len), "=D" (dst), "=S" (src)
42 : "0" (len), "1" (dst), "2" (src)
43 : "memory" );
44
45 return dst;
46 }
47
48 void bcopy(const void * src, void * dst, size_t len)
49 {
50 memcpy(dst, src, len);
51 }
52
53 void bzero(void * dst, size_t len)
54 {
55 memset(dst, 0, len);
56 }
57
58 #if 0
59 /* #if DONT_USE_GCC_BUILT_IN_STRLEN */
60
61 #define tolower(c) ((int)((c) & ~0x20))
62 #define toupper(c) ((int)((c) | 0x20))
63
64 int strlen(const char * s)
65 {
66 int n = 0;
67 while (*s++) n++;
68 return(n);
69 }
70
71 /*#endif*/
72 #endif
73
74 int
75 strcmp(const char * s1, const char * s2)
76 {
77 while (*s1 && (*s1 == *s2)) {
78 s1++;
79 s2++;
80 }
81 return (*s1 - *s2);
82 }
83
84 #if 0
85 int strncmp(const char * s1, const char * s2, size_t len)
86 {
87 register int n = len;
88 while (--n >= 0 && *s1 == *s2++)
89 if (*s1++ == '\0')
90 return(0);
91 return(n<0 ? 0 : *s1 - *--s2);
92 }
93
94 char *
95 strcpy(char * s1, const char * s2)
96 {
97 register char *ret = s1;
98 while (*s1++ = *s2++)
99 continue;
100 return ret;
101 }
102 #endif
103
104 char *
105 strncpy(char * s1, const char * s2, size_t n)
106 {
107 register char *ret = s1;
108 while (n && (*s1++ = *s2++))
109 n--;
110 return ret;
111 }
112
113 char *
114 strlcpy(char * s1, const char * s2, size_t n)
115 {
116 register char *ret = s1;
117 while (n && (*s1++ = *s2++))
118 n--;
119 if (!n) *--s1=0;
120 return ret;
121 }
122
123 #if 0
124 int
125 ptol(const char *str)
126 {
127 register int c = *str;
128
129 if (c <= '7' && c >= '0')
130 c -= '0';
131 else if (c <= 'h' && c >= 'a')
132 c -= 'a';
133 else c = 0;
134 return c;
135 }
136 #endif
137
138 int
139 atoi(const char *str)
140 {
141 register int sum = 0;
142 while (*str == ' ' || *str == '\t')
143 str++;
144 while (*str >= '0' && *str <= '9') {
145 sum *= 10;
146 sum += *str++ - '0';
147 }
148 return sum;
149 }
150
151 #if 0
152 char *strncat(char *s1, const char *s2, size_t n)
153 {
154 register char *ret = s1;
155 while (*s1)
156 s1++;
157 while (n-- && *s2)
158 *s1++ = *s2++;
159 *s1 = '\0';
160 return ret;
161 }
162
163 char *strcat(char *s1, const char *s2)
164 {
165 return(strncat(s1, s2, strlen(s2)));
166 }
167
168 #if STRNCASECMP
169 int strncasecmp(const char *s1, const char *s2, size_t len)
170 {
171 register int n = len;
172 while (--n >= 0 && tolower(*s1) == tolower(*s2++))
173 if (*s1++ == '\0')
174 return(0);
175 return(n<0 ? 0 : tolower(*s1) - tolower(*--s2));
176 }
177 #endif
178 #endif