Anders sends us an example which isn’t precisely a WTF. It’s just C handling C strings. Which, I guess, when I say it that way, is a WTF.
while(modPath != NULL) {
p = strchr(modPath, ':');
if(p != NULL) {
*p++ = ' ';
}
dvModpathCreate(utSymCreate(modPath));
modPath = p;
} while(modPath != NULL);
We start with a variable called modPath
which points to a C string. So long as modPath
is not null, we’re going to search through the string.
The string is in a :
separated format, e.g., foo:bar:goo
. We want to split it. This function does this by being very C about it.
It uses strchr
to find the address of the first colon. If we think about this in C strings, complete with null terminators, it looks something like this:
"foo:bar:goo "
^ ^
| |
| p
modPath
We then replace :
with