string.h 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  1. // -*- C++ -*-
  2. //===----------------------------------------------------------------------===//
  3. //
  4. // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
  5. // See https://llvm.org/LICENSE.txt for license information.
  6. // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
  7. //
  8. //===----------------------------------------------------------------------===//
  9. #ifndef _LIBCPP_STRING_H
  10. #define _LIBCPP_STRING_H
  11. /*
  12. string.h synopsis
  13. Macros:
  14. NULL
  15. Types:
  16. size_t
  17. void* memcpy(void* restrict s1, const void* restrict s2, size_t n);
  18. void* memmove(void* s1, const void* s2, size_t n);
  19. char* strcpy (char* restrict s1, const char* restrict s2);
  20. char* strncpy(char* restrict s1, const char* restrict s2, size_t n);
  21. char* strcat (char* restrict s1, const char* restrict s2);
  22. char* strncat(char* restrict s1, const char* restrict s2, size_t n);
  23. int memcmp(const void* s1, const void* s2, size_t n);
  24. int strcmp (const char* s1, const char* s2);
  25. int strncmp(const char* s1, const char* s2, size_t n);
  26. int strcoll(const char* s1, const char* s2);
  27. size_t strxfrm(char* restrict s1, const char* restrict s2, size_t n);
  28. const void* memchr(const void* s, int c, size_t n);
  29. void* memchr( void* s, int c, size_t n);
  30. const char* strchr(const char* s, int c);
  31. char* strchr( char* s, int c);
  32. size_t strcspn(const char* s1, const char* s2);
  33. const char* strpbrk(const char* s1, const char* s2);
  34. char* strpbrk( char* s1, const char* s2);
  35. const char* strrchr(const char* s, int c);
  36. char* strrchr( char* s, int c);
  37. size_t strspn(const char* s1, const char* s2);
  38. const char* strstr(const char* s1, const char* s2);
  39. char* strstr( char* s1, const char* s2);
  40. char* strtok(char* restrict s1, const char* restrict s2);
  41. void* memset(void* s, int c, size_t n);
  42. char* strerror(int errnum);
  43. size_t strlen(const char* s);
  44. */
  45. #include <__config>
  46. #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
  47. # pragma GCC system_header
  48. #endif
  49. #if __has_include_next(<string.h>)
  50. # include_next <string.h>
  51. #endif
  52. // MSVCRT, GNU libc and its derivates may already have the correct prototype in
  53. // <string.h>. This macro can be defined by users if their C library provides
  54. // the right signature.
  55. #if defined(__CORRECT_ISO_CPP_STRING_H_PROTO) || defined(_LIBCPP_MSVCRT) || defined(_STRING_H_CPLUSPLUS_98_CONFORMANCE_)
  56. #define _LIBCPP_STRING_H_HAS_CONST_OVERLOADS
  57. #endif
  58. #if defined(__cplusplus) && !defined(_LIBCPP_STRING_H_HAS_CONST_OVERLOADS) && defined(_LIBCPP_PREFERRED_OVERLOAD)
  59. extern "C++" {
  60. inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_PREFERRED_OVERLOAD const char* strchr(const char* __s, int __c) {
  61. return __builtin_strchr(__s, __c);
  62. }
  63. inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_PREFERRED_OVERLOAD char* strchr(char* __s, int __c) {
  64. return __builtin_strchr(__s, __c);
  65. }
  66. inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_PREFERRED_OVERLOAD const char* strpbrk(const char* __s1, const char* __s2) {
  67. return __builtin_strpbrk(__s1, __s2);
  68. }
  69. inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_PREFERRED_OVERLOAD char* strpbrk(char* __s1, const char* __s2) {
  70. return __builtin_strpbrk(__s1, __s2);
  71. }
  72. inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_PREFERRED_OVERLOAD const char* strrchr(const char* __s, int __c) {
  73. return __builtin_strrchr(__s, __c);
  74. }
  75. inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_PREFERRED_OVERLOAD char* strrchr(char* __s, int __c) {
  76. return __builtin_strrchr(__s, __c);
  77. }
  78. inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_PREFERRED_OVERLOAD const void* memchr(const void* __s, int __c, size_t __n) {
  79. return __builtin_memchr(__s, __c, __n);
  80. }
  81. inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_PREFERRED_OVERLOAD void* memchr(void* __s, int __c, size_t __n) {
  82. return __builtin_memchr(__s, __c, __n);
  83. }
  84. inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_PREFERRED_OVERLOAD const char* strstr(const char* __s1, const char* __s2) {
  85. return __builtin_strstr(__s1, __s2);
  86. }
  87. inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_PREFERRED_OVERLOAD char* strstr(char* __s1, const char* __s2) {
  88. return __builtin_strstr(__s1, __s2);
  89. }
  90. } // extern "C++"
  91. #endif
  92. #endif // _LIBCPP_STRING_H