]>
Commit | Line | Data |
---|---|---|
f083c6c3 A |
1 | /* |
2 | * Copyright (c) 1999-2002 Apple Computer, Inc. All rights reserved. | |
3 | * | |
4 | * @APPLE_LICENSE_HEADER_START@ | |
5 | * | |
6 | * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved. | |
7 | * | |
8 | * This file contains Original Code and/or Modifications of Original Code | |
9 | * as defined in and that are subject to the Apple Public Source License | |
10 | * Version 2.0 (the 'License'). You may not use this file except in | |
11 | * compliance with the License. Please obtain a copy of the License at | |
12 | * http://www.opensource.apple.com/apsl/ and read it before using this | |
13 | * file. | |
14 | * | |
15 | * The Original Code and all software distributed under the License are | |
16 | * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER | |
17 | * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, | |
18 | * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, | |
19 | * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT. | |
20 | * Please see the License for the specific language governing rights and | |
21 | * limitations under the License. | |
22 | * | |
23 | * @APPLE_LICENSE_HEADER_END@ | |
24 | */ | |
25 | /* string operations */ | |
26 | ||
27 | #include "libsa.h" | |
28 | ||
29 | void * memset(void * dst, int val, size_t len) | |
30 | { | |
31 | asm( "rep; stosb" | |
32 | : "=c" (len), "=D" (dst) | |
33 | : "0" (len), "1" (dst), "a" (val) | |
34 | : "memory" ); | |
35 | ||
36 | return dst; | |
37 | } | |
38 | ||
39 | void * memcpy(void * dst, const void * src, size_t len) | |
40 | { | |
41 | asm( "rep; movsb" | |
42 | : "=c" (len), "=D" (dst), "=S" (src) | |
43 | : "0" (len), "1" (dst), "2" (src) | |
44 | : "memory" ); | |
45 | ||
46 | return dst; | |
47 | } | |
48 | ||
49 | void bcopy(const void * src, void * dst, size_t len) | |
50 | { | |
51 | memcpy(dst, src, len); | |
52 | } | |
53 | ||
54 | void bzero(void * dst, size_t len) | |
55 | { | |
56 | memset(dst, 0, len); | |
57 | } | |
58 | ||
59 | #if 0 | |
60 | /* #if DONT_USE_GCC_BUILT_IN_STRLEN */ | |
61 | ||
62 | #define tolower(c) ((int)((c) & ~0x20)) | |
63 | #define toupper(c) ((int)((c) | 0x20)) | |
64 | ||
65 | int strlen(const char * s) | |
66 | { | |
67 | int n = 0; | |
68 | while (*s++) n++; | |
69 | return(n); | |
70 | } | |
71 | ||
72 | /*#endif*/ | |
73 | #endif | |
74 | ||
75 | int | |
76 | strcmp(const char * s1, const char * s2) | |
77 | { | |
78 | while (*s1 && (*s1 == *s2)) { | |
79 | s1++; | |
80 | s2++; | |
81 | } | |
82 | return (*s1 - *s2); | |
83 | } | |
84 | ||
85 | #if 0 | |
86 | int strncmp(const char * s1, const char * s2, size_t len) | |
87 | { | |
88 | register int n = len; | |
89 | while (--n >= 0 && *s1 == *s2++) | |
90 | if (*s1++ == '\0') | |
91 | return(0); | |
92 | return(n<0 ? 0 : *s1 - *--s2); | |
93 | } | |
94 | ||
95 | char * | |
96 | strcpy(char * s1, const char * s2) | |
97 | { | |
98 | register char *ret = s1; | |
99 | while (*s1++ = *s2++) | |
100 | continue; | |
101 | return ret; | |
102 | } | |
103 | #endif | |
104 | ||
105 | char * | |
106 | strncpy(char * s1, const char * s2, size_t n) | |
107 | { | |
108 | register char *ret = s1; | |
109 | while (n && (*s1++ = *s2++)) | |
110 | n--; | |
111 | return ret; | |
112 | } | |
113 | ||
114 | char * | |
115 | strlcpy(char * s1, const char * s2, size_t n) | |
116 | { | |
117 | register char *ret = s1; | |
118 | while (n && (*s1++ = *s2++)) | |
119 | n--; | |
120 | if (!n) *--s1=0; | |
121 | return ret; | |
122 | } | |
123 | ||
124 | #if 0 | |
125 | int | |
126 | ptol(const char *str) | |
127 | { | |
128 | register int c = *str; | |
129 | ||
130 | if (c <= '7' && c >= '0') | |
131 | c -= '0'; | |
132 | else if (c <= 'h' && c >= 'a') | |
133 | c -= 'a'; | |
134 | else c = 0; | |
135 | return c; | |
136 | } | |
137 | #endif | |
138 | ||
139 | int | |
140 | atoi(const char *str) | |
141 | { | |
142 | register int sum = 0; | |
143 | while (*str == ' ' || *str == '\t') | |
144 | str++; | |
145 | while (*str >= '0' && *str <= '9') { | |
146 | sum *= 10; | |
147 | sum += *str++ - '0'; | |
148 | } | |
149 | return sum; | |
150 | } | |
151 | ||
152 | #if 0 | |
153 | char *strncat(char *s1, const char *s2, size_t n) | |
154 | { | |
155 | register char *ret = s1; | |
156 | while (*s1) | |
157 | s1++; | |
158 | while (n-- && *s2) | |
159 | *s1++ = *s2++; | |
160 | *s1 = '\0'; | |
161 | return ret; | |
162 | } | |
163 | ||
164 | char *strcat(char *s1, const char *s2) | |
165 | { | |
166 | return(strncat(s1, s2, strlen(s2))); | |
167 | } | |
168 | ||
169 | #if STRNCASECMP | |
170 | int strncasecmp(const char *s1, const char *s2, size_t len) | |
171 | { | |
172 | register int n = len; | |
173 | while (--n >= 0 && tolower(*s1) == tolower(*s2++)) | |
174 | if (*s1++ == '\0') | |
175 | return(0); | |
176 | return(n<0 ? 0 : tolower(*s1) - tolower(*--s2)); | |
177 | } | |
178 | #endif | |
179 | #endif |