What is Nostr?
gentoobro /
npub1hap…jkkv
2024-09-03 04:39:09
in reply to nevent1q…5z5n

gentoobro on Nostr: Yes. There's basically no reason to use strtok ever. You can't (shouldn't) modify ...

Yes. There's basically no reason to use strtok ever. You can't (shouldn't) modify string literals, so it's possible that you could segfault if a pointer to a string literal got passed to strtok, depending on your system and if it locks the section containing the memory for string literals. Also, if I recall, it's not reentrant.

A basic loop with strchr can replace it, though in modern not-super-performance-sensitive code you really should just write a function like char\*\* strsplit(char\* in, char\* sep) that returns a malloc'd, null-terminated list of pointers to malloc'd null-terminated strings. Memory allocation is not the super slow bugbear it used to be.
Author Public Key
npub1hap4f3j40p06jdjde9yeh5k85sdvhw4p00mh3kthnq744j9y8zcsuvjkkv