ucs2_string.c 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. #include <linux/ucs2_string.h>
  2. #include <linux/module.h>
  3. /* Return the number of unicode characters in data */
  4. unsigned long
  5. ucs2_strnlen(const ucs2_char_t *s, size_t maxlength)
  6. {
  7. unsigned long length = 0;
  8. while (*s++ != 0 && length < maxlength)
  9. length++;
  10. return length;
  11. }
  12. EXPORT_SYMBOL(ucs2_strnlen);
  13. unsigned long
  14. ucs2_strlen(const ucs2_char_t *s)
  15. {
  16. return ucs2_strnlen(s, ~0UL);
  17. }
  18. EXPORT_SYMBOL(ucs2_strlen);
  19. /*
  20. * Return the number of bytes is the length of this string
  21. * Note: this is NOT the same as the number of unicode characters
  22. */
  23. unsigned long
  24. ucs2_strsize(const ucs2_char_t *data, unsigned long maxlength)
  25. {
  26. return ucs2_strnlen(data, maxlength/sizeof(ucs2_char_t)) * sizeof(ucs2_char_t);
  27. }
  28. EXPORT_SYMBOL(ucs2_strsize);
  29. int
  30. ucs2_strncmp(const ucs2_char_t *a, const ucs2_char_t *b, size_t len)
  31. {
  32. while (1) {
  33. if (len == 0)
  34. return 0;
  35. if (*a < *b)
  36. return -1;
  37. if (*a > *b)
  38. return 1;
  39. if (*a == 0) /* implies *b == 0 */
  40. return 0;
  41. a++;
  42. b++;
  43. len--;
  44. }
  45. }
  46. EXPORT_SYMBOL(ucs2_strncmp);