This is the mail archive of the libstdc++@gcc.gnu.org mailing list for the libstdc++ project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[PATCH] Prefer strtok_r to strtok


Ok, lesson learned...

I don't think we should really autoconf for strtok_r: is in Posix
and similarly we already use strdup, which is also non standard.

Tested x86-linux.

Ok?

//////////////
2002-11-25  Paolo Carlini  <pcarlini@unitus.it>

	* src/localename.cc
	(locale::_Impl::_Impl(const char*, size_t)): Prefer strtok_r
	to strtok for thread safety reasons.
--- localename.cc.~1.31.~	2002-10-11 09:09:36.000000000 +0200
+++ localename.cc	2002-11-25 22:16:49.000000000 +0100
@@ -155,17 +155,18 @@
       {
 	char* __tmp = strdup(__s);
 	__tmp[strlen(__tmp)] = ';';
-	strtok(__tmp, "=;");
+	char* __save;
+	strtok_r(__tmp, "=;", &__save);
 	for (size_t __i = 0; 
 	     __i < _S_categories_size + _S_extra_categories_size - 1; ++__i)
 	  {
-	    char* __src = strtok(NULL, "=;");
+	    char* __src = strtok_r(NULL, "=;", &__save);
 	    char* __new = new char[strlen(__src) + 1];
 	    strcpy(__new, __src);
 	    _M_names[__i] = __new;
-	    strtok(NULL, "=;");
+	    strtok_r(NULL, "=;", &__save);
 	  }
-	char* __src = strtok(NULL, "=;");
+	char* __src = strtok_r(NULL, "=;", &__save);
 	char* __new = new char[strlen(__src) + 1];
 	strcpy(__new, __src);
 	_M_names[_S_categories_size + _S_extra_categories_size - 1] = __new;

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]