This is the mail archive of the
libstdc++@gcc.gnu.org
mailing list for the libstdc++ project.
[Patch] Final (hopefully) strtok patch
- From: Paolo Carlini <pcarlini at unitus dot it>
- To: libstdc++ at gcc dot gnu dot org
- Cc: bkoz at redhat dot com
- Date: Thu, 28 Nov 2002 01:03:35 +0100
- Subject: [Patch] Final (hopefully) strtok patch
Hi!
Ok, this is the result of Nathan's latest indications about
strchr (vs strlen) and so on. Seems indeed much cleaner
to me.
If nobody complaints, tomorrow I would like to apply it and
move to something else ;)
Tested x86-linux.
Ciao, Paolo.
///////
2002-11-27 Paolo Carlini <pcarlini@unitus.it>
Nathan Myers <ncm@cantrip.org>
* src/localename.cc
(locale::_Impl::_Impl(const char*, size_t)):
Improve previous fix for the strtok vs MT issue.
*** localename.cc.~1.32.~ Tue Nov 26 01:06:54 2002
--- localename.cc Thu Nov 28 00:17:10 2002
*************** namespace std
*** 141,177 ****
}
// Name all the categories.
! size_t __len = strlen(__s) + 1;
if (!strchr(__s, ';'))
{
for (size_t __i = 0;
__i < _S_categories_size + _S_extra_categories_size; ++__i)
{
! _M_names[__i] = new char[__len];
strcpy(_M_names[__i], __s);
}
}
else
! {
! char* __new;
! const char* __save = __s;
! char* __next = strpbrk(__save, "=;");
! __save = __next + 1;
for (size_t __i = 0;
! __i < _S_categories_size + _S_extra_categories_size - 1; ++__i)
{
! __next = strpbrk(__save, "=;");
! __new = new char[__next - __save + 1];
! memcpy(__new, __save, __next - __save);
! __new[__next - __save] = '\0';
_M_names[__i] = __new;
! __save = __next + 1;
! __next = strpbrk(__save, "=;");
! __save = __next + 1;
! }
! __new = new char[__s + __len - __save];
! memcpy(__new, __save, __s + __len - __save);
! _M_names[_S_categories_size + _S_extra_categories_size - 1] = __new;
}
// Construct all standard facets and add them to _M_facets.
--- 141,171 ----
}
// Name all the categories.
! size_t __len = strlen(__s);
if (!strchr(__s, ';'))
{
for (size_t __i = 0;
__i < _S_categories_size + _S_extra_categories_size; ++__i)
{
! _M_names[__i] = new char[__len + 1];
strcpy(_M_names[__i], __s);
}
}
else
! {
! const char* __beg = __s;
for (size_t __i = 0;
! __i < _S_categories_size + _S_extra_categories_size; ++__i)
{
! __beg = strchr(__beg, '=') + 1;
! const char* __end = strchr(__beg, ';');
! if (!__end)
! __end = __s + __len;
! char* __new = new char[__end - __beg + 1];
! memcpy(__new, __beg, __end - __beg);
! __new[__end - __beg] = '\0';
_M_names[__i] = __new;
! }
}
// Construct all standard facets and add them to _M_facets.