ia64/linux-2.6.18-xen.hg

annotate lib/string.c @ 782:9ab1c319531f

merge with linux-2.6.18-xen.hg
author Isaku Yamahata <yamahata@valinux.co.jp>
date Wed Jan 28 13:07:23 2009 +0900 (2009-01-28)
parents 831230e53067
children
rev   line source
ian@0 1 /*
ian@0 2 * linux/lib/string.c
ian@0 3 *
ian@0 4 * Copyright (C) 1991, 1992 Linus Torvalds
ian@0 5 */
ian@0 6
ian@0 7 /*
ian@0 8 * stupid library routines.. The optimized versions should generally be found
ian@0 9 * as inline code in <asm-xx/string.h>
ian@0 10 *
ian@0 11 * These are buggy as well..
ian@0 12 *
ian@0 13 * * Fri Jun 25 1999, Ingo Oeser <ioe@informatik.tu-chemnitz.de>
ian@0 14 * - Added strsep() which will replace strtok() soon (because strsep() is
ian@0 15 * reentrant and should be faster). Use only strsep() in new code, please.
ian@0 16 *
ian@0 17 * * Sat Feb 09 2002, Jason Thomas <jason@topic.com.au>,
ian@0 18 * Matthew Hawkins <matt@mh.dropbear.id.au>
ian@0 19 * - Kissed strtok() goodbye
ian@0 20 */
ian@0 21
ian@0 22 #include <linux/types.h>
ian@0 23 #include <linux/string.h>
ian@0 24 #include <linux/ctype.h>
ian@0 25 #include <linux/module.h>
ian@0 26
ian@0 27 #ifndef __HAVE_ARCH_STRNICMP
ian@0 28 /**
ian@0 29 * strnicmp - Case insensitive, length-limited string comparison
ian@0 30 * @s1: One string
ian@0 31 * @s2: The other string
ian@0 32 * @len: the maximum number of characters to compare
ian@0 33 */
ian@0 34 int strnicmp(const char *s1, const char *s2, size_t len)
ian@0 35 {
ian@0 36 /* Yes, Virginia, it had better be unsigned */
ian@0 37 unsigned char c1, c2;
ian@0 38
ian@0 39 c1 = c2 = 0;
ian@0 40 if (len) {
ian@0 41 do {
ian@0 42 c1 = *s1;
ian@0 43 c2 = *s2;
ian@0 44 s1++;
ian@0 45 s2++;
ian@0 46 if (!c1)
ian@0 47 break;
ian@0 48 if (!c2)
ian@0 49 break;
ian@0 50 if (c1 == c2)
ian@0 51 continue;
ian@0 52 c1 = tolower(c1);
ian@0 53 c2 = tolower(c2);
ian@0 54 if (c1 != c2)
ian@0 55 break;
ian@0 56 } while (--len);
ian@0 57 }
ian@0 58 return (int)c1 - (int)c2;
ian@0 59 }
ian@0 60 EXPORT_SYMBOL(strnicmp);
ian@0 61 #endif
ian@0 62
ian@0 63 #ifndef __HAVE_ARCH_STRCPY
ian@0 64 /**
ian@0 65 * strcpy - Copy a %NUL terminated string
ian@0 66 * @dest: Where to copy the string to
ian@0 67 * @src: Where to copy the string from
ian@0 68 */
ian@0 69 #undef strcpy
ian@0 70 char *strcpy(char *dest, const char *src)
ian@0 71 {
ian@0 72 char *tmp = dest;
ian@0 73
ian@0 74 while ((*dest++ = *src++) != '\0')
ian@0 75 /* nothing */;
ian@0 76 return tmp;
ian@0 77 }
ian@0 78 EXPORT_SYMBOL(strcpy);
ian@0 79 #endif
ian@0 80
ian@0 81 #ifndef __HAVE_ARCH_STRNCPY
ian@0 82 /**
ian@0 83 * strncpy - Copy a length-limited, %NUL-terminated string
ian@0 84 * @dest: Where to copy the string to
ian@0 85 * @src: Where to copy the string from
ian@0 86 * @count: The maximum number of bytes to copy
ian@0 87 *
ian@0 88 * The result is not %NUL-terminated if the source exceeds
ian@0 89 * @count bytes.
ian@0 90 *
ian@0 91 * In the case where the length of @src is less than that of
ian@0 92 * count, the remainder of @dest will be padded with %NUL.
ian@0 93 *
ian@0 94 */
ian@0 95 char *strncpy(char *dest, const char *src, size_t count)
ian@0 96 {
ian@0 97 char *tmp = dest;
ian@0 98
ian@0 99 while (count) {
ian@0 100 if ((*tmp = *src) != 0)
ian@0 101 src++;
ian@0 102 tmp++;
ian@0 103 count--;
ian@0 104 }
ian@0 105 return dest;
ian@0 106 }
ian@0 107 EXPORT_SYMBOL(strncpy);
ian@0 108 #endif
ian@0 109
ian@0 110 #ifndef __HAVE_ARCH_STRLCPY
ian@0 111 /**
ian@0 112 * strlcpy - Copy a %NUL terminated string into a sized buffer
ian@0 113 * @dest: Where to copy the string to
ian@0 114 * @src: Where to copy the string from
ian@0 115 * @size: size of destination buffer
ian@0 116 *
ian@0 117 * Compatible with *BSD: the result is always a valid
ian@0 118 * NUL-terminated string that fits in the buffer (unless,
ian@0 119 * of course, the buffer size is zero). It does not pad
ian@0 120 * out the result like strncpy() does.
ian@0 121 */
ian@0 122 size_t strlcpy(char *dest, const char *src, size_t size)
ian@0 123 {
ian@0 124 size_t ret = strlen(src);
ian@0 125
ian@0 126 if (size) {
ian@0 127 size_t len = (ret >= size) ? size - 1 : ret;
ian@0 128 memcpy(dest, src, len);
ian@0 129 dest[len] = '\0';
ian@0 130 }
ian@0 131 return ret;
ian@0 132 }
ian@0 133 EXPORT_SYMBOL(strlcpy);
ian@0 134 #endif
ian@0 135
ian@0 136 #ifndef __HAVE_ARCH_STRCAT
ian@0 137 /**
ian@0 138 * strcat - Append one %NUL-terminated string to another
ian@0 139 * @dest: The string to be appended to
ian@0 140 * @src: The string to append to it
ian@0 141 */
ian@0 142 #undef strcat
ian@0 143 char *strcat(char *dest, const char *src)
ian@0 144 {
ian@0 145 char *tmp = dest;
ian@0 146
ian@0 147 while (*dest)
ian@0 148 dest++;
ian@0 149 while ((*dest++ = *src++) != '\0')
ian@0 150 ;
ian@0 151 return tmp;
ian@0 152 }
ian@0 153 EXPORT_SYMBOL(strcat);
ian@0 154 #endif
ian@0 155
ian@0 156 #ifndef __HAVE_ARCH_STRNCAT
ian@0 157 /**
ian@0 158 * strncat - Append a length-limited, %NUL-terminated string to another
ian@0 159 * @dest: The string to be appended to
ian@0 160 * @src: The string to append to it
ian@0 161 * @count: The maximum numbers of bytes to copy
ian@0 162 *
ian@0 163 * Note that in contrast to strncpy, strncat ensures the result is
ian@0 164 * terminated.
ian@0 165 */
ian@0 166 char *strncat(char *dest, const char *src, size_t count)
ian@0 167 {
ian@0 168 char *tmp = dest;
ian@0 169
ian@0 170 if (count) {
ian@0 171 while (*dest)
ian@0 172 dest++;
ian@0 173 while ((*dest++ = *src++) != 0) {
ian@0 174 if (--count == 0) {
ian@0 175 *dest = '\0';
ian@0 176 break;
ian@0 177 }
ian@0 178 }
ian@0 179 }
ian@0 180 return tmp;
ian@0 181 }
ian@0 182 EXPORT_SYMBOL(strncat);
ian@0 183 #endif
ian@0 184
ian@0 185 #ifndef __HAVE_ARCH_STRLCAT
ian@0 186 /**
ian@0 187 * strlcat - Append a length-limited, %NUL-terminated string to another
ian@0 188 * @dest: The string to be appended to
ian@0 189 * @src: The string to append to it
ian@0 190 * @count: The size of the destination buffer.
ian@0 191 */
ian@0 192 size_t strlcat(char *dest, const char *src, size_t count)
ian@0 193 {
ian@0 194 size_t dsize = strlen(dest);
ian@0 195 size_t len = strlen(src);
ian@0 196 size_t res = dsize + len;
ian@0 197
ian@0 198 /* This would be a bug */
ian@0 199 BUG_ON(dsize >= count);
ian@0 200
ian@0 201 dest += dsize;
ian@0 202 count -= dsize;
ian@0 203 if (len >= count)
ian@0 204 len = count-1;
ian@0 205 memcpy(dest, src, len);
ian@0 206 dest[len] = 0;
ian@0 207 return res;
ian@0 208 }
ian@0 209 EXPORT_SYMBOL(strlcat);
ian@0 210 #endif
ian@0 211
ian@0 212 #ifndef __HAVE_ARCH_STRCMP
ian@0 213 /**
ian@0 214 * strcmp - Compare two strings
ian@0 215 * @cs: One string
ian@0 216 * @ct: Another string
ian@0 217 */
ian@0 218 #undef strcmp
ian@0 219 int strcmp(const char *cs, const char *ct)
ian@0 220 {
ian@0 221 signed char __res;
ian@0 222
ian@0 223 while (1) {
ian@0 224 if ((__res = *cs - *ct++) != 0 || !*cs++)
ian@0 225 break;
ian@0 226 }
ian@0 227 return __res;
ian@0 228 }
ian@0 229 EXPORT_SYMBOL(strcmp);
ian@0 230 #endif
ian@0 231
ian@0 232 #ifndef __HAVE_ARCH_STRNCMP
ian@0 233 /**
ian@0 234 * strncmp - Compare two length-limited strings
ian@0 235 * @cs: One string
ian@0 236 * @ct: Another string
ian@0 237 * @count: The maximum number of bytes to compare
ian@0 238 */
ian@0 239 int strncmp(const char *cs, const char *ct, size_t count)
ian@0 240 {
ian@0 241 signed char __res = 0;
ian@0 242
ian@0 243 while (count) {
ian@0 244 if ((__res = *cs - *ct++) != 0 || !*cs++)
ian@0 245 break;
ian@0 246 count--;
ian@0 247 }
ian@0 248 return __res;
ian@0 249 }
ian@0 250 EXPORT_SYMBOL(strncmp);
ian@0 251 #endif
ian@0 252
ian@0 253 #ifndef __HAVE_ARCH_STRCHR
ian@0 254 /**
ian@0 255 * strchr - Find the first occurrence of a character in a string
ian@0 256 * @s: The string to be searched
ian@0 257 * @c: The character to search for
ian@0 258 */
ian@0 259 char *strchr(const char *s, int c)
ian@0 260 {
ian@0 261 for (; *s != (char)c; ++s)
ian@0 262 if (*s == '\0')
ian@0 263 return NULL;
ian@0 264 return (char *)s;
ian@0 265 }
ian@0 266 EXPORT_SYMBOL(strchr);
ian@0 267 #endif
ian@0 268
ian@0 269 #ifndef __HAVE_ARCH_STRRCHR
ian@0 270 /**
ian@0 271 * strrchr - Find the last occurrence of a character in a string
ian@0 272 * @s: The string to be searched
ian@0 273 * @c: The character to search for
ian@0 274 */
ian@0 275 char *strrchr(const char *s, int c)
ian@0 276 {
ian@0 277 const char *p = s + strlen(s);
ian@0 278 do {
ian@0 279 if (*p == (char)c)
ian@0 280 return (char *)p;
ian@0 281 } while (--p >= s);
ian@0 282 return NULL;
ian@0 283 }
ian@0 284 EXPORT_SYMBOL(strrchr);
ian@0 285 #endif
ian@0 286
ian@0 287 #ifndef __HAVE_ARCH_STRNCHR
ian@0 288 /**
ian@0 289 * strnchr - Find a character in a length limited string
ian@0 290 * @s: The string to be searched
ian@0 291 * @count: The number of characters to be searched
ian@0 292 * @c: The character to search for
ian@0 293 */
ian@0 294 char *strnchr(const char *s, size_t count, int c)
ian@0 295 {
ian@0 296 for (; count-- && *s != '\0'; ++s)
ian@0 297 if (*s == (char)c)
ian@0 298 return (char *)s;
ian@0 299 return NULL;
ian@0 300 }
ian@0 301 EXPORT_SYMBOL(strnchr);
ian@0 302 #endif
ian@0 303
ian@0 304 /**
ian@0 305 * strstrip - Removes leading and trailing whitespace from @s.
ian@0 306 * @s: The string to be stripped.
ian@0 307 *
ian@0 308 * Note that the first trailing whitespace is replaced with a %NUL-terminator
ian@0 309 * in the given string @s. Returns a pointer to the first non-whitespace
ian@0 310 * character in @s.
ian@0 311 */
ian@0 312 char *strstrip(char *s)
ian@0 313 {
ian@0 314 size_t size;
ian@0 315 char *end;
ian@0 316
ian@0 317 size = strlen(s);
ian@0 318
ian@0 319 if (!size)
ian@0 320 return s;
ian@0 321
ian@0 322 end = s + size - 1;
ian@0 323 while (end != s && isspace(*end))
ian@0 324 end--;
ian@0 325 *(end + 1) = '\0';
ian@0 326
ian@0 327 while (*s && isspace(*s))
ian@0 328 s++;
ian@0 329
ian@0 330 return s;
ian@0 331 }
ian@0 332 EXPORT_SYMBOL(strstrip);
ian@0 333
ian@0 334 #ifndef __HAVE_ARCH_STRLEN
ian@0 335 /**
ian@0 336 * strlen - Find the length of a string
ian@0 337 * @s: The string to be sized
ian@0 338 */
ian@0 339 size_t strlen(const char *s)
ian@0 340 {
ian@0 341 const char *sc;
ian@0 342
ian@0 343 for (sc = s; *sc != '\0'; ++sc)
ian@0 344 /* nothing */;
ian@0 345 return sc - s;
ian@0 346 }
ian@0 347 EXPORT_SYMBOL(strlen);
ian@0 348 #endif
ian@0 349
ian@0 350 #ifndef __HAVE_ARCH_STRNLEN
ian@0 351 /**
ian@0 352 * strnlen - Find the length of a length-limited string
ian@0 353 * @s: The string to be sized
ian@0 354 * @count: The maximum number of bytes to search
ian@0 355 */
ian@0 356 size_t strnlen(const char *s, size_t count)
ian@0 357 {
ian@0 358 const char *sc;
ian@0 359
ian@0 360 for (sc = s; count-- && *sc != '\0'; ++sc)
ian@0 361 /* nothing */;
ian@0 362 return sc - s;
ian@0 363 }
ian@0 364 EXPORT_SYMBOL(strnlen);
ian@0 365 #endif
ian@0 366
ian@0 367 #ifndef __HAVE_ARCH_STRSPN
ian@0 368 /**
ian@0 369 * strspn - Calculate the length of the initial substring of @s which only
ian@0 370 * contain letters in @accept
ian@0 371 * @s: The string to be searched
ian@0 372 * @accept: The string to search for
ian@0 373 */
ian@0 374 size_t strspn(const char *s, const char *accept)
ian@0 375 {
ian@0 376 const char *p;
ian@0 377 const char *a;
ian@0 378 size_t count = 0;
ian@0 379
ian@0 380 for (p = s; *p != '\0'; ++p) {
ian@0 381 for (a = accept; *a != '\0'; ++a) {
ian@0 382 if (*p == *a)
ian@0 383 break;
ian@0 384 }
ian@0 385 if (*a == '\0')
ian@0 386 return count;
ian@0 387 ++count;
ian@0 388 }
ian@0 389 return count;
ian@0 390 }
ian@0 391
ian@0 392 EXPORT_SYMBOL(strspn);
ian@0 393 #endif
ian@0 394
ian@0 395 #ifndef __HAVE_ARCH_STRCSPN
ian@0 396 /**
ian@0 397 * strcspn - Calculate the length of the initial substring of @s which does
ian@0 398 * not contain letters in @reject
ian@0 399 * @s: The string to be searched
ian@0 400 * @reject: The string to avoid
ian@0 401 */
ian@0 402 size_t strcspn(const char *s, const char *reject)
ian@0 403 {
ian@0 404 const char *p;
ian@0 405 const char *r;
ian@0 406 size_t count = 0;
ian@0 407
ian@0 408 for (p = s; *p != '\0'; ++p) {
ian@0 409 for (r = reject; *r != '\0'; ++r) {
ian@0 410 if (*p == *r)
ian@0 411 return count;
ian@0 412 }
ian@0 413 ++count;
ian@0 414 }
ian@0 415 return count;
ian@0 416 }
ian@0 417 EXPORT_SYMBOL(strcspn);
ian@0 418 #endif
ian@0 419
ian@0 420 #ifndef __HAVE_ARCH_STRPBRK
ian@0 421 /**
ian@0 422 * strpbrk - Find the first occurrence of a set of characters
ian@0 423 * @cs: The string to be searched
ian@0 424 * @ct: The characters to search for
ian@0 425 */
ian@0 426 char *strpbrk(const char *cs, const char *ct)
ian@0 427 {
ian@0 428 const char *sc1, *sc2;
ian@0 429
ian@0 430 for (sc1 = cs; *sc1 != '\0'; ++sc1) {
ian@0 431 for (sc2 = ct; *sc2 != '\0'; ++sc2) {
ian@0 432 if (*sc1 == *sc2)
ian@0 433 return (char *)sc1;
ian@0 434 }
ian@0 435 }
ian@0 436 return NULL;
ian@0 437 }
ian@0 438 EXPORT_SYMBOL(strpbrk);
ian@0 439 #endif
ian@0 440
ian@0 441 #ifndef __HAVE_ARCH_STRSEP
ian@0 442 /**
ian@0 443 * strsep - Split a string into tokens
ian@0 444 * @s: The string to be searched
ian@0 445 * @ct: The characters to search for
ian@0 446 *
ian@0 447 * strsep() updates @s to point after the token, ready for the next call.
ian@0 448 *
ian@0 449 * It returns empty tokens, too, behaving exactly like the libc function
ian@0 450 * of that name. In fact, it was stolen from glibc2 and de-fancy-fied.
ian@0 451 * Same semantics, slimmer shape. ;)
ian@0 452 */
ian@0 453 char *strsep(char **s, const char *ct)
ian@0 454 {
ian@0 455 char *sbegin = *s;
ian@0 456 char *end;
ian@0 457
ian@0 458 if (sbegin == NULL)
ian@0 459 return NULL;
ian@0 460
ian@0 461 end = strpbrk(sbegin, ct);
ian@0 462 if (end)
ian@0 463 *end++ = '\0';
ian@0 464 *s = end;
ian@0 465 return sbegin;
ian@0 466 }
ian@0 467 EXPORT_SYMBOL(strsep);
ian@0 468 #endif
ian@0 469
ian@0 470 #ifndef __HAVE_ARCH_MEMSET
ian@0 471 /**
ian@0 472 * memset - Fill a region of memory with the given value
ian@0 473 * @s: Pointer to the start of the area.
ian@0 474 * @c: The byte to fill the area with
ian@0 475 * @count: The size of the area.
ian@0 476 *
ian@0 477 * Do not use memset() to access IO space, use memset_io() instead.
ian@0 478 */
ian@0 479 void *memset(void *s, int c, size_t count)
ian@0 480 {
ian@0 481 char *xs = s;
ian@0 482
ian@0 483 while (count--)
ian@0 484 *xs++ = c;
ian@0 485 return s;
ian@0 486 }
ian@0 487 EXPORT_SYMBOL(memset);
ian@0 488 #endif
ian@0 489
ian@0 490 #ifndef __HAVE_ARCH_MEMCPY
ian@0 491 /**
ian@0 492 * memcpy - Copy one area of memory to another
ian@0 493 * @dest: Where to copy to
ian@0 494 * @src: Where to copy from
ian@0 495 * @count: The size of the area.
ian@0 496 *
ian@0 497 * You should not use this function to access IO space, use memcpy_toio()
ian@0 498 * or memcpy_fromio() instead.
ian@0 499 */
ian@0 500 void *memcpy(void *dest, const void *src, size_t count)
ian@0 501 {
ian@0 502 char *tmp = dest;
ian@0 503 const char *s = src;
ian@0 504
ian@0 505 while (count--)
ian@0 506 *tmp++ = *s++;
ian@0 507 return dest;
ian@0 508 }
ian@0 509 EXPORT_SYMBOL(memcpy);
ian@0 510 #endif
ian@0 511
ian@0 512 #ifndef __HAVE_ARCH_MEMMOVE
ian@0 513 /**
ian@0 514 * memmove - Copy one area of memory to another
ian@0 515 * @dest: Where to copy to
ian@0 516 * @src: Where to copy from
ian@0 517 * @count: The size of the area.
ian@0 518 *
ian@0 519 * Unlike memcpy(), memmove() copes with overlapping areas.
ian@0 520 */
ian@0 521 void *memmove(void *dest, const void *src, size_t count)
ian@0 522 {
ian@0 523 char *tmp;
ian@0 524 const char *s;
ian@0 525
ian@0 526 if (dest <= src) {
ian@0 527 tmp = dest;
ian@0 528 s = src;
ian@0 529 while (count--)
ian@0 530 *tmp++ = *s++;
ian@0 531 } else {
ian@0 532 tmp = dest;
ian@0 533 tmp += count;
ian@0 534 s = src;
ian@0 535 s += count;
ian@0 536 while (count--)
ian@0 537 *--tmp = *--s;
ian@0 538 }
ian@0 539 return dest;
ian@0 540 }
ian@0 541 EXPORT_SYMBOL(memmove);
ian@0 542 #endif
ian@0 543
ian@0 544 #ifndef __HAVE_ARCH_MEMCMP
ian@0 545 /**
ian@0 546 * memcmp - Compare two areas of memory
ian@0 547 * @cs: One area of memory
ian@0 548 * @ct: Another area of memory
ian@0 549 * @count: The size of the area.
ian@0 550 */
ian@0 551 #undef memcmp
ian@0 552 int memcmp(const void *cs, const void *ct, size_t count)
ian@0 553 {
ian@0 554 const unsigned char *su1, *su2;
ian@0 555 int res = 0;
ian@0 556
ian@0 557 for (su1 = cs, su2 = ct; 0 < count; ++su1, ++su2, count--)
ian@0 558 if ((res = *su1 - *su2) != 0)
ian@0 559 break;
ian@0 560 return res;
ian@0 561 }
ian@0 562 EXPORT_SYMBOL(memcmp);
ian@0 563 #endif
ian@0 564
ian@0 565 #ifndef __HAVE_ARCH_MEMSCAN
ian@0 566 /**
ian@0 567 * memscan - Find a character in an area of memory.
ian@0 568 * @addr: The memory area
ian@0 569 * @c: The byte to search for
ian@0 570 * @size: The size of the area.
ian@0 571 *
ian@0 572 * returns the address of the first occurrence of @c, or 1 byte past
ian@0 573 * the area if @c is not found
ian@0 574 */
ian@0 575 void *memscan(void *addr, int c, size_t size)
ian@0 576 {
ian@0 577 unsigned char *p = addr;
ian@0 578
ian@0 579 while (size) {
ian@0 580 if (*p == c)
ian@0 581 return (void *)p;
ian@0 582 p++;
ian@0 583 size--;
ian@0 584 }
ian@0 585 return (void *)p;
ian@0 586 }
ian@0 587 EXPORT_SYMBOL(memscan);
ian@0 588 #endif
ian@0 589
ian@0 590 #ifndef __HAVE_ARCH_STRSTR
ian@0 591 /**
ian@0 592 * strstr - Find the first substring in a %NUL terminated string
ian@0 593 * @s1: The string to be searched
ian@0 594 * @s2: The string to search for
ian@0 595 */
ian@0 596 char *strstr(const char *s1, const char *s2)
ian@0 597 {
ian@0 598 int l1, l2;
ian@0 599
ian@0 600 l2 = strlen(s2);
ian@0 601 if (!l2)
ian@0 602 return (char *)s1;
ian@0 603 l1 = strlen(s1);
ian@0 604 while (l1 >= l2) {
ian@0 605 l1--;
ian@0 606 if (!memcmp(s1, s2, l2))
ian@0 607 return (char *)s1;
ian@0 608 s1++;
ian@0 609 }
ian@0 610 return NULL;
ian@0 611 }
ian@0 612 EXPORT_SYMBOL(strstr);
ian@0 613 #endif
ian@0 614
ian@0 615 #ifndef __HAVE_ARCH_MEMCHR
ian@0 616 /**
ian@0 617 * memchr - Find a character in an area of memory.
ian@0 618 * @s: The memory area
ian@0 619 * @c: The byte to search for
ian@0 620 * @n: The size of the area.
ian@0 621 *
ian@0 622 * returns the address of the first occurrence of @c, or %NULL
ian@0 623 * if @c is not found
ian@0 624 */
ian@0 625 void *memchr(const void *s, int c, size_t n)
ian@0 626 {
ian@0 627 const unsigned char *p = s;
ian@0 628 while (n-- != 0) {
ian@0 629 if ((unsigned char)c == *p++) {
ian@0 630 return (void *)(p - 1);
ian@0 631 }
ian@0 632 }
ian@0 633 return NULL;
ian@0 634 }
ian@0 635 EXPORT_SYMBOL(memchr);
ian@0 636 #endif