Author: sebor
Date: Tue Dec 5 10:23:00 2006
New Revision: 482729
URL: http://svn.apache.org/viewvc?view=rev&rev=482729
Log:
2006-12-05 Martin Sebor <[EMAIL PROTECTED]>
* string.cpp (__rw_memcpy, __rw_memmove, __rw_memchr, __rw_memset,
__rw_memcmp, __rw_strlen): Defined each helper without depending
on the corresponding libc function in order to avoid infinite
recursion.
(__rw_wmemcpy, __rw_wmemmove, __rw_wmemchr, __rw_wmemset, __rw_wmemcmp,
__rw_wcslen): Same.
Modified:
incubator/stdcxx/trunk/src/string.cpp
Modified: incubator/stdcxx/trunk/src/string.cpp
URL:
http://svn.apache.org/viewvc/incubator/stdcxx/trunk/src/string.cpp?view=diff&rev=482729&r1=482728&r2=482729
==============================================================================
--- incubator/stdcxx/trunk/src/string.cpp (original)
+++ incubator/stdcxx/trunk/src/string.cpp Tue Dec 5 10:23:00 2006
@@ -6,140 +6,27 @@
*
***************************************************************************
*
- * Copyright (c) 1994-2005 Quovadx, Inc., acting through its Rogue Wave
- * Software division. Licensed under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance with the
- * License. You may obtain a copy of the License at
- * http://www.apache.org/licenses/LICENSE-2.0. Unless required by
- * applicable law or agreed to in writing, software distributed under
- * the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
- * CONDITIONS OF ANY KIND, either express or implied. See the License
- * for the specific language governing permissions and limitations under
- * the License.
- *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed
+ * with this work for additional information regarding copyright
+ * ownership. The ASF licenses this file to you under the Apache
+ * License, Version 2.0 (the "License"); you may not use this file
+ * except in compliance with the License. You may obtain a copy of
+ * the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
+ * implied. See the License for the specific language governing
+ * permissions and limitations under the License.
+ *
**************************************************************************/
#define _RWSTD_LIB_SRC
#include <rw/_defs.h>
-#include <rw/_traits.h>
-
-#include <string.h>
-
-#ifndef _RWSTD_NO_WCHAR_H
-# include <wchar.h>
-#endif // _RWSTD_NO_WCHAR_H
-
-
-extern "C" {
-
-// declare functions that are known to be defined in the libc binary
-// but that, for some reason, are missing function prototypes in libc
-// headers
-
-
-#if defined (_RWSTD_NO_MEMCPY) && !defined (_RWSTD_NO_MEMCPY_IN_LIBC)
-
-void* memcpy (void*, const void*, _RWSTD_SIZE_T) _LIBC_THROWS ();
-
-# undef _RWSTD_NO_MEMCPY
-#endif // _RWSTD_NO_MEMCPY && !_RWSTD_NO_MEMCPY_IN_LIBC
-
-
-#if defined (_RWSTD_NO_MEMMOVE) && !defined (_RWSTD_NO_MEMMOVE_IN_LIBC)
-
-void* memmove (void*, const void*, _RWSTD_SIZE_T) _LIBC_THROWS ();
-
-# undef _RWSTD_NO_MEMMOVE
-#endif // _RWSTD_NO_MEMMOVE && !_RWSTD_NO_MEMMOVE_IN_LIBC
-
-
-#if defined (_RWSTD_NO_MEMCHR) && !defined (_RWSTD_NO_MEMCHR_IN_LIBC)
-
-void* memchr (const void*, int, _RWSTD_SIZE_T) _LIBC_THROWS ();
-
-# undef _RWSTD_NO_MEMCHR
-#endif // _RWSTD_NO_MEMCHR && !_RWSTD_NO_MEMCHR_IN_LIBC
-
-
-#if defined (_RWSTD_NO_MEMSET) && !defined (_RWSTD_NO_MEMSET_IN_LIBC)
-
-void* memset (void*, int, _RWSTD_SIZE_T) _LIBC_THROWS ();
-
-# undef _RWSTD_NO_MEMSET
-#endif // _RWSTD_NO_MEMSET && !_RWSTD_NO_MEMSET_IN_LIBC
-
-
-#if defined (_RWSTD_NO_MEMCMP) && !defined (_RWSTD_NO_MEMCMP_IN_LIBC)
-
-int memcmp (const void*, const void*, _RWSTD_SIZE_T) _LIBC_THROWS ();
-
-# undef _RWSTD_NO_MEMCMP
-#endif // _RWSTD_NO_MEMCMP && !_RWSTD_NO_MEMCMP_IN_LIBC
-
-
-#if defined (_RWSTD_NO_STRLEN) && !defined (_RWSTD_NO_STRLEN_IN_LIBC)
-
-_RWSTD_SIZE_T strlen (const char*) _LIBC_THROWS ();
-
-# undef _RWSTD_NO_STRLEN
-#endif // _RWSTD_NO_STRLEN && !_RWSTD_NO_STRLEN_IN_LIBC
-
-
-#ifndef _RWSTD_NO_WCHAR_T
-
-# if defined (_RWSTD_NO_WMEMCPY) && !defined (_RWSTD_NO_WMEMCPY_IN_LIBC)
-
-wchar_t* wmemcpy (wchar_t*, const wchar_t*, _RWSTD_SIZE_T) _LIBC_THROWS ();
-
-# undef _RWSTD_NO_WMEMCPY
-# endif // _RWSTD_NO_WMEMCPY && !_RWSTD_NO_WMEMCPY_IN_LIBC
-
-
-# if defined (_RWSTD_NO_WMEMMOVE) && !defined (_RWSTD_NO_WMEMMOVE_IN_LIBC)
-
-wchar_t* wmemmove (wchar_t*, const wchar_t*, _RWSTD_SIZE_T) _LIBC_THROWS ();
-
-# undef _RWSTD_NO_WMEMMOVE
-# endif // _RWSTD_NO_WMEMMOVE && !_RWSTD_NO_WMEMMOVE_IN_LIBC
-
-
-# if defined (_RWSTD_NO_WMEMCHR) && !defined (_RWSTD_NO_WMEMCHR_IN_LIBC)
-
-wchar_t* wmemchr (const wchar_t*, wchar_t, _RWSTD_SIZE_T) _LIBC_THROWS ();
-
-# undef _RWSTD_NO_WMEMCHR
-# endif // _RWSTD_NO_WMEMCHR && !_RWSTD_NO_WMEMCHR_IN_LIBC
-
-
-# if defined (_RWSTD_NO_WMEMSET) && !defined (_RWSTD_NO_WMEMSET_IN_LIBC)
-
-wchar_t* wmemset (wchar_t*, wchar_t, _RWSTD_SIZE_T) _LIBC_THROWS ();
-
-# undef _RWSTD_NO_WMEMSET
-# endif // _RWSTD_NO_WMEMSET && !_RWSTD_NO_WMEMSET_IN_LIBC
-
-
-# if defined (_RWSTD_NO_WMEMCMP) && !defined (_RWSTD_NO_WMEMCMP_IN_LIBC)
-
-int wmemcmp (const wchar_t*, const wchar_t*, _RWSTD_SIZE_T) _LIBC_THROWS ();
-
-# undef _RWSTD_NO_WMEMCMP
-# endif // _RWSTD_NO_WMEMCMP && !_RWSTD_NO_WMEMCMP_IN_LIBC
-
-
-# if defined (_RWSTD_NO_WSTRLEN) && !defined (_RWSTD_NO_WSTRLEN_IN_LIBC)
-
-_RWSTD_SIZE_T wcslen (const wchar_t*) _LIBC_THROWS ();
-
-# undef _RWSTD_NO_WSTRLEN
-# endif // _RWSTD_NO_WSTRLEN && !_RWSTD_NO_WSTRLEN_IN_LIBC
-
-#endif // _RWSTD_NO_WCHAR_T
-
-
-} // extern "C"
-
_RWSTD_NAMESPACE (__rw) {
@@ -149,21 +36,12 @@
{
_RWSTD_ASSERT (0 == nbytes || dst && src);
-#ifndef _RWSTD_NO_MEMCPY
-
- return memcpy (dst, src, nbytes);
-
-#else // if defined (_RWSTD_NO_MEMCPY)
-
const char* csrc = _RWSTD_STATIC_CAST (const char*, src);
for (char *tmp = _RWSTD_STATIC_CAST (char*, dst); nbytes; --nbytes)
*tmp++ = *csrc++;
return dst;
-
-#endif // _RWSTD_NO_MEMCPY
-
}
@@ -172,12 +50,6 @@
{
_RWSTD_ASSERT (0 == nbytes || dst && src);
-#ifndef _RWSTD_NO_MEMMOVE
-
- return memmove (dst, src, nbytes);
-
-#else // if _RWSTD_NO_MEMMOVE
-
char* cdst = _RWSTD_STATIC_CAST (char*, dst);
const char* csrc = _RWSTD_STATIC_CAST (const char*, src);
@@ -191,9 +63,6 @@
}
return dst;
-
-#endif // _RWSTD_NO_MEMMOVE
-
}
@@ -202,12 +71,6 @@
{
_RWSTD_ASSERT (0 == nbytes || src);
-#ifndef _RWSTD_NO_MEMCHR
-
- return memchr (src, c, nbytes);
-
-#else // if defined (_RWSTD_NO_MEMCHR)
-
typedef unsigned char UChar;
const UChar* csrc = _RWSTD_STATIC_CAST (const UChar*, src);
@@ -216,9 +79,6 @@
++csrc;
return int (*csrc) == c ? csrc : 0;
-
-#endif // _RWSTD_NO_MEMCHR
-
}
@@ -227,19 +87,10 @@
{
_RWSTD_ASSERT (0 == nbytes || dst);
-#ifndef _RWSTD_NO_MEMSET
-
- return memset (dst, c, nbytes);
-
-#else // if defined (_RWSTD_NO_MEMSET)
-
for (char *tmp = _RWSTD_STATIC_CAST (char*, dst); nbytes; ++tmp, --nbytes)
*tmp = c;
return dst;
-
-#endif // _RWSTD_NO_MEMSET
-
}
@@ -248,12 +99,6 @@
{
_RWSTD_ASSERT (0 == nbytes || s1 && s2);
-#ifndef _RWSTD_NO_MEMCMP
-
- return memcmp (s1, s2, nbytes);
-
-#else // if defined (_RWSTD_NO_MEMCMP)
-
typedef unsigned char UChar;
const UChar* cs1 = _RWSTD_STATIC_CAST (const UChar*, s1);
@@ -264,29 +109,17 @@
for ( ; nbytes && !(result = *cs1 - *cs2); ++cs1, ++cs2, --nbytes);
return result;
-
-#endif // _RWSTD_NO_MEMCMP
-
}
_RWSTD_EXPORT _RWSTD_SIZE_T
__rw_strlen (const char *str)
{
-#ifndef _RWSTD_NO_STRLEN
-
- return strlen (str);
-
-#else // if defined (_RWSTD_NO_STRLEN)
-
const char* const begin = str;
for (; *str; ++str);
- return size_t (str - begin);
-
-#endif // _RWSTD_NO_STRLEN
-
+ return _RWSTD_STATIC_CAST (_RWSTD_SIZE_T, str - begin);
}
@@ -297,19 +130,10 @@
{
_RWSTD_ASSERT (0 == nwchars || dst && src);
-#ifndef _RWSTD_NO_WMEMCPY
-
- return wmemcpy (dst, src, nwchars);
-
-#else // if defined (_RWSTD_NO_WMEMCPY)
-
for (wchar_t *tmp = dst; nwchars; --nwchars)
*tmp++ = *src++;
return dst;
-
-#endif // _RWSTD_NO_WMEMCPY
-
}
@@ -318,12 +142,6 @@
{
_RWSTD_ASSERT (0 == nwchars || dst && src);
-#ifndef _RWSTD_NO_WMEMMOVE
-
- return wmemmove (dst, src, nwchars);
-
-#else // if _RWSTD_NO_WMEMMOVE
-
if (dst < src) {
while (nwchars--)
*dst++ = *src++;
@@ -334,9 +152,6 @@
}
return dst;
-
-#endif // _RWSTD_NO_WMEMMOVE
-
}
@@ -345,19 +160,10 @@
{
_RWSTD_ASSERT (0 == nwchars || src);
-#ifndef _RWSTD_NO_WMEMCHR
-
- return wmemchr (src, wc, nwchars);
-
-#else // if defined (_RWSTD_NO_WMEMCHR)
-
while (nwchars-- > 0 && *src != wc)
++src;
return *src == wc ? src : 0;
-
-#endif // _RWSTD_NO_WMEMCHR
-
}
@@ -366,19 +172,10 @@
{
_RWSTD_ASSERT (0 == nwchars || dst);
-#ifndef _RWSTD_NO_WMEMSET
-
- return wmemset (dst, wc, nwchars);
-
-#else // if defined (_RWSTD_NO_WMEMSET)
-
for (wchar_t *tmp = dst; nwchars; ++tmp, --nwchars)
*tmp = wc;
return dst;
-
-#endif // _RWSTD_NO_WMEMSET
-
}
@@ -387,20 +184,11 @@
{
_RWSTD_ASSERT (0 == nwchars || s1 && s2);
-#ifndef _RWSTD_NO_WMEMCMP
-
- return wmemcmp (s1, s2, nwchars);
-
-#else // if defined (_RWSTD_NO_WMEMCMP)
-
int result = 0;
for ( ; nwchars && !(result = *s1 - *s2); ++s1, ++s2, --nwchars);
return result;
-
-#endif // _RWSTD_NO_WMEMCMP
-
}
@@ -409,20 +197,11 @@
{
_RWSTD_ASSERT (0 != wstr);
-#ifndef _RWSTD_NO_WCSLEN
-
- return wcslen (wstr);
-
-#else // if defined (_RWSTD_NO_WCSLEN)
-
const wchar_t* const begin = wstr;
for (; *wstr; ++wstr);
- return size_t (wstr - begin);
-
-#endif // _RWSTD_NO_WCSLEN
-
+ return _RWSTD_STATIC_CAST (_RWSTD_SIZE_T, wstr - begin);
}
#endif // _RWSTD_NO_WCHAR_T