Richard Smith | 5827a77 | 2016-02-10 00:59:02 +0000 | [diff] [blame] | 1 | // -*- C++ -*- |
Louis Dionne | 9bd9388 | 2021-11-17 16:25:01 -0500 | [diff] [blame] | 2 | //===----------------------------------------------------------------------===// |
Richard Smith | 5827a77 | 2016-02-10 00:59:02 +0000 | [diff] [blame] | 3 | // |
Chandler Carruth | 7642bb1 | 2019-01-19 08:50:56 +0000 | [diff] [blame] | 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 |
Richard Smith | 5827a77 | 2016-02-10 00:59:02 +0000 | [diff] [blame] | 7 | // |
| 8 | //===----------------------------------------------------------------------===// |
| 9 | |
| 10 | #ifndef _LIBCPP_STRING_H |
| 11 | #define _LIBCPP_STRING_H |
| 12 | |
| 13 | /* |
| 14 | string.h synopsis |
| 15 | |
| 16 | Macros: |
| 17 | |
| 18 | NULL |
| 19 | |
| 20 | Types: |
| 21 | |
| 22 | size_t |
| 23 | |
| 24 | void* memcpy(void* restrict s1, const void* restrict s2, size_t n); |
| 25 | void* memmove(void* s1, const void* s2, size_t n); |
| 26 | char* strcpy (char* restrict s1, const char* restrict s2); |
| 27 | char* strncpy(char* restrict s1, const char* restrict s2, size_t n); |
| 28 | char* strcat (char* restrict s1, const char* restrict s2); |
| 29 | char* strncat(char* restrict s1, const char* restrict s2, size_t n); |
| 30 | int memcmp(const void* s1, const void* s2, size_t n); |
| 31 | int strcmp (const char* s1, const char* s2); |
| 32 | int strncmp(const char* s1, const char* s2, size_t n); |
| 33 | int strcoll(const char* s1, const char* s2); |
| 34 | size_t strxfrm(char* restrict s1, const char* restrict s2, size_t n); |
| 35 | const void* memchr(const void* s, int c, size_t n); |
| 36 | void* memchr( void* s, int c, size_t n); |
| 37 | const char* strchr(const char* s, int c); |
| 38 | char* strchr( char* s, int c); |
| 39 | size_t strcspn(const char* s1, const char* s2); |
| 40 | const char* strpbrk(const char* s1, const char* s2); |
| 41 | char* strpbrk( char* s1, const char* s2); |
| 42 | const char* strrchr(const char* s, int c); |
| 43 | char* strrchr( char* s, int c); |
| 44 | size_t strspn(const char* s1, const char* s2); |
| 45 | const char* strstr(const char* s1, const char* s2); |
| 46 | char* strstr( char* s1, const char* s2); |
| 47 | char* strtok(char* restrict s1, const char* restrict s2); |
| 48 | void* memset(void* s, int c, size_t n); |
| 49 | char* strerror(int errnum); |
| 50 | size_t strlen(const char* s); |
| 51 | |
| 52 | */ |
| 53 | |
| 54 | #include <__config> |
| 55 | |
| 56 | #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) |
Arthur O'Dwyer | 6eeaa00 | 2022-02-01 20:16:40 -0500 | [diff] [blame] | 57 | # pragma GCC system_header |
Richard Smith | 5827a77 | 2016-02-10 00:59:02 +0000 | [diff] [blame] | 58 | #endif |
| 59 | |
Louis Dionne | be1aa9e | 2022-11-15 17:08:01 -0500 | [diff] [blame] | 60 | #if __has_include_next(<string.h>) |
| 61 | # include_next <string.h> |
| 62 | #endif |
Richard Smith | 5827a77 | 2016-02-10 00:59:02 +0000 | [diff] [blame] | 63 | |
Richard Smith | 763496e | 2016-02-11 23:51:02 +0000 | [diff] [blame] | 64 | // MSVCRT, GNU libc and its derivates may already have the correct prototype in |
| 65 | // <string.h>. This macro can be defined by users if their C library provides |
| 66 | // the right signature. |
| 67 | #if defined(__CORRECT_ISO_CPP_STRING_H_PROTO) || defined(_LIBCPP_MSVCRT) || \ |
| 68 | defined(__sun__) || defined(_STRING_H_CPLUSPLUS_98_CONFORMANCE_) |
Richard Smith | 5827a77 | 2016-02-10 00:59:02 +0000 | [diff] [blame] | 69 | #define _LIBCPP_STRING_H_HAS_CONST_OVERLOADS |
| 70 | #endif |
| 71 | |
| 72 | #if defined(__cplusplus) && !defined(_LIBCPP_STRING_H_HAS_CONST_OVERLOADS) && defined(_LIBCPP_PREFERRED_OVERLOAD) |
| 73 | extern "C++" { |
Louis Dionne | 10ebfb7 | 2022-11-24 14:28:48 -0500 | [diff] [blame^] | 74 | inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_PREFERRED_OVERLOAD const char* strchr(const char* __s, int __c) { |
| 75 | return __builtin_strchr(__s, __c); |
Richard Smith | 5827a77 | 2016-02-10 00:59:02 +0000 | [diff] [blame] | 76 | } |
Louis Dionne | 10ebfb7 | 2022-11-24 14:28:48 -0500 | [diff] [blame^] | 77 | inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_PREFERRED_OVERLOAD char* strchr(char* __s, int __c) { |
| 78 | return __builtin_strchr(__s, __c); |
| 79 | } |
| 80 | |
| 81 | inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_PREFERRED_OVERLOAD const char* strpbrk(const char* __s1, const char* __s2) { |
| 82 | return __builtin_strpbrk(__s1, __s2); |
| 83 | } |
| 84 | inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_PREFERRED_OVERLOAD char* strpbrk(char* __s1, const char* __s2) { |
| 85 | return __builtin_strpbrk(__s1, __s2); |
| 86 | } |
| 87 | |
| 88 | inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_PREFERRED_OVERLOAD const char* strrchr(const char* __s, int __c) { |
| 89 | return __builtin_strrchr(__s, __c); |
| 90 | } |
| 91 | inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_PREFERRED_OVERLOAD char* strrchr(char* __s, int __c) { |
| 92 | return __builtin_strrchr(__s, __c); |
| 93 | } |
| 94 | |
| 95 | inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_PREFERRED_OVERLOAD const void* memchr(const void* __s, int __c, size_t __n) { |
| 96 | return __builtin_memchr(__s, __c, __n); |
| 97 | } |
| 98 | inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_PREFERRED_OVERLOAD void* memchr(void* __s, int __c, size_t __n) { |
| 99 | return __builtin_memchr(__s, __c, __n); |
| 100 | } |
| 101 | |
| 102 | inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_PREFERRED_OVERLOAD const char* strstr(const char* __s1, const char* __s2) { |
| 103 | return __builtin_strstr(__s1, __s2); |
| 104 | } |
| 105 | inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_PREFERRED_OVERLOAD char* strstr(char* __s1, const char* __s2) { |
| 106 | return __builtin_strstr(__s1, __s2); |
| 107 | } |
| 108 | } // extern "C++" |
Richard Smith | 5827a77 | 2016-02-10 00:59:02 +0000 | [diff] [blame] | 109 | #endif |
| 110 | |
Louis Dionne | 2b1ceaa | 2021-04-20 12:03:32 -0400 | [diff] [blame] | 111 | #endif // _LIBCPP_STRING_H |