1 /*
2 Copyright (c) 1991, 1993
3 The Regents of the University of California.  All rights reserved.
4 c) UNIX System Laboratories, Inc.
5 All or some portions of this file are derived from material licensed
6 to the University of California by American Telephone and Telegraph
7 Co. or Unix System Laboratories, Inc. and are reproduced herein with
8 the permission of UNIX System Laboratories, Inc.
9 
10 Redistribution and use in source and binary forms, with or without
11 modification, are permitted provided that the following conditions
12 are met:
13 1. Redistributions of source code must retain the above copyright
14 notice, this list of conditions and the following disclaimer.
15 2. Redistributions in binary form must reproduce the above copyright
16 notice, this list of conditions and the following disclaimer in the
17 documentation and/or other materials provided with the distribution.
18 3. Neither the name of the University nor the names of its contributors
19 may be used to endorse or promote products derived from this software
20 without specific prior written permission.
21 
22 THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
23 ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
24 IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
25 ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
26 FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
27 DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
28 OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
29 HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
30 LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
31 OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
32 SUCH DAMAGE.
33  */
34 /*
35  * string.h
36  *
37  * Definitions for memory and string functions.
38  */
39 
40 #ifndef _STRING_H_
41 #define	_STRING_H_
42 
43 #include <sys/cdefs.h>
44 
45 #define __need_size_t
46 #define __need_NULL
47 #include <stddef.h>
48 
49 #if __POSIX_VISIBLE >= 200809
50 #include <sys/_locale.h>
51 #endif
52 
53 #if __BSD_VISIBLE
54 #include <strings.h>
55 #endif
56 
57 _BEGIN_STD_C
58 
59 /* There are two common basename variants.  If you do NOT #include <libgen.h>
60    and you do
61 
62      #define _GNU_SOURCE
63      #include <string.h>
64 
65    you get the GNU version.  Otherwise you get the POSIX versionfor which you
66    should #include <libgen.h>i for the function prototype.  POSIX requires that
67    #undef basename will still let you invoke the underlying function.  However,
68    this also implies that the POSIX version is used in this case.  That's made
69    sure here. */
70 #if __GNU_VISIBLE && !defined(basename)
71 # ifdef __ASMNAME
72 #  define basename basename
73 char *__nonnull ((1))
74          basename (const char *) _ASMNAME("__gnu_basename");
75 # else
76 #  define basename(s) (__gnu_basename(s))
77 # endif
78 #endif
79 
80 #if __MISC_VISIBLE || __POSIX_VISIBLE
81 void    *memccpy (void *__restrict, const void *__restrict, int, size_t);
82 #endif
83 void    *memchr (const void *, int, size_t);
84 int 	 memcmp (const void *, const void *, size_t);
85 void    *memcpy (void *__restrict, const void *__restrict, size_t);
86 #if __GNU_VISIBLE
87 void    *memmem (const void *, size_t, const void *, size_t);
88 #endif
89 void    *memmove (void *, const void *, size_t);
90 #if __GNU_VISIBLE
91 void    *mempcpy (void *, const void *, size_t);
92 void    *memrchr (const void *, int, size_t);
93 #endif
94 void    *memset (void *, int, size_t);
95 #if __GNU_VISIBLE
96 void    *rawmemchr (const void *, int);
97 #endif
98 #if __POSIX_VISIBLE >= 200809
99 char 	*stpcpy (char *__restrict, const char *__restrict);
100 char 	*stpncpy (char *__restrict, const char *__restrict, size_t);
101 #endif
102 #if __GNU_VISIBLE
103 char	*strcasestr (const char *, const char *);
104 #endif
105 char 	*strcat (char *__restrict, const char *__restrict);
106 char 	*strchr (const char *, int);
107 #if __GNU_VISIBLE
108 char 	*strchrnul (const char *, int);
109 #endif
110 int	 strcmp (const char *, const char *);
111 int	 strcoll (const char *, const char *);
112 #if __POSIX_VISIBLE >= 200809
113 int	 strcoll_l (const char *, const char *, locale_t);
114 #endif
115 char 	*strcpy (char *__restrict, const char *__restrict);
116 size_t	 strcspn (const char *, const char *);
117 #if __MISC_VISIBLE || __POSIX_VISIBLE >= 200809 || __XSI_VISIBLE >= 4
118 void	free (void *) _NOTHROW; /* for __malloc_like */
119 char 	*strdup (const char *) __malloc_like __result_use_check;
120 #endif
121 #if __GNU_VISIBLE && defined(__GNUC__)
122 #define strdupa(__s) \
123 	(__extension__ ({const char *__sin = (__s); \
124 			 size_t __len = strlen (__sin) + 1; \
125 			 char * __sout = (char *) __builtin_alloca (__len); \
126 			 (char *) memcpy (__sout, __sin, __len);}))
127 #define strndupa(__s, __n) \
128 	(__extension__ ({const char *__sin = (__s); \
129 			 size_t __len = strnlen (__sin, (__n)) + 1; \
130 			 char *__sout = (char *) __builtin_alloca (__len); \
131 			 __sout[__len-1] = '\0'; \
132 			 (char *) memcpy (__sout, __sin, __len-1);}))
133 #endif /* __GNU_VISIBLE && __GNUC__ */
134 char 	*strerror (int);
135 #if __POSIX_VISIBLE >= 200809
136 char	*strerror_l (int, locale_t);
137 #endif
138 /* There are two common strerror_r variants.  If you request
139    _GNU_SOURCE, you get the GNU version; otherwise you get the POSIX
140    version.  POSIX requires that #undef strerror_r will still let you
141    invoke the underlying function, but that requires gcc support.  */
142 #if __GNU_VISIBLE
143 char    *strerror_r (int, char *, size_t);
144 #elif __POSIX_VISIBLE >= 200112
145 # ifdef __GNUC__
146 int	 strerror_r (int, char *, size_t) _ASMNAME("__xpg_strerror_r");
147 # else
148 int	__xpg_strerror_r (int, char *, size_t);
149 #  define strerror_r __xpg_strerror_r
150 # endif
151 #endif
152 #if __BSD_VISIBLE
153 size_t   strlcat (char *, const char *, size_t);
154 #endif
155 size_t	 strlen (const char *);
156 #if __BSD_VISIBLE
157 size_t   strlcpy (char *, const char *, size_t);
158 #endif
159 #if __MISC_VISIBLE
160 char	*strlwr (char *);
161 #endif
162 char 	*strncat (char *__restrict, const char *__restrict, size_t);
163 int	 strncmp (const char *, const char *, size_t);
164 char 	*strncpy (char *__restrict, const char *__restrict, size_t);
165 #if __POSIX_VISIBLE >= 200809
166 char 	*strndup (const char *, size_t) __malloc_like __result_use_check;
167 #endif
168 #if __POSIX_VISIBLE >= 200809 || __ZEPHYR_VISIBLE
169 size_t	 strnlen (const char *, size_t);
170 #endif
171 #if __BSD_VISIBLE
172 char    *strnstr(const char *, const char *, size_t) __pure;
173 #endif
174 char 	*strpbrk (const char *, const char *);
175 char 	*strrchr (const char *, int);
176 #if __BSD_VISIBLE
177 char 	*strsep (char **, const char *);
178 #endif
179 #if __POSIX_VISIBLE >= 200809
180 char	*strsignal (int __signo);
181 #endif
182 size_t	 strspn (const char *, const char *);
183 char 	*strstr (const char *, const char *);
184 char 	*strtok (char *__restrict, const char *__restrict);
185 #if __MISC_VISIBLE || __POSIX_VISIBLE || __ZEPHYR_VISIBLE
186 char 	*strtok_r (char *__restrict, const char *__restrict, char **__restrict);
187 #endif
188 #if __MISC_VISIBLE
189 char	*strupr (char *);
190 #endif
191 #if __GNU_VISIBLE
192 int	 strverscmp (const char *, const char *);
193 #endif
194 size_t	 strxfrm (char *__restrict, const char *__restrict, size_t);
195 #if __POSIX_VISIBLE >= 200809
196 size_t	 strxfrm_l (char *__restrict, const char *__restrict, size_t, locale_t);
197 #endif
198 #if __BSD_VISIBLE
199 int	 timingsafe_bcmp (const void *, const void *, size_t);
200 int	 timingsafe_memcmp (const void *, const void *, size_t);
201 #endif
202 
203 #if __STDC_WANT_LIB_EXT1__ == 1
204 #include <sys/_types.h>
205 
206 #ifndef _ERRNO_T_DEFINED
207 typedef __errno_t errno_t;
208 #define _ERRNO_T_DEFINED
209 #endif
210 
211 #ifndef _RSIZE_T_DEFINED
212 typedef __rsize_t rsize_t;
213 #define _RSIZE_T_DEFINED
214 #endif
215 
216 errno_t memcpy_s(void *__restrict, rsize_t, const void *__restrict, rsize_t);
217 errno_t memset_s(void *, rsize_t, int, rsize_t);
218 errno_t memmove_s(void *, rsize_t, const void *, rsize_t);
219 errno_t strcpy_s(char *__restrict, rsize_t, const char *__restrict);
220 errno_t strcat_s(char *__restrict, rsize_t, const char *__restrict);
221 errno_t strncpy_s(char *__restrict, rsize_t, const char *__restrict, rsize_t);
222 errno_t strncat_s(char *__restrict, rsize_t, const char *__restrict, rsize_t);
223 size_t strnlen_s(const char *, size_t);
224 errno_t strerror_s(char *, rsize_t, errno_t);
225 size_t strerrorlen_s(errno_t);
226 #endif
227 
228 #include <sys/string.h>
229 
230 _END_STD_C
231 
232 #if __SSP_FORTIFY_LEVEL > 0
233 #include <ssp/string.h>
234 #endif
235 
236 #endif /* _STRING_H_ */
237