The strtok_s function exists in vc8 but not in vc7. So what’s a function (or code) that does the equivalent of strtok_s in vc7?
Share
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Take a look at this MSDN page.
As far as I can tell, the security enhancements a) Make strtok() reentrant (and thread-safe) by having it take a ‘context’ parameter and b) Make it safe to use with NULL pointers. (The actual behaviors in the case of NULL parameters are listed in a table on the page I’ve linked.)
As for a VC7 alternative, you’ll have to write (or import) one yourself. The NULL-safety is easy to do externally, you’ll just have to be careful not to pass NULL strings where none are expected; but as far as reentrancy goes, there’s no way for strtok() to handle that.
Take a look at this and this question. I believe POSIX also supplies a reentrant version of strtok() called strtok_r(); you can search for it. It would also be a good (and short) exercise to write an implementation yourself. Shouldn’t take more than ~10 lines of code.