With “opendir” and “readdir” i do read a directories content.
During that process i do some strings manipulation / allocation:
something like that:
int stringlength = strlen(cur_dir)+strlen(ep->d_name)+2;
char *file_with_path = xmalloc(stringlength); //xmalloc is a malloc wrapper with some tests (like no more memory)
snprintf (file_with_path, (size_t)stringlength, "%s/%s", cur_dir, ep->d_name);
But what if a string contains a two-byte utf8 char?
How do you handle that issue?
stringlength*2?
Thanks
strlen()counts the bytes in the string, it doesn’t care if the contained bytes represent UTF-8 encoded Unicode characters. So, for example,strlen()of a string containing an UTF-8 encoding of “aöü” would return5, since the string is encoded as"a\xc3\xb6\xc3\xbc".