[libcxx] r249929 - Split <string.h> out of <cstring>.

Richard Smith via cfe-commits cfe-commits at lists.llvm.org
Fri Oct 9 18:25:32 PDT 2015


Author: rsmith
Date: Fri Oct  9 20:25:31 2015
New Revision: 249929

URL: http://llvm.org/viewvc/llvm-project?rev=249929&view=rev
Log:
Split <string.h> out of <cstring>.

Also fix the overload set for the five functions whose signatures change in the
case where we can fix it. This is already covered by existing tests for the
affected systems.

Added:
    libcxx/trunk/include/string.h
      - copied, changed from r249736, libcxx/trunk/include/cstring
Modified:
    libcxx/trunk/include/cstring

Modified: libcxx/trunk/include/cstring
URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/include/cstring?rev=249929&r1=249928&r2=249929&view=diff
==============================================================================
--- libcxx/trunk/include/cstring (original)
+++ libcxx/trunk/include/cstring Fri Oct  9 20:25:31 2015
@@ -78,37 +78,42 @@ using ::strcmp;
 using ::strncmp;
 using ::strcoll;
 using ::strxfrm;
+using ::strcspn;
+using ::strspn;
+#ifndef _LIBCPP_HAS_NO_THREAD_UNSAFE_C_FUNCTIONS
+using ::strtok;
+#endif
+using ::memset;
+using ::strerror;
+using ::strlen;
 
-using ::memchr;
+// MSVCRT, GNU libc and its derivates already have the correct prototype in
+// <string.h> if __cplusplus is defined. This macro can be defined by users if
+// their C library provides the right signature.
+#if defined(__GLIBC__) || defined(_LIBCPP_MSVCRT) || defined(__sun__) || \
+    defined(_STRING_H_CPLUSPLUS_98_CONFORMANCE_)
+#define _LIBCPP_STRING_H_HAS_CONST_OVERLOADS
+#endif
 
+#ifdef _LIBCPP_STRING_H_HAS_CONST_OVERLOADS
 using ::strchr;
-
-using ::strcspn;
-
 using ::strpbrk;
-
 using ::strrchr;
-
-using ::strspn;
-
+using ::memchr;
 using ::strstr;
-
-// MSVCRT, GNU libc and its derivates already have the correct prototype in <string.h> #ifdef __cplusplus
-#if !defined(__GLIBC__) && !defined(_LIBCPP_MSVCRT) && !defined(__sun__) && !defined(_STRING_H_CPLUSPLUS_98_CONFORMANCE_)
+#else
+inline _LIBCPP_INLINE_VISIBILITY const char* strchr(const char* __s, int __c) {return ::strchr(__s, __c);}
 inline _LIBCPP_INLINE_VISIBILITY       char* strchr(      char* __s, int __c) {return ::strchr(__s, __c);}
+inline _LIBCPP_INLINE_VISIBILITY const char* strpbrk(const char* __s1, const char* __s2) {return ::strpbrk(__s1, __s2);}
 inline _LIBCPP_INLINE_VISIBILITY       char* strpbrk(      char* __s1, const char* __s2) {return ::strpbrk(__s1, __s2);}
+inline _LIBCPP_INLINE_VISIBILITY const char* strrchr(const char* __s, int __c) {return ::strrchr(__s, __c);}
 inline _LIBCPP_INLINE_VISIBILITY       char* strrchr(      char* __s, int __c) {return ::strrchr(__s, __c);}
+inline _LIBCPP_INLINE_VISIBILITY const void* memchr(const void* __s, int __c, size_t __n) {return ::memchr(__s, __c, __n);}
 inline _LIBCPP_INLINE_VISIBILITY       void* memchr(      void* __s, int __c, size_t __n) {return ::memchr(__s, __c, __n);}
+inline _LIBCPP_INLINE_VISIBILITY const char* strstr(const char* __s1, const char* __s2) {return ::strstr(__s1, __s2);}
 inline _LIBCPP_INLINE_VISIBILITY       char* strstr(      char* __s1, const char* __s2) {return ::strstr(__s1, __s2);}
 #endif
 
