xref: /netbsd-src/include/string.h (revision 2db69065917f14f1b3da7a3fa14f2d3ee8d7b04b)
1 /*	$NetBSD: string.h,v 1.58 2024/12/09 12:09:02 nros Exp $	*/
2 
3 /*-
4  * Copyright (c) 1990, 1993
5  *	The Regents of the University of California.  All rights reserved.
6  *
7  * Redistribution and use in source and binary forms, with or without
8  * modification, are permitted provided that the following conditions
9  * are met:
10  * 1. Redistributions of source code must retain the above copyright
11  *    notice, this list of conditions and the following disclaimer.
12  * 2. Redistributions in binary form must reproduce the above copyright
13  *    notice, this list of conditions and the following disclaimer in the
14  *    documentation and/or other materials provided with the distribution.
15  * 3. Neither the name of the University nor the names of its contributors
16  *    may be used to endorse or promote products derived from this software
17  *    without specific prior written permission.
18  *
19  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
20  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
21  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
22  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
23  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
24  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
25  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
26  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
27  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
28  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
29  * SUCH DAMAGE.
30  *
31  *	@(#)string.h	8.1 (Berkeley) 6/2/93
32  */
33 
34 #ifndef _STRING_H_
35 #define	_STRING_H_
36 #include <machine/ansi.h>
37 
38 #ifdef	_BSD_SIZE_T_
39 typedef	_BSD_SIZE_T_	size_t;
40 #undef	_BSD_SIZE_T_
41 #endif
42 
43 #include <sys/null.h>
44 
45 #include <sys/cdefs.h>
46 #include <sys/featuretest.h>
47 
48 #if (_POSIX_C_SOURCE - 0) >= 200809L || defined(_NETBSD_SOURCE)
49 #  ifndef __LOCALE_T_DECLARED
50 typedef struct _locale		*locale_t;
51 #  define __LOCALE_T_DECLARED
52 #  endif
53 #endif /* _POSIX_C_SOURCE || _NETBSD_SOURCE */
54 
55 __BEGIN_DECLS
56 #if defined(_XOPEN_SOURCE) || defined(_NETBSD_SOURCE) || \
57     (__STDC_VERSION__ - 0 >= 202311L) || defined(_ISOC23_SOURCE)
58 void	*memccpy(void *, const void *, int, size_t);
59 #endif /* _XOPEN_SOURCE || _NETBSD_SOURCE || _ISOC23_SOURCE */
60 void	*memchr(const void *, int, size_t);
61 int	 memcmp(const void *, const void *, size_t);
62 void	*memcpy(void * __restrict, const void * __restrict, size_t);
63 #if (_POSIX_C_SOURCE - 0 >= 202405L) || defined(_NETBSD_SOURCE)
64 void	*memmem(const void *, size_t, const void *, size_t);
65 #endif /* _POSIX_C_SOURCE || _NETBSD_SOURCE */
66 void	*memmove(void *, const void *, size_t);
67 void	*memset(void *, int, size_t);
68 #if (__STDC_VERSION__ - 0 >= 202311L) || defined(_ISOC23_SOURCE) || \
69     defined(_NETBSD_SOURCE)
70 void	*memset_explicit(void *, int, size_t);
71 #endif
72 #if (_POSIX_C_SOURCE - 0 >= 200809L) || defined(_NETBSD_SOURCE)
73 char	*stpcpy(char * __restrict, const char * __restrict);
74 char	*stpncpy(char * __restrict, const char * __restrict, size_t);
75 #endif /* _POSIX_C_SOURCE || _NETBSD_SOURCE */
76 char	*strcat(char * __restrict, const char * __restrict);
77 char	*strchr(const char *, int);
78 int	 strcmp(const char *, const char *);
79 int	 strcoll(const char *, const char *);
80 #if (_POSIX_C_SOURCE - 0) >= 200809L || defined(_NETBSD_SOURCE)
81 int	 strcoll_l(const char *, const char *, locale_t);
82 #endif /* _POSIX_C_SOURCE || _NETBSD_SOURCE */
83 char	*strcpy(char * __restrict, const char * __restrict);
84 size_t	 strcspn(const char *, const char *);
85 #if (_POSIX_C_SOURCE - 0 >= 200809L) || defined(_XOPEN_SOURCE) || \
86     defined(_NETBSD_SOURCE) || (__STDC_VERSION__ - 0 >= 202311L) || \
87     defined(_ISOC23_SOURCE)
88 char	*strdup(const char *);
89 #endif /* _POSIX_C_SOURCE || _XOPEN_SOURCE || _NETBSD_SOURCE ||
90         * _ISOC23_SOURCE
91         */
92 __aconst char *strerror(int);
93 #if (_POSIX_C_SOURCE - 0) >= 200809L || defined(_NETBSD_SOURCE)
94 __aconst char *strerror_l(int, locale_t);
95 #endif /* _POSIX_C_SOURCE || _NETBSD_SOURCE */
96 #if (_POSIX_C_SOURCE - 0 >= 200112L) || \
97     defined(_REENTRANT) || defined(_NETBSD_SOURCE)
98 int	 strerror_r(int, char *, size_t);
99 #endif /* _POSIX_C_SOURCE || _REENTRANT || _NETBSD_SOURCE */
100 #if (_POSIX_C_SOURCE - 0 >= 202405L) || defined(_NETBSD_SOURCE)
101 size_t	 strlcat(char * __restrict, const char * __restrict, size_t);
102 size_t	 strlcpy(char * __restrict, const char * __restrict, size_t);
103 #endif /* _POSIX_C_SOURCE || _NETBSD_SOURCE */
104 size_t	 strlen(const char *);
105 char	*strncat(char * __restrict, const char * __restrict, size_t);
106 int	 strncmp(const char *, const char *, size_t);
107 char	*strncpy(char * __restrict, const char * __restrict, size_t);
108 #if (_POSIX_C_SOURCE - 0 >= 200809L) || defined(_NETBSD_SOURCE) || \
109     (__STDC_VERSION__ - 0 >= 202311L) || defined(_ISOC23_SOURCE)
110 char	*strndup(const char *, size_t);
111 #endif /* _POSIX_C_SOURCE || _NETBSD_SOURCE || _ISOC23_SOURCE */
112 #if (_POSIX_C_SOURCE - 0 >= 200809L) || defined(_NETBSD_SOURCE)
113 size_t	strnlen(const char *, size_t);
114 #endif /* _POSIX_C_SOURCE || _NETBSD_SOURCE */
115 char	*strpbrk(const char *, const char *);
116 char	*strrchr(const char *, int);
117 #if (_POSIX_C_SOURCE - 0 >= 200809L) || defined(_NETBSD_SOURCE)
118 #ifndef __STRSIGNAL_DECLARED
119 #define __STRSIGNAL_DECLARED
120 /* also in unistd.h */
121 __aconst char *strsignal(int);
122 #endif /* __STRSIGNAL_DECLARED */
123 #endif
124 size_t	 strspn(const char *, const char *);
125 char	*strstr(const char *, const char *);
126 char	*strtok(char * __restrict, const char * __restrict);
127 #if (_POSIX_C_SOURCE - 0 >= 200112L) || \
128     defined(_REENTRANT) || defined(_NETBSD_SOURCE)
129 char	*strtok_r(char *, const char *, char **);
130 #endif /* _POSIX_C_SOURCE || _REENTRANT || _NETBSD_SOURCE */
131 size_t	 strxfrm(char * __restrict, const char * __restrict, size_t);
132 #if (_POSIX_C_SOURCE - 0) >= 200809L || defined(_NETBSD_SOURCE)
133 size_t	 strxfrm_l(char * __restrict, const char * __restrict, size_t,
134 	    locale_t);
135 #endif /* _POSIX_C_SOURCE || _NETBSD_SOURCE */
136 __END_DECLS
137 
138 #if defined(_NETBSD_SOURCE)
139 #include <strings.h>		/* for backwards-compatibility */
140 __BEGIN_DECLS
141 char	*strcasestr(const char *, const char *);
142 char	*strchrnul(const char *, int);
143 char	*strsep(char **, const char *);
144 char	*stresep(char **, const char *, int);
145 char	*strnstr(const char *, const char *, size_t);
146 void	*memrchr(const void *, int, size_t);
147 void	*mempcpy(void * __restrict, const void * __restrict, size_t);
148 void	*explicit_memset(void *, int, size_t);
149 int	consttime_memequal(const void *, const void *, size_t);
150 __END_DECLS
151 #endif /* _NETBSD_SOURCE */
152 
153 #if _FORTIFY_SOURCE > 0
154 #include <ssp/string.h>
155 #endif
156 #endif /* !defined(_STRING_H_) */
157