int utf8_strlen(char *ptr) { int len = 0; while (*ptr) { if (((*ptr & 0xC0) != 0x80) { len++; } ptr++; } return len; }