string.c 995 B

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  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. * Very basic string functions
  12. */
  13. #include "boot.h"
  14. int strcmp(const char *str1, const char *str2)
  15. {
  16. const unsigned char *s1 = (const unsigned char *)str1;
  17. const unsigned char *s2 = (const unsigned char *)str2;
  18. int delta = 0;
  19. while (*s1 || *s2) {
  20. delta = *s2 - *s1;
  21. if (delta)
  22. return delta;
  23. s1++;
  24. s2++;
  25. }
  26. return 0;
  27. }
  28. size_t strnlen(const char *s, size_t maxlen)
  29. {
  30. const char *es = s;
  31. while (*es && maxlen) {
  32. es++;
  33. maxlen--;
  34. }
  35. return (es - s);
  36. }
  37. unsigned int atou(const char *s)
  38. {
  39. unsigned int i = 0;
  40. while (isdigit(*s))
  41. i = i * 10 + (*s++ - '0');
  42. return i;
  43. }