3 ms·
strtok_r() destructively modifies its input so wrapping it works against this library's objective of using const ponters. It is easy enough to reimplement, thou
by kevin_thibedeau 6y ago
strtok_r() destructively modifies its input so wrapping it works against this library's objective of using const ponters. It is easy enough to reimplement, though, and I've done this for similar sub-string pointer objects that work without NUL termination.
- souprock 6y agoThe existence of strtok_r() is weird anyway. If we can make errno thread-safe, there is no reason why plain strtok() can't be thread-safe. The idea that somebody wants strtok() state shared across threads is just as weird as the idea that errno should be shared across threads.
- kevin_thibedeau 6y agoThe C API was never designed with threading in mind. Not all platforms support threads so the old behavior must stay around.
- souprock 6y agoSay what? You like to call plain strtok() from different threads, having them all update a shared global state? I think you missed the point here, because that would be some really evil usage of the strtok() function. We had "int errno" as global state. We fixed it, in a compatible way, to be thread-safe. Platforms without threads can still implement it the old way if desired. The same kind of compatible fix could have been done with the strtok() function. There was no need to introduce another function. Simply: the internal state of strtok() shall be distinct for each thread. (which is trivial if the platform only supports a single thread)