zig

fork of https://codeberg.org/ziglang/zig
Log | Files | Refs | README | LICENSE

_string.h (9281B) - Raw


      1 /*
      2  * Copyright (c) 2023 Apple Inc. All rights reserved.
      3  *
      4  * @APPLE_LICENSE_HEADER_START@
      5  *
      6  * This file contains Original Code and/or Modifications of Original Code
      7  * as defined in and that are subject to the Apple Public Source License
      8  * Version 2.0 (the 'License'). You may not use this file except in
      9  * compliance with the License. Please obtain a copy of the License at
     10  * http://www.opensource.apple.com/apsl/ and read it before using this
     11  * file.
     12  *
     13  * The Original Code and all software distributed under the License are
     14  * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
     15  * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
     16  * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
     17  * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
     18  * Please see the License for the specific language governing rights and
     19  * limitations under the License.
     20  *
     21  * @APPLE_LICENSE_HEADER_END@
     22  */
     23 /*-
     24  * Copyright (c) 1990, 1993
     25  *	The Regents of the University of California.  All rights reserved.
     26  *
     27  * Redistribution and use in source and binary forms, with or without
     28  * modification, are permitted provided that the following conditions
     29  * are met:
     30  * 1. Redistributions of source code must retain the above copyright
     31  *    notice, this list of conditions and the following disclaimer.
     32  * 2. Redistributions in binary form must reproduce the above copyright
     33  *    notice, this list of conditions and the following disclaimer in the
     34  *    documentation and/or other materials provided with the distribution.
     35  * 3. All advertising materials mentioning features or use of this software
     36  *    must display the following acknowledgement:
     37  *	This product includes software developed by the University of
     38  *	California, Berkeley and its contributors.
     39  * 4. Neither the name of the University nor the names of its contributors
     40  *    may be used to endorse or promote products derived from this software
     41  *    without specific prior written permission.
     42  *
     43  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
     44  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
     45  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
     46  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
     47  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
     48  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
     49  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
     50  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
     51  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
     52  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
     53  * SUCH DAMAGE.
     54  *
     55  *	@(#)string.h	8.1 (Berkeley) 6/2/93
     56  */
     57 
     58 #ifndef _STRING_H_
     59 #define	_STRING_H_
     60 
     61 #include <_bounds.h>
     62 #include <_types.h>
     63 #include <sys/cdefs.h>
     64 #include <Availability.h>
     65 #include <sys/_types/_size_t.h>
     66 #include <sys/_types/_null.h>
     67 
     68 /* ANSI-C */
     69 
     70 _LIBC_SINGLE_BY_DEFAULT()
     71 
     72 __BEGIN_DECLS
     73 void *_LIBC_SIZE(__n)
     74 		memchr(const void *_LIBC_SIZE(__n) __s, int __c, size_t __n);
     75 int	 memcmp(const void *_LIBC_SIZE(__n) __s1, const void *_LIBC_SIZE(__n) __s2,
     76 		size_t __n);
     77 void *_LIBC_SIZE(__n)
     78 		memcpy(void *_LIBC_SIZE(__n) __dst, const void *_LIBC_SIZE(__n) __src,
     79 		size_t __n);
     80 void *_LIBC_SIZE(__len)
     81 		memmove(void *_LIBC_SIZE(__len) __dst,
     82 		const void *_LIBC_SIZE(__len) __src, size_t __len);
     83 void *_LIBC_SIZE(__len)
     84 		memset(void *_LIBC_SIZE(__len) __b, int __c, size_t __len);
     85 char *_LIBC_CSTR
     86 		strcat(char *_LIBC_UNSAFE_INDEXABLE __s1, const char *__s2)
     87 		_LIBC_PTRCHECK_REPLACED(strlcat);
     88 char *_LIBC_CSTR strchr(const char *__s, int __c);
     89 int	 strcmp(const char *__s1, const char *__s2);
     90 int	 strcoll(const char *__s1, const char *__s2);
     91 char *_LIBC_CSTR
     92 		strcpy(char *_LIBC_UNSAFE_INDEXABLE __dst, const char *__src)
     93 		_LIBC_PTRCHECK_REPLACED(strlcpy);
     94 size_t	 strcspn(const char *__s, const char *__charset);
     95 char *_LIBC_CSTR	strerror(int __errnum) __DARWIN_ALIAS(strerror);
     96 size_t	 strlen(const char *__s);
     97 char *_LIBC_CSTR
     98 		strncat(char *_LIBC_UNSAFE_INDEXABLE __s1,
     99 		const char *_LIBC_COUNT(__n) __s2, size_t __n)
    100 		_LIBC_PTRCHECK_REPLACED(strlcat);
    101 int	 strncmp(const char *_LIBC_UNSAFE_INDEXABLE __s1,
    102 		const char *_LIBC_UNSAFE_INDEXABLE __s2, size_t __n);
    103 char *_LIBC_UNSAFE_INDEXABLE
    104 		strncpy(char *_LIBC_COUNT(__n) __dst,
    105         const char *_LIBC_UNSAFE_INDEXABLE __src, size_t __n)
    106         _LIBC_PTRCHECK_REPLACED(strlcpy);
    107 char *_LIBC_CSTR    strpbrk(const char *__s, const char *__charset);
    108 char *_LIBC_CSTR    strrchr(const char *__s, int __c);
    109 size_t	 strspn(const char *__s, const char *__charset);
    110 char *_LIBC_CSTR    strstr(const char *__big, const char *__little);
    111 char *_LIBC_CSTR    strtok(char *_LIBC_CSTR __str, const char *__sep);
    112 size_t	 strxfrm(char *_LIBC_COUNT(__n) __s1, const char *__s2, size_t __n);
    113 __END_DECLS
    114 
    115 
    116 
    117 /* Additional functionality provided by:
    118  * POSIX.1c-1995,
    119  * POSIX.1i-1995,
    120  * and the omnibus ISO/IEC 9945-1: 1996
    121  */
    122 
    123 #if __DARWIN_C_LEVEL >= 199506L
    124 __BEGIN_DECLS
    125 char *_LIBC_CSTR
    126         strtok_r(char *_LIBC_CSTR __str, const char *__sep,
    127         char *_LIBC_CSTR *__lasts);
    128 __END_DECLS
    129 #endif /* __DARWIN_C_LEVEL >= 199506L */
    130 
    131 
    132 
    133 /* Additional functionality provided by:
    134  * POSIX.1-2001
    135  */
    136 
    137 #if __DARWIN_C_LEVEL >= 200112L
    138 __BEGIN_DECLS
    139 int	 strerror_r(int __errnum, char *_LIBC_COUNT(__buflen) __strerrbuf,
    140         size_t __buflen);
    141 char *_LIBC_CSTR    strdup(const char *__s1);
    142 void *_LIBC_UNSAFE_INDEXABLE /* in bounds of __dst */
    143         memccpy(void *_LIBC_SIZE(__n) __dst, const void *_LIBC_SIZE(__n) __src,
    144         int __c, size_t __n);
    145 __END_DECLS
    146 #endif /* __DARWIN_C_LEVEL >= 200112L */
    147 
    148 
    149 
    150 /* Additional functionality provided by:
    151  * POSIX.1-2008
    152  */
    153 
    154 #if __DARWIN_C_LEVEL >= 200809L
    155 __BEGIN_DECLS
    156 char *_LIBC_CSTR
    157         stpcpy(char *_LIBC_UNSAFE_INDEXABLE __dst, const char *__src) _LIBC_PTRCHECK_REPLACED(strlcpy);
    158 char *_LIBC_CSTR
    159         stpncpy(char *_LIBC_UNSAFE_INDEXABLE __dst,
    160         const char *_LIBC_UNSAFE_INDEXABLE __src, size_t __n)
    161         __OSX_AVAILABLE_STARTING(__MAC_10_7, __IPHONE_4_3)
    162         _LIBC_PTRCHECK_REPLACED(strlcpy);
    163 char *_LIBC_CSTR    strndup(const char *_LIBC_COUNT(__n) __s1, size_t __n) __OSX_AVAILABLE_STARTING(__MAC_10_7, __IPHONE_4_3);
    164 size_t   strnlen(const char *_LIBC_COUNT(__n) __s1, size_t __n) __OSX_AVAILABLE_STARTING(__MAC_10_7, __IPHONE_4_3);
    165 char *_LIBC_CSTR    strsignal(int __sig);
    166 __END_DECLS
    167 #endif /* __DARWIN_C_LEVEL >= 200809L */
    168 
    169 /* C11 Annex K */
    170 
    171 #if defined(__STDC_WANT_LIB_EXT1__) && __STDC_WANT_LIB_EXT1__ >= 1
    172 #include <sys/_types/_rsize_t.h>
    173 #include <sys/_types/_errno_t.h>
    174 
    175 __BEGIN_DECLS
    176 errno_t	memset_s(void *_LIBC_SIZE(__smax) __s, rsize_t __smax, int __c, rsize_t __n) __OSX_AVAILABLE_STARTING(__MAC_10_9, __IPHONE_7_0);
    177 __END_DECLS
    178 #endif
    179 
    180 /* Darwin extensions */
    181 
    182 #if __DARWIN_C_LEVEL >= __DARWIN_C_FULL
    183 #include <sys/_types/_ssize_t.h>
    184 
    185 __BEGIN_DECLS
    186 void *_LIBC_UNSAFE_INDEXABLE
    187         memmem(const void *_LIBC_SIZE(__big_len) __big, size_t __big_len,
    188         const void *_LIBC_SIZE(__little_len) __little, size_t __little_len) __OSX_AVAILABLE_STARTING(__MAC_10_7, __IPHONE_4_3);
    189 void	 memset_pattern4(void *_LIBC_SIZE(__len) __b, const void *_LIBC_SIZE(4) __pattern4, size_t __len) __OSX_AVAILABLE_STARTING(__MAC_10_5, __IPHONE_3_0);
    190 void	 memset_pattern8(void *_LIBC_SIZE(__len) __b, const void *_LIBC_SIZE(8) __pattern8, size_t __len) __OSX_AVAILABLE_STARTING(__MAC_10_5, __IPHONE_3_0);
    191 void	 memset_pattern16(void *_LIBC_SIZE(__len) __b, const void *_LIBC_SIZE(16) __pattern16, size_t __len) __OSX_AVAILABLE_STARTING(__MAC_10_5, __IPHONE_3_0);
    192 
    193 char *_LIBC_CSTR
    194         strcasestr(const char *__big, const char *__little);
    195 __OSX_AVAILABLE(15.4) __IOS_AVAILABLE(18.4)
    196 __TVOS_AVAILABLE(18.4) __WATCHOS_AVAILABLE(11.4)
    197 char *_LIBC_CSTR
    198         strchrnul(const char *__s, int __c);
    199 char *_LIBC_CSTR
    200         strnstr(const char *_LIBC_COUNT(__len) __big, const char *__little, size_t __len);
    201 size_t	 strlcat(char *_LIBC_COUNT(__size) __dst, const char *__source, size_t __size);
    202 size_t	 strlcpy(char *_LIBC_COUNT(__size) __dst, const char *__source, size_t __size);
    203 void	 strmode(int __mode, char *_LIBC_COUNT(12) __bp);
    204 char *_LIBC_CSTR
    205         strsep(char *_LIBC_CSTR *__stringp, const char *__delim);
    206 
    207 /* SUS places swab() in unistd.h.  It is listed here for source compatibility */
    208 void	 swab(const void *_LIBC_SIZE(__len) __restrict, void *_LIBC_SIZE(__len) __restrict, ssize_t __len);
    209 
    210 __OSX_AVAILABLE(10.12.1) __IOS_AVAILABLE(10.1)
    211 __TVOS_AVAILABLE(10.0.1) __WATCHOS_AVAILABLE(3.1)
    212 int	timingsafe_bcmp(const void *_LIBC_SIZE(__len) __b1, const void *_LIBC_SIZE(__len) __b2, size_t __len);
    213 
    214 __OSX_AVAILABLE(11.0) __IOS_AVAILABLE(14.0)
    215 __TVOS_AVAILABLE(14.0) __WATCHOS_AVAILABLE(7.0)
    216 int 	 strsignal_r(int __sig, char *_LIBC_COUNT(__buflen) __strsignalbuf, size_t __buflen);
    217 __END_DECLS
    218 
    219 /* Some functions historically defined in string.h were placed in strings.h
    220  * by SUS.
    221  */
    222 #include <_strings.h>
    223 #endif /* __DARWIN_C_LEVEL >= __DARWIN_C_FULL */
    224 
    225 
    226 #if defined (__GNUC__) && _FORTIFY_SOURCE > 0 && !defined (__cplusplus)
    227 /* Security checking functions.  */
    228 #include <secure/_string.h>
    229 #endif
    230 
    231 #endif /* _STRING_H_ */