-#ifndef _LIBCPP_HAS_NO_THREAD_UNSAFE_C_FUNCTIONS
-using ::strtok;
-#endif
-using ::memset;
-using ::strerror;
-using ::strlen;
-
 _LIBCPP_END_NAMESPACE_STD
 
 #endif  // _LIBCPP_CSTRING

Copied: libcxx/trunk/include/string.h (from r249736, libcxx/trunk/include/cstring)
URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/include/string.h?p2=libcxx/trunk/include/string.h&p1=libcxx/trunk/include/cstring&r1=249736&r2=249929&rev=249929&view=diff
==============================================================================
--- libcxx/trunk/include/cstring (original)
+++ libcxx/trunk/include/string.h Fri Oct  9 20:25:31 2015
@@ -1,5 +1,5 @@
 // -*- C++ -*-
-//===--------------------------- cstring ----------------------------------===//
+//===--------------------------- string.h ---------------------------------===//
 //
 //                     The LLVM Compiler Infrastructure
 //
@@ -8,19 +8,16 @@
 //
 //===----------------------------------------------------------------------===//
 
-#ifndef _LIBCPP_CSTRING
-#define _LIBCPP_CSTRING
+#ifndef _LIBCPP_STRING_H
+#define _LIBCPP_STRING_H
 
 /*
-    cstring synopsis
+    string.h synopsis
 
 Macros:
 
     NULL
 
-namespace std
-{
-
 Types:
 
     size_t
@@ -53,62 +50,14 @@ void* memset(void* s, int c, size_t n);
 char* strerror(int errnum);
 size_t strlen(const char* s);
 
-}  // std
-
 */
 
 #include <__config>
-#include <string.h>
 
 #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
 #pragma GCC system_header
 #endif
 
-_LIBCPP_BEGIN_NAMESPACE_STD
-
-using ::size_t;
-using ::memcpy;
-using ::memmove;
-using ::strcpy;
-using ::strncpy;
-using ::strcat;
-using ::strncat;
-using ::memcmp;
-using ::strcmp;
-using ::strncmp;
-using ::strcoll;
-using ::strxfrm;
-
-using ::memchr;
-
-using ::strchr;
-
-using ::strcspn;
-
-using ::strpbrk;
-
-using ::strrchr;
-
-using ::strspn;
-
-using ::strstr;
-
-// MSVCRT, GNU libc and its derivates already have the correct prototype in <string.h> #ifdef __cplusplus
-#if !defined(__GLIBC__) && !defined(_LIBCPP_MSVCRT) && !defined(__sun__) && !defined(_STRING_H_CPLUSPLUS_98_CONFORMANCE_)
-inline _LIBCPP_INLINE_VISIBILITY       char* strchr(      char* __s, int __c) {return ::strchr(__s, __c);}
-inline _LIBCPP_INLINE_VISIBILITY       char* strpbrk(      char* __s1, const char* __s2) {return ::strpbrk(__s1, __s2);}
-inline _LIBCPP_INLINE_VISIBILITY       char* strrchr(      char* __s, int __c) {return ::strrchr(__s, __c);}
-inline _LIBCPP_INLINE_VISIBILITY       void* memchr(      void* __s, int __c, size_t __n) {return ::memchr(__s, __c, __n);}
-inline _LIBCPP_INLINE_VISIBILITY       char* strstr(      char* __s1, const char* __s2) {return ::strstr(__s1, __s2);}
-#endif
-
-#ifndef _LIBCPP_HAS_NO_THREAD_UNSAFE_C_FUNCTIONS
-using ::strtok;
-#endif
-using ::memset;
-using ::strerror;
-using ::strlen;
-
-_LIBCPP_END_NAMESPACE_STD
+#include_next <string.h>
 
-#endif  // _LIBCPP_CSTRING
+#endif  // _LIBCPP_STRING_H




More information about the cfe-commits mailing list