Changeset 838e14e2 in mainline
- Timestamp:
- 2008-08-09T22:14:20Z (16 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- 0516fd7
- Parents:
- b3105ff6
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/lib/libc/generic/string.c
rb3105ff6 r838e14e2 67 67 68 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] = 70 ((unsigned char *) (((unsigned long *) src) + i))[j]; 70 71 71 72 return (char *) src; … … 76 77 int i, j; 77 78 78 if (((long) dst & (sizeof(long) - 1)) || ((long) src & (sizeof(long) - 1))) 79 if (((long) dst & (sizeof(long) - 1)) || 80 ((long) src & (sizeof(long) - 1))) 79 81 return unaligned_memcpy(dst, src, n); 80 82 … … 83 85 84 86 for (j = 0; j < n % sizeof(unsigned long); j++) 85 ((unsigned char *) (((unsigned long *) dst) + i))[j] = ((unsigned char *) (((unsigned long *) src) + i))[j]; 87 ((unsigned char *) (((unsigned long *) dst) + i))[j] = 88 ((unsigned char *) (((unsigned long *) src) + i))[j]; 86 89 87 90 return (char *) src; … … 96 99 97 100 for (j = (n % sizeof(unsigned long)) - 1; j >= 0; j--) 98 ((unsigned char *) ((unsigned long *) dst))[j] = ((unsigned char *) ((unsigned long *) src))[j]; 101 ((unsigned char *) ((unsigned long *) dst))[j] = 102 ((unsigned char *) ((unsigned long *) src))[j]; 99 103 100 104 for (i = n / sizeof(unsigned long) - 1; i >=0 ; i--) … … 106 110 /** Compare two memory areas. 107 111 * 108 * @param s1 Pointer to the first 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 same111 * 112 * @return If len is 0, return zero. If the areas match, return zero.113 * 112 * @param s1 Pointer to the first area to compare. 113 * @param s2 Pointer to the second area to compare. 114 * @param len Size of the first area in bytes. Both areas must have 115 * the same length. 116 * @return If len is 0, return zero. If the areas match, return 117 * zero. Otherwise return non-zero. 114 118 */ 115 119 int bcmp(const char *s1, const char *s2, size_t len) … … 121 125 122 126 /** Count the number of characters in the string, not including terminating 0. 123 * @param str string 124 * @return number of characters in string. 127 * 128 * @param str String. 129 * @return Number of characters in string. 125 130 */ 126 131 size_t strlen(const char *str) … … 156 161 } 157 162 158 /** Return pointer to the first occurence of character c in string 159 * @param str scanned string 160 * @param c searched character (taken as one byte) 161 * @return pointer to the matched character or NULL if it is not found in given string. 163 /** Return pointer to the first occurence of character c in string. 164 * 165 * @param str Scanned string. 166 * @param c Searched character (taken as one byte). 167 * @return Pointer to the matched character or NULL if it is not 168 * found in given string. 162 169 */ 163 170 char *strchr(const char *str, int c) … … 172 179 } 173 180 174 /** Return pointer to the last occurence of character c in string 175 * @param str scanned string 176 * @param c searched character (taken as one byte) 177 * @return pointer to the matched character or NULL if it is not found in given string. 181 /** Return pointer to the last occurence of character c in string. 182 * 183 * @param str Scanned string. 184 * @param c Searched character (taken as one byte). 185 * @return Pointer to the matched character or NULL if it is not 186 * found in given string. 178 187 */ 179 188 char *strrchr(const char *str, int c) … … 192 201 /** Convert string to a number. 193 202 * Core of strtol and strtoul functions. 194 * @param nptr pointer to string 195 * @param endptr if not NULL, function stores here pointer to the first invalid character 196 * @param base zero or number between 2 and 36 inclusive 197 * @param sgn its set to 1 if minus found 198 * @return result of conversion. 199 */ 200 static unsigned long _strtoul(const char *nptr, char **endptr, int base, char *sgn) 203 * 204 * @param nptr Pointer to string. 205 * @param endptr If not NULL, function stores here pointer to the first 206 * invalid character. 207 * @param base Zero or number between 2 and 36 inclusive. 208 * @param sgn It's set to 1 if minus found. 209 * @return Result of conversion. 210 */ 211 static unsigned long 212 _strtoul(const char *nptr, char **endptr, int base, char *sgn) 201 213 { 202 214 unsigned char c; … … 220 232 return 0; 221 233 } 222 if ((base == 16) && (*str == '0') && ((str[1] == 'x') || (str[1] == 'X'))) { 234 if ((base == 16) && (*str == '0') && ((str[1] == 'x') || 235 (str[1] == 'X'))) { 223 236 str += 2; 224 237 } … … 239 252 while (*str) { 240 253 c = *str; 241 c = (c >= 'a' ? c - 'a' + 10 : (c >= 'A' ? c - 'A' + 10 : (c <= '9' ? c - '0' : 0xff))); 254 c = (c >= 'a' ? c - 'a' + 10 : (c >= 'A' ? c - 'A' + 10 : 255 (c <= '9' ? c - '0' : 0xff))); 242 256 if (c > base) { 243 257 break; … … 258 272 259 273 if (str == tmpptr) { 260 /* no number was found => first invalid character is the first character of the string */ 274 /* 275 * No number was found => first invalid character is the first 276 * character of the string. 277 */ 261 278 /* FIXME: set errno to EINVAL */ 262 279 str = nptr; … … 276 293 277 294 /** Convert initial part of string to long int according to given base. 278 * The number may begin with an arbitrary number of whitespaces followed by optional sign (`+' or `-'). 279 * If the base is 0 or 16, the prefix `0x' may be inserted and the number will be taken as hexadecimal one. 280 * If the base is 0 and the number begin with a zero, number will be taken as octal one (as with base 8). 281 * Otherwise the base 0 is taken as decimal. 282 * @param nptr pointer to string 283 * @param endptr if not NULL, function stores here pointer to the first invalid character 284 * @param base zero or number between 2 and 36 inclusive 285 * @return result of conversion. 295 * The number may begin with an arbitrary number of whitespaces followed by 296 * optional sign (`+' or `-'). If the base is 0 or 16, the prefix `0x' may be 297 * inserted and the number will be taken as hexadecimal one. If the base is 0 298 * and the number begin with a zero, number will be taken as octal one (as with 299 * base 8). Otherwise the base 0 is taken as decimal. 300 * 301 * @param nptr Pointer to string. 302 * @param endptr If not NULL, function stores here pointer to the first 303 * invalid character. 304 * @param base Zero or number between 2 and 36 inclusive. 305 * @return Result of conversion. 286 306 */ 287 307 long int strtol(const char *nptr, char **endptr, int base) … … 306 326 307 327 /** Convert initial part of string to unsigned long according to given base. 308 * The number may begin with an arbitrary number of whitespaces followed by optional sign (`+' or `-'). 309 * If the base is 0 or 16, the prefix `0x' may be inserted and the number will be taken as hexadecimal one. 310 * If the base is 0 and the number begin with a zero, number will be taken as octal one (as with base 8). 311 * Otherwise the base 0 is taken as decimal. 312 * @param nptr pointer to string 313 * @param endptr if not NULL, function stores here pointer to the first invalid character 314 * @param base zero or number between 2 and 36 inclusive 315 * @return result of conversion. 328 * The number may begin with an arbitrary number of whitespaces followed by 329 * optional sign (`+' or `-'). If the base is 0 or 16, the prefix `0x' may be 330 * inserted and the number will be taken as hexadecimal one. If the base is 0 331 * and the number begin with a zero, number will be taken as octal one (as with 332 * base 8). Otherwise the base 0 is taken as decimal. 333 * 334 * @param nptr Pointer to string. 335 * @param endptr If not NULL, function stores here pointer to the first 336 * invalid character 337 * @param base Zero or number between 2 and 36 inclusive. 338 * @return Result of conversion. 316 339 */ 317 340 unsigned long strtoul(const char *nptr, char **endptr, int base)
Note:
See TracChangeset
for help on using the changeset viewer.