utflen.c 216 B

123456789101112131415161718192021
  1. #include "lib9.h"
  2. int
  3. utflen(char *s)
  4. {
  5. int c;
  6. long n;
  7. Rune rune;
  8. n = 0;
  9. for(;;) {
  10. c = *(uchar*)s;
  11. if(c < Runeself) {
  12. if(c == 0)
  13. return n;
  14. s++;
  15. } else
  16. s += chartorune(&rune, s);
  17. n++;
  18. }
  19. }