Commit b1455c55 by Paolo Carlini Committed by Paolo Carlini

localename.cc (locale::_Impl::_Impl(const char*, size_t)): Avoid strtok for thread safety.

2002-11-25  Paolo Carlini  <pcarlini@unitus.it>
	    Nathan Myers  <ncm@cantrip.org>

	* src/localename.cc
	(locale::_Impl::_Impl(const char*, size_t)):
	Avoid strtok for thread safety.

Co-Authored-By: Nathan Myers <ncm@cantrip.org>

From-SVN: r59486
parent 162c7cd9
2002-11-25 Paolo Carlini <pcarlini@unitus.it>
Nathan Myers <ncm@cantrip.org>
* src/localename.cc
(locale::_Impl::_Impl(const char*, size_t)):
Avoid strtok for thread safety.
2002-11-25 Stephen M. Webb <stephen@bregmasoft.com> 2002-11-25 Stephen M. Webb <stephen@bregmasoft.com>
* testsuite/testsuite_allocator.h: New file. * testsuite/testsuite_allocator.h: New file.
......
...@@ -141,9 +141,9 @@ namespace std ...@@ -141,9 +141,9 @@ namespace std
} }
// Name all the categories. // Name all the categories.
size_t __len = strlen(__s) + 1;
if (!strchr(__s, ';')) if (!strchr(__s, ';'))
{ {
size_t __len = strlen(__s) + 1;
for (size_t __i = 0; for (size_t __i = 0;
__i < _S_categories_size + _S_extra_categories_size; ++__i) __i < _S_categories_size + _S_extra_categories_size; ++__i)
{ {
...@@ -152,27 +152,28 @@ namespace std ...@@ -152,27 +152,28 @@ namespace std
} }
} }
else else
{ {
char* __tmp = strdup(__s); char* __new;
__tmp[strlen(__tmp)] = ';'; const char* __save = __s;
strtok(__tmp, "=;"); char* __next = strpbrk(__save, "=;");
__save = __next + 1;
for (size_t __i = 0; for (size_t __i = 0;
__i < _S_categories_size + _S_extra_categories_size - 1; ++__i) __i < _S_categories_size + _S_extra_categories_size - 1; ++__i)
{ {
char* __src = strtok(NULL, "=;"); __next = strpbrk(__save, "=;");
char* __new = new char[strlen(__src) + 1]; __new = new char[__next - __save + 1];
strcpy(__new, __src); memcpy(__new, __save, __next - __save);
__new[__next - __save] = '\0';
_M_names[__i] = __new; _M_names[__i] = __new;
strtok(NULL, "=;"); __save = __next + 1;
__next = strpbrk(__save, "=;");
__save = __next + 1;
} }
char* __src = strtok(NULL, "=;"); __new = new char[__s + __len - __save];
char* __new = new char[strlen(__src) + 1]; memcpy(__new, __save, __s + __len - __save);
strcpy(__new, __src);
_M_names[_S_categories_size + _S_extra_categories_size - 1] = __new; _M_names[_S_categories_size + _S_extra_categories_size - 1] = __new;
free(__tmp);
} }
// Construct all standard facets and add them to _M_facets. // Construct all standard facets and add them to _M_facets.
_M_init_facet(new std::ctype<char>(__cloc, 0, false)); _M_init_facet(new std::ctype<char>(__cloc, 0, false));
_M_init_facet(new codecvt<char, char, mbstate_t>(__cloc)); _M_init_facet(new codecvt<char, char, mbstate_t>(__cloc));
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment