string.c 1.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. /* -*- linux-c -*- ------------------------------------------------------- *
  2. *
  3. * Copyright (C) 1991, 1992 Linus Torvalds
  4. * Copyright 2007 rPath, Inc. - All Rights Reserved
  5. *
  6. * This file is part of the Linux kernel, and is made available under
  7. * the terms of the GNU General Public License version 2.
  8. *
  9. * ----------------------------------------------------------------------- */
  10. /*
  11. * arch/i386/boot/string.c
  12. *
  13. * Very basic string functions
  14. */
  15. #include "boot.h"
  16. int strcmp(const char *str1, const char *str2)
  17. {
  18. const unsigned char *s1 = (const unsigned char *)str1;
  19. const unsigned char *s2 = (const unsigned char *)str2;
  20. int delta = 0;
  21. while (*s1 || *s2) {
  22. delta = *s2 - *s1;
  23. if (delta)
  24. return delta;
  25. s1++;
  26. s2++;
  27. }
  28. return 0;
  29. }
  30. size_t strnlen(const char *s, size_t maxlen)
  31. {
  32. const char *es = s;
  33. while (*es && maxlen) {
  34. es++;
  35. maxlen--;
  36. }
  37. return (es - s);
  38. }
  39. unsigned int atou(const char *s)
  40. {
  41. unsigned int i = 0;
  42. while (isdigit(*s))
  43. i = i * 10 + (*s++ - '0');
  44. return i;
  45. }