preliminary thread safety fix (strtok_r)

based on a patch by Prabhat Ranjan Kanth,
still needs a solution for platforms w/o strtok_r