Rev 2541 | Rev 2754 | Go to most recent revision | Only display areas with differences | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 2541 | Rev 2640 | ||
---|---|---|---|
1 | /* |
1 | /* |
2 | * Copyright (c) 2005 Martin Decky |
2 | * Copyright (c) 2005 Martin Decky |
3 | * All rights reserved. |
3 | * All rights reserved. |
4 | * |
4 | * |
5 | * Redistribution and use in source and binary forms, with or without |
5 | * Redistribution and use in source and binary forms, with or without |
6 | * modification, are permitted provided that the following conditions |
6 | * modification, are permitted provided that the following conditions |
7 | * are met: |
7 | * are met: |
8 | * |
8 | * |
9 | * - Redistributions of source code must retain the above copyright |
9 | * - Redistributions of source code must retain the above copyright |
10 | * notice, this list of conditions and the following disclaimer. |
10 | * notice, this list of conditions and the following disclaimer. |
11 | * - Redistributions in binary form must reproduce the above copyright |
11 | * - Redistributions in binary form must reproduce the above copyright |
12 | * notice, this list of conditions and the following disclaimer in the |
12 | * notice, this list of conditions and the following disclaimer in the |
13 | * documentation and/or other materials provided with the distribution. |
13 | * documentation and/or other materials provided with the distribution. |
14 | * - The name of the author may not be used to endorse or promote products |
14 | * - The name of the author may not be used to endorse or promote products |
15 | * derived from this software without specific prior written permission. |
15 | * derived from this software without specific prior written permission. |
16 | * |
16 | * |
17 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR |
17 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR |
18 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES |
18 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES |
19 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. |
19 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. |
20 | * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, |
20 | * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, |
21 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT |
21 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT |
22 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
22 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
23 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
23 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
24 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
24 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
25 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF |
25 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF |
26 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
26 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
27 | */ |
27 | */ |
28 | 28 | ||
29 | /** @addtogroup libc |
29 | /** @addtogroup libc |
30 | * @{ |
30 | * @{ |
31 | */ |
31 | */ |
32 | /** @file |
32 | /** @file |
33 | */ |
33 | */ |
34 | 34 | ||
35 | #include <string.h> |
35 | #include <string.h> |
36 | #include <unistd.h> |
36 | #include <unistd.h> |
37 | #include <ctype.h> |
37 | #include <ctype.h> |
38 | #include <limits.h> |
38 | #include <limits.h> |
39 | #include <align.h> |
39 | #include <align.h> |
40 | #include <sys/types.h> |
40 | #include <sys/types.h> |
41 | 41 | ||
42 | 42 | ||
43 | /* Dummy implementation of mem/ functions */ |
43 | /* Dummy implementation of mem/ functions */ |
44 | 44 | ||
45 | void *memset(void *s, int c, size_t n) |
45 | void *memset(void *s, int c, size_t n) |
46 | { |
46 | { |
47 | char *os = s; |
47 | char *os = s; |
48 | 48 | ||
49 | while (n--) |
49 | while (n--) |
50 | *(os++) = c; |
50 | *(os++) = c; |
51 | 51 | ||
52 | return s; |
52 | return s; |
53 | } |
53 | } |
54 | 54 | ||
55 | struct along { |
55 | struct along { |
56 | unsigned long n; |
56 | unsigned long n; |
57 | } __attribute__ ((packed)); |
57 | } __attribute__ ((packed)); |
58 | 58 | ||
59 | static void *unaligned_memcpy(void *dst, const void *src, size_t n) |
59 | static void *unaligned_memcpy(void *dst, const void *src, size_t n) |
60 | { |
60 | { |
61 | int i, j; |
61 | int i, j; |
62 | struct along *adst = dst; |
62 | struct along *adst = dst; |
63 | const struct along *asrc = src; |
63 | const struct along *asrc = src; |
64 | 64 | ||
65 | for (i = 0; i < n / sizeof(unsigned long); i++) |
65 | for (i = 0; i < n / sizeof(unsigned long); i++) |
66 | adst[i].n = asrc[i].n; |
66 | adst[i].n = asrc[i].n; |
67 | 67 | ||
68 | for (j = 0; j < n % sizeof(unsigned long); j++) |
68 | for (j = 0; j < n % sizeof(unsigned long); j++) |
69 | ((unsigned char *) (((unsigned long *) dst) + i))[j] = ((unsigned char *) (((unsigned long *) src) + i))[j]; |
69 | ((unsigned char *) (((unsigned long *) dst) + i))[j] = ((unsigned char *) (((unsigned long *) src) + i))[j]; |
70 | 70 | ||
71 | return (char *) src; |
71 | return (char *) src; |
72 | } |
72 | } |
73 | 73 | ||
74 | void *memcpy(void *dst, const void *src, size_t n) |
74 | void *memcpy(void *dst, const void *src, size_t n) |
75 | { |
75 | { |
76 | int i, j; |
76 | int i, j; |
77 | 77 | ||
78 | if (((long) dst & (sizeof(long) - 1)) || ((long) src & (sizeof(long) - 1))) |
78 | if (((long) dst & (sizeof(long) - 1)) || ((long) src & (sizeof(long) - 1))) |
79 | return unaligned_memcpy(dst, src, n); |
79 | return unaligned_memcpy(dst, src, n); |
80 | 80 | ||
81 | for (i = 0; i < n / sizeof(unsigned long); i++) |
81 | for (i = 0; i < n / sizeof(unsigned long); i++) |
82 | ((unsigned long *) dst)[i] = ((unsigned long *) src)[i]; |
82 | ((unsigned long *) dst)[i] = ((unsigned long *) src)[i]; |
83 | 83 | ||
84 | for (j = 0; j < n % sizeof(unsigned long); j++) |
84 | for (j = 0; j < n % sizeof(unsigned long); j++) |
85 | ((unsigned char *) (((unsigned long *) dst) + i))[j] = ((unsigned char *) (((unsigned long *) src) + i))[j]; |
85 | ((unsigned char *) (((unsigned long *) dst) + i))[j] = ((unsigned char *) (((unsigned long *) src) + i))[j]; |
86 | 86 | ||
87 | return (char *) src; |
87 | return (char *) src; |
88 | } |
88 | } |
89 | 89 | ||
90 | void *memmove(void *dst, const void *src, size_t n) |
90 | void *memmove(void *dst, const void *src, size_t n) |
91 | { |
91 | { |
92 | int i, j; |
92 | int i, j; |
93 | 93 | ||
94 | if (src > dst) |
94 | if (src > dst) |
95 | return memcpy(dst, src, n); |
95 | return memcpy(dst, src, n); |
96 | 96 | ||
97 | for (j = (n % sizeof(unsigned long)) - 1; j >= 0; j--) |
97 | for (j = (n % sizeof(unsigned long)) - 1; j >= 0; j--) |
98 | ((unsigned char *) ((unsigned long *) dst))[j] = ((unsigned char *) ((unsigned long *) src))[j]; |
98 | ((unsigned char *) ((unsigned long *) dst))[j] = ((unsigned char *) ((unsigned long *) src))[j]; |
99 | 99 | ||
100 | for (i = n / sizeof(unsigned long) - 1; i >=0 ; i--) |
100 | for (i = n / sizeof(unsigned long) - 1; i >=0 ; i--) |
101 | ((unsigned long *) dst)[i] = ((unsigned long *) src)[i]; |
101 | ((unsigned long *) dst)[i] = ((unsigned long *) src)[i]; |
102 | 102 | ||
103 | return (char *) src; |
103 | return (char *) src; |
104 | } |
104 | } |
105 | 105 | ||
106 | /** Compare two memory areas. |
106 | /** Compare two memory areas. |
107 | * |
107 | * |
108 | * @param s1 Pointer to the first area to compare. |
108 | * @param s1 Pointer to the first area to compare. |
109 | * @param s2 Pointer to the second area to compare. |
109 | * @param s2 Pointer to the second area to compare. |
110 | * @param len Size of the first area in bytes. Both areas must have the same |
110 | * @param len Size of the first area in bytes. Both areas must have the same |
111 | * length. |
111 | * length. |
112 | * @return If len is 0, return zero. If the areas match, return zero. |
112 | * @return If len is 0, return zero. If the areas match, return zero. |
113 | * Otherwise return non-zero. |
113 | * Otherwise return non-zero. |
114 | */ |
114 | */ |
115 | int bcmp(const char *s1, const char *s2, size_t len) |
115 | int bcmp(const char *s1, const char *s2, size_t len) |
116 | { |
116 | { |
117 | for (; len && *s1++ == *s2++; len--) |
117 | for (; len && *s1++ == *s2++; len--) |
118 | ; |
118 | ; |
119 | return len; |
119 | return len; |
120 | } |
120 | } |
121 | 121 | ||
122 | /** Count the number of characters in the string, not including terminating 0. |
122 | /** Count the number of characters in the string, not including terminating 0. |
123 | * @param str string |
123 | * @param str string |
124 | * @return number of characters in string. |
124 | * @return number of characters in string. |
125 | */ |
125 | */ |
126 | size_t strlen(const char *str) |
126 | size_t strlen(const char *str) |
127 | { |
127 | { |
128 | size_t counter = 0; |
128 | size_t counter = 0; |
129 | 129 | ||
130 | while (str[counter] != 0) |
130 | while (str[counter] != 0) |
131 | counter++; |
131 | counter++; |
132 | 132 | ||
133 | return counter; |
133 | return counter; |
134 | } |
134 | } |
135 | 135 | ||
136 | int strcmp(const char *a, const char *b) |
136 | int strcmp(const char *a, const char *b) |
137 | { |
137 | { |
138 | int c = 0; |
138 | int c = 0; |
139 | 139 | ||
140 | while (a[c] && b[c] && (!(a[c] - b[c]))) |
140 | while (a[c] && b[c] && (!(a[c] - b[c]))) |
141 | c++; |
141 | c++; |
142 | 142 | ||
143 | return (a[c] - b[c]); |
143 | return (a[c] - b[c]); |
144 | 144 | ||
145 | } |
145 | } |
146 | 146 | ||
- | 147 | int strncmp(const char *a, const char *b, size_t n) |
|
- | 148 | { |
|
- | 149 | size_t c = 0; |
|
- | 150 | ||
- | 151 | while (c < n && a[c] && b[c] && (!(a[c] - b[c]))) |
|
- | 152 | c++; |
|
- | 153 | ||
- | 154 | return ( c < n ? a[c] - b[c] : 0); |
|
- | 155 | ||
- | 156 | } |
|
147 | 157 | ||
148 | /** Return pointer to the first occurence of character c in string |
158 | /** Return pointer to the first occurence of character c in string |
149 | * @param str scanned string |
159 | * @param str scanned string |
150 | * @param c searched character (taken as one byte) |
160 | * @param c searched character (taken as one byte) |
151 | * @return pointer to the matched character or NULL if it is not found in given string. |
161 | * @return pointer to the matched character or NULL if it is not found in given string. |
152 | */ |
162 | */ |
153 | char *strchr(const char *str, int c) |
163 | char *strchr(const char *str, int c) |
154 | { |
164 | { |
155 | while (*str != '\0') { |
165 | while (*str != '\0') { |
156 | if (*str == (char) c) |
166 | if (*str == (char) c) |
157 | return (char *) str; |
167 | return (char *) str; |
158 | str++; |
168 | str++; |
159 | } |
169 | } |
160 | 170 | ||
161 | return NULL; |
171 | return NULL; |
162 | } |
172 | } |
163 | 173 | ||
164 | /** Return pointer to the last occurence of character c in string |
174 | /** Return pointer to the last occurence of character c in string |
165 | * @param str scanned string |
175 | * @param str scanned string |
166 | * @param c searched character (taken as one byte) |
176 | * @param c searched character (taken as one byte) |
167 | * @return pointer to the matched character or NULL if it is not found in given string. |
177 | * @return pointer to the matched character or NULL if it is not found in given string. |
168 | */ |
178 | */ |
169 | char *strrchr(const char *str, int c) |
179 | char *strrchr(const char *str, int c) |
170 | { |
180 | { |
171 | char *retval = NULL; |
181 | char *retval = NULL; |
172 | 182 | ||
173 | while (*str != '\0') { |
183 | while (*str != '\0') { |
174 | if (*str == (char) c) |
184 | if (*str == (char) c) |
175 | retval = (char *) str; |
185 | retval = (char *) str; |
176 | str++; |
186 | str++; |
177 | } |
187 | } |
178 | 188 | ||
179 | return (char *) retval; |
189 | return (char *) retval; |
180 | } |
190 | } |
181 | 191 | ||
182 | /** Convert string to a number. |
192 | /** Convert string to a number. |
183 | * Core of strtol and strtoul functions. |
193 | * Core of strtol and strtoul functions. |
184 | * @param nptr pointer to string |
194 | * @param nptr pointer to string |
185 | * @param endptr if not NULL, function stores here pointer to the first invalid character |
195 | * @param endptr if not NULL, function stores here pointer to the first invalid character |
186 | * @param base zero or number between 2 and 36 inclusive |
196 | * @param base zero or number between 2 and 36 inclusive |
187 | * @param sgn its set to 1 if minus found |
197 | * @param sgn its set to 1 if minus found |
188 | * @return result of conversion. |
198 | * @return result of conversion. |
189 | */ |
199 | */ |
190 | static unsigned long _strtoul(const char *nptr, char **endptr, int base, char *sgn) |
200 | static unsigned long _strtoul(const char *nptr, char **endptr, int base, char *sgn) |
191 | { |
201 | { |
192 | unsigned char c; |
202 | unsigned char c; |
193 | unsigned long result = 0; |
203 | unsigned long result = 0; |
194 | unsigned long a, b; |
204 | unsigned long a, b; |
195 | const char *str = nptr; |
205 | const char *str = nptr; |
196 | const char *tmpptr; |
206 | const char *tmpptr; |
197 | 207 | ||
198 | while (isspace(*str)) |
208 | while (isspace(*str)) |
199 | str++; |
209 | str++; |
200 | 210 | ||
201 | if (*str == '-') { |
211 | if (*str == '-') { |
202 | *sgn = 1; |
212 | *sgn = 1; |
203 | ++str; |
213 | ++str; |
204 | } else if (*str == '+') |
214 | } else if (*str == '+') |
205 | ++str; |
215 | ++str; |
206 | 216 | ||
207 | if (base) { |
217 | if (base) { |
208 | if ((base == 1) || (base > 36)) { |
218 | if ((base == 1) || (base > 36)) { |
209 | /* FIXME: set errno to EINVAL */ |
219 | /* FIXME: set errno to EINVAL */ |
210 | return 0; |
220 | return 0; |
211 | } |
221 | } |
212 | if ((base == 16) && (*str == '0') && ((str[1] == 'x') || (str[1] == 'X'))) { |
222 | if ((base == 16) && (*str == '0') && ((str[1] == 'x') || (str[1] == 'X'))) { |
213 | str += 2; |
223 | str += 2; |
214 | } |
224 | } |
215 | } else { |
225 | } else { |
216 | base = 10; |
226 | base = 10; |
217 | 227 | ||
218 | if (*str == '0') { |
228 | if (*str == '0') { |
219 | base = 8; |
229 | base = 8; |
220 | if ((str[1] == 'X') || (str[1] == 'x')) { |
230 | if ((str[1] == 'X') || (str[1] == 'x')) { |
221 | base = 16; |
231 | base = 16; |
222 | str += 2; |
232 | str += 2; |
223 | } |
233 | } |
224 | } |
234 | } |
225 | } |
235 | } |
226 | 236 | ||
227 | tmpptr = str; |
237 | tmpptr = str; |
228 | 238 | ||
229 | while (*str) { |
239 | while (*str) { |
230 | c = *str; |
240 | c = *str; |
231 | c = (c >= 'a' ? c - 'a' + 10 : (c >= 'A' ? c - 'A' + 10 : (c <= '9' ? c - '0' : 0xff))); |
241 | c = (c >= 'a' ? c - 'a' + 10 : (c >= 'A' ? c - 'A' + 10 : (c <= '9' ? c - '0' : 0xff))); |
232 | if (c > base) { |
242 | if (c > base) { |
233 | break; |
243 | break; |
234 | } |
244 | } |
235 | 245 | ||
236 | a = (result & 0xff) * base + c; |
246 | a = (result & 0xff) * base + c; |
237 | b = (result >> 8) * base + (a >> 8); |
247 | b = (result >> 8) * base + (a >> 8); |
238 | 248 | ||
239 | if (b > (ULONG_MAX >> 8)) { |
249 | if (b > (ULONG_MAX >> 8)) { |
240 | /* overflow */ |
250 | /* overflow */ |
241 | /* FIXME: errno = ERANGE*/ |
251 | /* FIXME: errno = ERANGE*/ |
242 | return ULONG_MAX; |
252 | return ULONG_MAX; |
243 | } |
253 | } |
244 | 254 | ||
245 | result = (b << 8) + (a & 0xff); |
255 | result = (b << 8) + (a & 0xff); |
246 | ++str; |
256 | ++str; |
247 | } |
257 | } |
248 | 258 | ||
249 | if (str == tmpptr) { |
259 | if (str == tmpptr) { |
250 | /* no number was found => first invalid character is the first character of the string */ |
260 | /* no number was found => first invalid character is the first character of the string */ |
251 | /* FIXME: set errno to EINVAL */ |
261 | /* FIXME: set errno to EINVAL */ |
252 | str = nptr; |
262 | str = nptr; |
253 | result = 0; |
263 | result = 0; |
254 | } |
264 | } |
255 | 265 | ||
256 | if (endptr) |
266 | if (endptr) |
257 | *endptr = (char *) str; |
267 | *endptr = (char *) str; |
258 | 268 | ||
259 | if (nptr == str) { |
269 | if (nptr == str) { |
260 | /*FIXME: errno = EINVAL*/ |
270 | /*FIXME: errno = EINVAL*/ |
261 | return 0; |
271 | return 0; |
262 | } |
272 | } |
263 | 273 | ||
264 | return result; |
274 | return result; |
265 | } |
275 | } |
266 | 276 | ||
267 | /** Convert initial part of string to long int according to given base. |
277 | /** Convert initial part of string to long int according to given base. |
268 | * The number may begin with an arbitrary number of whitespaces followed by optional sign (`+' or `-'). |
278 | * The number may begin with an arbitrary number of whitespaces followed by optional sign (`+' or `-'). |
269 | * If the base is 0 or 16, the prefix `0x' may be inserted and the number will be taken as hexadecimal one. |
279 | * If the base is 0 or 16, the prefix `0x' may be inserted and the number will be taken as hexadecimal one. |
270 | * If the base is 0 and the number begin with a zero, number will be taken as octal one (as with base 8). |
280 | * If the base is 0 and the number begin with a zero, number will be taken as octal one (as with base 8). |
271 | * Otherwise the base 0 is taken as decimal. |
281 | * Otherwise the base 0 is taken as decimal. |
272 | * @param nptr pointer to string |
282 | * @param nptr pointer to string |
273 | * @param endptr if not NULL, function stores here pointer to the first invalid character |
283 | * @param endptr if not NULL, function stores here pointer to the first invalid character |
274 | * @param base zero or number between 2 and 36 inclusive |
284 | * @param base zero or number between 2 and 36 inclusive |
275 | * @return result of conversion. |
285 | * @return result of conversion. |
276 | */ |
286 | */ |
277 | long int strtol(const char *nptr, char **endptr, int base) |
287 | long int strtol(const char *nptr, char **endptr, int base) |
278 | { |
288 | { |
279 | char sgn = 0; |
289 | char sgn = 0; |
280 | unsigned long number = 0; |
290 | unsigned long number = 0; |
281 | 291 | ||
282 | number = _strtoul(nptr, endptr, base, &sgn); |
292 | number = _strtoul(nptr, endptr, base, &sgn); |
283 | 293 | ||
284 | if (number > LONG_MAX) { |
294 | if (number > LONG_MAX) { |
285 | if ((sgn) && (number == (unsigned long) (LONG_MAX) + 1)) { |
295 | if ((sgn) && (number == (unsigned long) (LONG_MAX) + 1)) { |
286 | /* FIXME: set 0 to errno */ |
296 | /* FIXME: set 0 to errno */ |
287 | return number; |
297 | return number; |
288 | } |
298 | } |
289 | /* FIXME: set ERANGE to errno */ |
299 | /* FIXME: set ERANGE to errno */ |
290 | return (sgn ? LONG_MIN : LONG_MAX); |
300 | return (sgn ? LONG_MIN : LONG_MAX); |
291 | } |
301 | } |
292 | 302 | ||
293 | return (sgn ? -number : number); |
303 | return (sgn ? -number : number); |
294 | } |
304 | } |
295 | 305 | ||
296 | 306 | ||
297 | /** Convert initial part of string to unsigned long according to given base. |
307 | /** Convert initial part of string to unsigned long according to given base. |
298 | * The number may begin with an arbitrary number of whitespaces followed by optional sign (`+' or `-'). |
308 | * The number may begin with an arbitrary number of whitespaces followed by optional sign (`+' or `-'). |
299 | * If the base is 0 or 16, the prefix `0x' may be inserted and the number will be taken as hexadecimal one. |
309 | * If the base is 0 or 16, the prefix `0x' may be inserted and the number will be taken as hexadecimal one. |
300 | * If the base is 0 and the number begin with a zero, number will be taken as octal one (as with base 8). |
310 | * If the base is 0 and the number begin with a zero, number will be taken as octal one (as with base 8). |
301 | * Otherwise the base 0 is taken as decimal. |
311 | * Otherwise the base 0 is taken as decimal. |
302 | * @param nptr pointer to string |
312 | * @param nptr pointer to string |
303 | * @param endptr if not NULL, function stores here pointer to the first invalid character |
313 | * @param endptr if not NULL, function stores here pointer to the first invalid character |
304 | * @param base zero or number between 2 and 36 inclusive |
314 | * @param base zero or number between 2 and 36 inclusive |
305 | * @return result of conversion. |
315 | * @return result of conversion. |
306 | */ |
316 | */ |
307 | unsigned long strtoul(const char *nptr, char **endptr, int base) |
317 | unsigned long strtoul(const char *nptr, char **endptr, int base) |
308 | { |
318 | { |
309 | char sgn = 0; |
319 | char sgn = 0; |
310 | unsigned long number = 0; |
320 | unsigned long number = 0; |
311 | 321 | ||
312 | number = _strtoul(nptr, endptr, base, &sgn); |
322 | number = _strtoul(nptr, endptr, base, &sgn); |
313 | 323 | ||
314 | return (sgn ? -number : number); |
324 | return (sgn ? -number : number); |
315 | } |
325 | } |
316 | 326 | ||
317 | char *strcpy(char *dest, const char *src) |
327 | char *strcpy(char *dest, const char *src) |
318 | { |
328 | { |
319 | char *orig = dest; |
329 | char *orig = dest; |
320 | 330 | ||
321 | while ((*(dest++) = *(src++))); |
331 | while ((*(dest++) = *(src++))); |
322 | return orig; |
332 | return orig; |
323 | } |
333 | } |
324 | 334 | ||
325 | char *strncpy(char *dest, const char *src, size_t n) |
335 | char *strncpy(char *dest, const char *src, size_t n) |
326 | { |
336 | { |
327 | char *orig = dest; |
337 | char *orig = dest; |
328 | 338 | ||
329 | while ((*(dest++) = *(src++)) && --n); |
339 | while ((*(dest++) = *(src++)) && --n); |
330 | return orig; |
340 | return orig; |
331 | } |
341 | } |
332 | 342 | ||
333 | /** @} |
343 | /** @} |
334 | */ |
344 | */ |
335 | 345 |