xref: /freebsd/contrib/llvm-project/libcxx/include/string.h (revision bdd1243df58e60e85101c09001d9812a789b6bc4)
10b57cec5SDimitry Andric // -*- C++ -*-
2349cc55cSDimitry Andric //===----------------------------------------------------------------------===//
30b57cec5SDimitry Andric //
40b57cec5SDimitry Andric // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
50b57cec5SDimitry Andric // See https://llvm.org/LICENSE.txt for license information.
60b57cec5SDimitry Andric // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
70b57cec5SDimitry Andric //
80b57cec5SDimitry Andric //===----------------------------------------------------------------------===//
90b57cec5SDimitry Andric 
100b57cec5SDimitry Andric #ifndef _LIBCPP_STRING_H
110b57cec5SDimitry Andric #define _LIBCPP_STRING_H
120b57cec5SDimitry Andric 
130b57cec5SDimitry Andric /*
140b57cec5SDimitry Andric     string.h synopsis
150b57cec5SDimitry Andric 
160b57cec5SDimitry Andric Macros:
170b57cec5SDimitry Andric 
180b57cec5SDimitry Andric     NULL
190b57cec5SDimitry Andric 
200b57cec5SDimitry Andric Types:
210b57cec5SDimitry Andric 
220b57cec5SDimitry Andric     size_t
230b57cec5SDimitry Andric 
240b57cec5SDimitry Andric void* memcpy(void* restrict s1, const void* restrict s2, size_t n);
250b57cec5SDimitry Andric void* memmove(void* s1, const void* s2, size_t n);
260b57cec5SDimitry Andric char* strcpy (char* restrict s1, const char* restrict s2);
270b57cec5SDimitry Andric char* strncpy(char* restrict s1, const char* restrict s2, size_t n);
280b57cec5SDimitry Andric char* strcat (char* restrict s1, const char* restrict s2);
290b57cec5SDimitry Andric char* strncat(char* restrict s1, const char* restrict s2, size_t n);
300b57cec5SDimitry Andric int memcmp(const void* s1, const void* s2, size_t n);
310b57cec5SDimitry Andric int strcmp (const char* s1, const char* s2);
320b57cec5SDimitry Andric int strncmp(const char* s1, const char* s2, size_t n);
330b57cec5SDimitry Andric int strcoll(const char* s1, const char* s2);
340b57cec5SDimitry Andric size_t strxfrm(char* restrict s1, const char* restrict s2, size_t n);
350b57cec5SDimitry Andric const void* memchr(const void* s, int c, size_t n);
360b57cec5SDimitry Andric       void* memchr(      void* s, int c, size_t n);
370b57cec5SDimitry Andric const char* strchr(const char* s, int c);
380b57cec5SDimitry Andric       char* strchr(      char* s, int c);
390b57cec5SDimitry Andric size_t strcspn(const char* s1, const char* s2);
400b57cec5SDimitry Andric const char* strpbrk(const char* s1, const char* s2);
410b57cec5SDimitry Andric       char* strpbrk(      char* s1, const char* s2);
420b57cec5SDimitry Andric const char* strrchr(const char* s, int c);
430b57cec5SDimitry Andric       char* strrchr(      char* s, int c);
440b57cec5SDimitry Andric size_t strspn(const char* s1, const char* s2);
450b57cec5SDimitry Andric const char* strstr(const char* s1, const char* s2);
460b57cec5SDimitry Andric       char* strstr(      char* s1, const char* s2);
470b57cec5SDimitry Andric char* strtok(char* restrict s1, const char* restrict s2);
480b57cec5SDimitry Andric void* memset(void* s, int c, size_t n);
490b57cec5SDimitry Andric char* strerror(int errnum);
500b57cec5SDimitry Andric size_t strlen(const char* s);
510b57cec5SDimitry Andric 
520b57cec5SDimitry Andric */
530b57cec5SDimitry Andric 
540b57cec5SDimitry Andric #include <__config>
550b57cec5SDimitry Andric 
560b57cec5SDimitry Andric #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
570b57cec5SDimitry Andric #  pragma GCC system_header
580b57cec5SDimitry Andric #endif
590b57cec5SDimitry Andric 
60*bdd1243dSDimitry Andric #if __has_include_next(<string.h>)
610b57cec5SDimitry Andric #  include_next <string.h>
62*bdd1243dSDimitry Andric #endif
630b57cec5SDimitry Andric 
640b57cec5SDimitry Andric // MSVCRT, GNU libc and its derivates may already have the correct prototype in
650b57cec5SDimitry Andric // <string.h>. This macro can be defined by users if their C library provides
660b57cec5SDimitry Andric // the right signature.
670b57cec5SDimitry Andric #if defined(__CORRECT_ISO_CPP_STRING_H_PROTO) || defined(_LIBCPP_MSVCRT) || \
680b57cec5SDimitry Andric     defined(__sun__) || defined(_STRING_H_CPLUSPLUS_98_CONFORMANCE_)
690b57cec5SDimitry Andric #define _LIBCPP_STRING_H_HAS_CONST_OVERLOADS
700b57cec5SDimitry Andric #endif
710b57cec5SDimitry Andric 
720b57cec5SDimitry Andric #if defined(__cplusplus) && !defined(_LIBCPP_STRING_H_HAS_CONST_OVERLOADS) && defined(_LIBCPP_PREFERRED_OVERLOAD)
730b57cec5SDimitry Andric extern "C++" {
74*bdd1243dSDimitry Andric inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_PREFERRED_OVERLOAD const char* strchr(const char* __s, int __c) {
75*bdd1243dSDimitry Andric   return __builtin_strchr(__s, __c);
760b57cec5SDimitry Andric }
77*bdd1243dSDimitry Andric inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_PREFERRED_OVERLOAD char* strchr(char* __s, int __c) {
78*bdd1243dSDimitry Andric   return __builtin_strchr(__s, __c);
79*bdd1243dSDimitry Andric }
80*bdd1243dSDimitry Andric 
81*bdd1243dSDimitry Andric inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_PREFERRED_OVERLOAD const char* strpbrk(const char* __s1, const char* __s2) {
82*bdd1243dSDimitry Andric   return __builtin_strpbrk(__s1, __s2);
83*bdd1243dSDimitry Andric }
84*bdd1243dSDimitry Andric inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_PREFERRED_OVERLOAD char* strpbrk(char* __s1, const char* __s2) {
85*bdd1243dSDimitry Andric   return __builtin_strpbrk(__s1, __s2);
86*bdd1243dSDimitry Andric }
87*bdd1243dSDimitry Andric 
88*bdd1243dSDimitry Andric inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_PREFERRED_OVERLOAD const char* strrchr(const char* __s, int __c) {
89*bdd1243dSDimitry Andric   return __builtin_strrchr(__s, __c);
90*bdd1243dSDimitry Andric }
91*bdd1243dSDimitry Andric inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_PREFERRED_OVERLOAD char* strrchr(char* __s, int __c) {
92*bdd1243dSDimitry Andric   return __builtin_strrchr(__s, __c);
93*bdd1243dSDimitry Andric }
94*bdd1243dSDimitry Andric 
95*bdd1243dSDimitry Andric inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_PREFERRED_OVERLOAD const void* memchr(const void* __s, int __c, size_t __n) {
96*bdd1243dSDimitry Andric   return __builtin_memchr(__s, __c, __n);
97*bdd1243dSDimitry Andric }
98*bdd1243dSDimitry Andric inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_PREFERRED_OVERLOAD void* memchr(void* __s, int __c, size_t __n) {
99*bdd1243dSDimitry Andric   return __builtin_memchr(__s, __c, __n);
100*bdd1243dSDimitry Andric }
101*bdd1243dSDimitry Andric 
102*bdd1243dSDimitry Andric inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_PREFERRED_OVERLOAD const char* strstr(const char* __s1, const char* __s2) {
103*bdd1243dSDimitry Andric   return __builtin_strstr(__s1, __s2);
104*bdd1243dSDimitry Andric }
105*bdd1243dSDimitry Andric inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_PREFERRED_OVERLOAD char* strstr(char* __s1, const char* __s2) {
106*bdd1243dSDimitry Andric   return __builtin_strstr(__s1, __s2);
107*bdd1243dSDimitry Andric }
108*bdd1243dSDimitry Andric } // extern "C++"
1090b57cec5SDimitry Andric #endif
1100b57cec5SDimitry Andric 
1110b57cec5SDimitry Andric #endif // _LIBCPP_STRING_H
112