[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: strtok_r in glibc 2.0.7 bugginess



In message <5lbtjgn2iz.fsf@assaris.sics.se>, Assar Westerlund writes:
+-----
| "Brandon S. Allbery KF8NH" <allbery@kf8nh.apk.net> writes:
| > strtok() and strtok_r() are really pre-ANSI and in my experience are best 
| > avoided.
| 
| strtok() is ANSI but not reentrant, but I find strtok_r useful quite
| often.  What do you use instead?  strsep?
+--->8

It was imported into ANSI because it was commonly used, but it predates ANSI 
(it came from System III).

I generally write my own code in place to do such parsing, because most 
often I find myself needing to special case something --- formerly, needing 
a token separator which requires a special action (e.g. parsing "foo:bar" as 
two tokens but associating the result, but "foo : bar" has to mean something 
different) but more often these days because I end up needing to handle 
quoted strings.

Even in the quick-and-dirty cases like this one (deconstructing a 
parameter), I usually prefer to do it manually so I can provide better error 
checking/reporting.  Too many cases of quick'n'dirty coming back to haunt 
me, perhaps.

-- 
brandon s. allbery	[os/2][linux][solaris][japh]	 allbery@kf8nh.apk.net
system administrator	     [WAY too many hats]	   allbery@ece.cmu.edu
carnegie mellon / electrical and computer engineering			 KF8NH
     We are Linux. Resistance is an indication that you missed the point.