VSF Documented
string.h
Go to the documentation of this file.
1#ifndef __SIMPLE_LIBC_STRING_H__
2#define __SIMPLE_LIBC_STRING_H__
3
5
6#if VSF_LINUX_CFG_RELATIVE_PATH == ENABLED && VSF_LINUX_USE_SIMPLE_LIBC == ENABLED
7# include "./stddef.h"
8#else
9# include <stddef.h>
10#endif
11
14
15#if __IS_COMPILER_LLVM__
16# pragma clang diagnostic push
17# pragma clang diagnostic ignored "-Wbuiltin-requires-header"
18# pragma clang diagnostic ignored "-Wincompatible-library-redeclaration"
19# pragma clang diagnostic ignored "-Winconsistent-dllimport"
20#endif
21
22#ifdef __cplusplus
23extern "C" {
24#endif
25
26#if VSF_LINUX_LIBC_CFG_WRAPPER == ENABLED
27#if !(VSF_LINUX_SIMPLE_STDLIB_CFG_HEAP_MONITOR == ENABLED) \
28 || !(VSF_LINUX_SIMPLE_STDLIB_CFG_HEAP_MONITOR_TRACE_CALLER == ENABLED)
29// strdup will be macro in this condition, so no need to wrapper
30#define strdup VSF_LINUX_LIBC_WRAPPER(strdup)
31# endif
32#define strndup VSF_LINUX_LIBC_WRAPPER(strndup)
33#endif
34
35#if VSF_LINUX_APPLET_USE_LIBC_STRING == ENABLED
38
82# ifndef __VSF_APPLET__
84# endif
85#endif
86
87#if defined(__VSF_APPLET__) && (defined(__VSF_APPLET_LIB__) || defined(__VSF_APPLET_LINUX_LIBC_STRING_LIB__))\
88 && VSF_APPLET_CFG_ABI_PATCH != ENABLED && VSF_LINUX_APPLET_USE_LIBC_STRING == ENABLED
89
90#ifndef VSF_LINUX_APPLET_LIBC_STRING_VPLT
91# if VSF_LINUX_USE_APPLET == ENABLED
92# define VSF_LINUX_APPLET_LIBC_STRING_VPLT \
93 ((vsf_linux_libc_string_vplt_t *)(VSF_LINUX_APPLET_VPLT->libc_string_vplt))
94# else
95# define VSF_LINUX_APPLET_LIBC_STRING_VPLT \
96 ((vsf_linux_libc_string_vplt_t *)vsf_vplt((void *)0))
97# endif
98#endif
99
100#define VSF_LINUX_APPLET_LIBC_STRING_ENTRY(__NAME) \
101 VSF_APPLET_VPLT_ENTRY_FUNC_ENTRY(VSF_LINUX_APPLET_LIBC_STRING_VPLT, __NAME)
102#define VSF_LINUX_APPLET_LIBC_STRING_IMP(...) \
103 VSF_APPLET_VPLT_ENTRY_FUNC_IMP(VSF_LINUX_APPLET_LIBC_STRING_VPLT, __VA_ARGS__)
104
105#if VSF_LINUX_SIMPLE_STDLIB_CFG_HEAP_MONITOR == ENABLED
107VSF_LINUX_APPLET_LIBC_STRING_IMP(____strdup_ex, char *, vsf_linux_process_t *process, const char *str, const char *file, const char *func, int line) {
109 return VSF_LINUX_APPLET_LIBC_STRING_ENTRY(____strdup_ex)(process, str, file, func, line);
110}
111#endif
112VSF_LINUX_APPLET_LIBC_STRING_IMP(ffs, int, int i) {
114 return VSF_LINUX_APPLET_LIBC_STRING_ENTRY(ffs)(i);
115}
116VSF_LINUX_APPLET_LIBC_STRING_IMP(memset, void *, void *s, int ch, size_t n) {
118 return VSF_LINUX_APPLET_LIBC_STRING_ENTRY(memset)(s, ch, n);
119}
120VSF_LINUX_APPLET_LIBC_STRING_IMP(strlen, size_t, const char *str) {
122 return VSF_LINUX_APPLET_LIBC_STRING_ENTRY(strlen)(str);
123}
124VSF_LINUX_APPLET_LIBC_STRING_IMP(strnlen, size_t, const char *str, size_t maxlen) {
126 return VSF_LINUX_APPLET_LIBC_STRING_ENTRY(strnlen)(str, maxlen);
127}
128VSF_LINUX_APPLET_LIBC_STRING_IMP(strcmp, int, const char *str1, const char *str2) {
130 return VSF_LINUX_APPLET_LIBC_STRING_ENTRY(strcmp)(str1, str2);
131}
132VSF_LINUX_APPLET_LIBC_STRING_IMP(strncmp, int, const char *str1, const char *str2, size_t n) {
134 return VSF_LINUX_APPLET_LIBC_STRING_ENTRY(strncmp)(str1, str2, n);
135}
136VSF_LINUX_APPLET_LIBC_STRING_IMP(strdup, char *, const char *str) {
138 return VSF_LINUX_APPLET_LIBC_STRING_ENTRY(strdup)(str);
139}
140VSF_LINUX_APPLET_LIBC_STRING_IMP(strcpy, char *, char *dest, const char *src) {
142 return VSF_LINUX_APPLET_LIBC_STRING_ENTRY(strcpy)(dest, src);
143}
144VSF_LINUX_APPLET_LIBC_STRING_IMP(strncpy, char *, char *dest, const char *src, size_t n) {
146 return VSF_LINUX_APPLET_LIBC_STRING_ENTRY(strncpy)(dest, src, n);
147}
148VSF_LINUX_APPLET_LIBC_STRING_IMP(stpcpy, char *, char *dest, const char *src) {
150 return VSF_LINUX_APPLET_LIBC_STRING_ENTRY(stpcpy)(dest, src);
151}
152VSF_LINUX_APPLET_LIBC_STRING_IMP(stpncpy, char *, char *dest, const char *src, size_t n) {
154 return VSF_LINUX_APPLET_LIBC_STRING_ENTRY(stpncpy)(dest, src, n);
155}
156VSF_LINUX_APPLET_LIBC_STRING_IMP(strcat, char *, char *dest, const char *src) {
158 return VSF_LINUX_APPLET_LIBC_STRING_ENTRY(strcat)(dest, src);
159}
160VSF_LINUX_APPLET_LIBC_STRING_IMP(strncat, char *, char *dest, const char *str, size_t n) {
162 return VSF_LINUX_APPLET_LIBC_STRING_ENTRY(strncat)(dest, str, n);
163}
164VSF_LINUX_APPLET_LIBC_STRING_IMP(strcoll, int, const char *str1, const char *str2) {
166 return VSF_LINUX_APPLET_LIBC_STRING_ENTRY(strcoll)(str1, str2);
167}
168VSF_LINUX_APPLET_LIBC_STRING_IMP(strtok, char *, char *str, const char *delim) {
170 return VSF_LINUX_APPLET_LIBC_STRING_ENTRY(strtok)(str, delim);
171}
172VSF_LINUX_APPLET_LIBC_STRING_IMP(strtok_r, char *, char *str, const char *delim, char **saveptr) {
174 return VSF_LINUX_APPLET_LIBC_STRING_ENTRY(strtok_r)(str, delim, saveptr);
175}
176VSF_LINUX_APPLET_LIBC_STRING_IMP(strxfrm, size_t, char *dest, const char *src, size_t n) {
178 return VSF_LINUX_APPLET_LIBC_STRING_ENTRY(strxfrm)(dest, src, n);
179}
180VSF_LINUX_APPLET_LIBC_STRING_IMP(strspn, size_t, const char *str1, const char *str2) {
182 return VSF_LINUX_APPLET_LIBC_STRING_ENTRY(strspn)(str1, str2);
183}
184VSF_LINUX_APPLET_LIBC_STRING_IMP(strsep, char *, char **strp, const char *delim) {
186 return VSF_LINUX_APPLET_LIBC_STRING_ENTRY(strsep)(strp, delim);
187}
188VSF_LINUX_APPLET_LIBC_STRING_IMP(strcspn, size_t, const char *str1, const char *str2) {
190 return VSF_LINUX_APPLET_LIBC_STRING_ENTRY(strcspn)(str1, str2);
191}
192VSF_LINUX_APPLET_LIBC_STRING_IMP(strpbrk, char *, const char *str1, const char *str2) {
194 return VSF_LINUX_APPLET_LIBC_STRING_ENTRY(strpbrk)(str1, str2);
195}
196VSF_LINUX_APPLET_LIBC_STRING_IMP(strerror, char *, int errnum) {
198 return VSF_LINUX_APPLET_LIBC_STRING_ENTRY(strerror)(errnum);
199}
200VSF_LINUX_APPLET_LIBC_STRING_IMP(strcasecmp, int, const char *str1, const char *str2) {
202 return VSF_LINUX_APPLET_LIBC_STRING_ENTRY(strcasecmp)(str1, str2);
203}
204VSF_LINUX_APPLET_LIBC_STRING_IMP(strncasecmp, int, const char *str1, const char *str2, size_t n) {
206 return VSF_LINUX_APPLET_LIBC_STRING_ENTRY(strncasecmp)(str1, str2, n);
207}
208VSF_LINUX_APPLET_LIBC_STRING_IMP(memcpy, void *, void *dest, const void *src, size_t n) {
210 return VSF_LINUX_APPLET_LIBC_STRING_ENTRY(memcpy)(dest, src, n);
211}
212VSF_LINUX_APPLET_LIBC_STRING_IMP(mempcpy, void *, void *dest, const void *src, size_t n) {
214 return VSF_LINUX_APPLET_LIBC_STRING_ENTRY(mempcpy)(dest, src, n);
215}
216VSF_LINUX_APPLET_LIBC_STRING_IMP(strlcpy, size_t, char *dest, const char *src, size_t n) {
218 return VSF_LINUX_APPLET_LIBC_STRING_ENTRY(strlcpy)(dest, src, n);
219}
220VSF_LINUX_APPLET_LIBC_STRING_IMP(strstr, char *, const char *str1, const char *str2) {
222 return VSF_LINUX_APPLET_LIBC_STRING_ENTRY(strstr)(str1, str2);
223}
224VSF_LINUX_APPLET_LIBC_STRING_IMP(strcasestr, char *, const char *str1, const char *str2) {
226 return VSF_LINUX_APPLET_LIBC_STRING_ENTRY(strcasestr)(str1, str2);
227}
228VSF_LINUX_APPLET_LIBC_STRING_IMP(strchr, char *, const char *str, int c) {
230 return VSF_LINUX_APPLET_LIBC_STRING_ENTRY(strchr)(str, c);
231}
232VSF_LINUX_APPLET_LIBC_STRING_IMP(strrchr, char *, const char *str, int c) {
234 return VSF_LINUX_APPLET_LIBC_STRING_ENTRY(strrchr)(str, c);
235}
236VSF_LINUX_APPLET_LIBC_STRING_IMP(strchrnul, char *, const char *str, int c) {
238 return VSF_LINUX_APPLET_LIBC_STRING_ENTRY(strchrnul)(str, c);
239}
240VSF_LINUX_APPLET_LIBC_STRING_IMP(memmove, void *, void *dest, const void *src, size_t n) {
242 return VSF_LINUX_APPLET_LIBC_STRING_ENTRY(memmove)(dest, src, n);
243}
244VSF_LINUX_APPLET_LIBC_STRING_IMP(memcmp, int, const void *str1, const void *str2, size_t n) {
246 return VSF_LINUX_APPLET_LIBC_STRING_ENTRY(memcmp)(str1, str2, n);
247}
248VSF_LINUX_APPLET_LIBC_STRING_IMP(memchr, void *, const void *buf, int ch, size_t count) {
250 return VSF_LINUX_APPLET_LIBC_STRING_ENTRY(memchr)(buf, ch, count);
251}
252VSF_LINUX_APPLET_LIBC_STRING_IMP(memrchr, void *, const void *buf, int ch, size_t count) {
254 return VSF_LINUX_APPLET_LIBC_STRING_ENTRY(memrchr)(buf, ch, count);
255}
256VSF_LINUX_APPLET_LIBC_STRING_IMP(strverscmp, int, const char *str1, const char *str2) {
258 return VSF_LINUX_APPLET_LIBC_STRING_ENTRY(strverscmp)(str1, str2);
259}
260VSF_LINUX_APPLET_LIBC_STRING_IMP(strndup, char *, const char *str, size_t n) {
262 return VSF_LINUX_APPLET_LIBC_STRING_ENTRY(strndup)(str, n);
263}
264VSF_LINUX_APPLET_LIBC_STRING_IMP(strsignal, char *, int sig) {
266 return VSF_LINUX_APPLET_LIBC_STRING_ENTRY(strsignal)(sig);
267}
268VSF_LINUX_APPLET_LIBC_STRING_IMP(sigdescr_np, const char *, int sig) {
270 return VSF_LINUX_APPLET_LIBC_STRING_ENTRY(sigdescr_np)(sig);
271}
272VSF_LINUX_APPLET_LIBC_STRING_IMP(sigabbrev_np, const char *, int sig) {
274 return VSF_LINUX_APPLET_LIBC_STRING_ENTRY(sigabbrev_np)(sig);
275}
276
277#else // __VSF_APPLET__ && VSF_LINUX_APPLET_USE_LIBC_STRING
278
279int ffs(int i);
280void * memset(void *s, int ch, size_t n);
281size_t strlen(const char *str);
282size_t strnlen(const char *str, size_t maxlen);
283int strcmp(const char *str1, const char *str2);
284int strncmp(const char *str1, const char *str2, size_t n);
285int strverscmp(const char *str1, const char *str2);
286
287#if VSF_LINUX_SIMPLE_STDLIB_CFG_HEAP_MONITOR == ENABLED
289char * ____strdup_ex(vsf_linux_process_t *process, const char *str, const char *file, const char *func, int line);
290#endif
291
292#if VSF_LINUX_SIMPLE_STDLIB_CFG_HEAP_MONITOR == ENABLED \
293 && VSF_LINUX_SIMPLE_STDLIB_CFG_HEAP_MONITOR_TRACE_CALLER == ENABLED
294# define strdup(__str) ____strdup_ex(NULL, (char *)(__str), __FILE__, __FUNCTION__, __LINE__)
295#else
296char * strdup(const char *str);
297#endif
298char * strndup(const char *str, size_t n);
299char * strcpy(char *dest, const char *src);
300char * strncpy(char *dest, const char *src, size_t n);
301ssize_t strscpy(char *dest, const char *src, size_t n);
302char * stpcpy(char *dest, const char *src);
303char * stpncpy(char *dest, const char *src, size_t n);
304char * strcat(char *dest, const char *src);
305char * strncat(char *dest, const char *str, size_t n);
306int strcoll(const char *str1, const char *str2);
307char * strtok(char *str, const char *delim);
308char * strtok_r(char *str, const char *delim, char **saveptr);
309size_t strxfrm(char *dest, const char *src, size_t n);
310size_t strspn(const char *str1, const char *str2);
311char * strsep(char **strp, const char *delim);
312size_t strcspn(const char *str1, const char *str2);
313char * strpbrk(const char *str1, const char *str2);
314char * strerror(int errnum);
315// XSI-compliant
316int strerror_r(int errnum, char *buf, size_t buflen);
317
318#if defined(__WIN__)
319# ifndef _CONST_RETURN
320# ifdef __cplusplus
321# define _CONST_RETURN const
322# else
323# define _CONST_RETURN
324# endif
325# endif
326
327# ifndef __VSF_APPLET__
328int stricmp(const char *str1, const char *str2);
329int strnicmp(const char *str1, const char *str2, size_t n);
330# ifndef strcasecmp
331# define strcasecmp stricmp
332# endif
333# ifndef strncasecmp
334# define strncasecmp strnicmp
335# endif
336# endif
337
338# if defined(__CPU_X64__)
339void * memcpy(void *dest, const void *src, unsigned long long n);
340# else
341void * memcpy(void *dest, const void *src, unsigned int n);
342# endif
343#else
344# define _CONST_RETURN
345int strcasecmp(const char *str1, const char *str2);
346int strncasecmp(const char *str1, const char *str2, size_t n);
347void * memcpy(void *dest, const void *src, size_t n);
348size_t strlcpy(char *dest, const char *src, size_t n);
349#endif
350void * mempcpy(void *dest, const void *src, size_t n);
351
352_CONST_RETURN char * strstr(const char *str1, const char *str2);
353_CONST_RETURN char * strchr(const char *str, int c);
354_CONST_RETURN char * strrchr(const char *str, int c);
355_CONST_RETURN char * strchrnul(const char *str, int c);
356_CONST_RETURN void * memchr(const void *buf, int ch, size_t count);
357_CONST_RETURN void * memrchr(const void *buf, int ch, size_t count);
358char * strcasestr(const char *haystack, const char *needle);
359
360void * memmove(void *dest, const void *src, size_t n);
361int memcmp(const void *str1, const void *str2, size_t n);
362
363char * strsignal(int sig);
364const char * sigdescr_np(int sig);
365const char * sigabbrev_np(int sig);
366
367#endif // __VSF_APPLET__ && VSF_LINUX_APPLET_USE_LIBC_STRING
368
369#ifdef __cplusplus
370}
371#endif
372
373#if __IS_COMPILER_LLVM__
374# pragma clang diagnostic pop
375#endif
376
377#endif
Definition vsf_linux.h:278
int ssize_t
Definition types.h:68
size_t strlen(const char *str)
size_t strspn(const char *str1, const char *str2)
char * strpbrk(const char *str1, const char *str2)
_CONST_RETURN char * strrchr(const char *str, int c)
char * strcat(char *dest, const char *src)
void * memset(void *s, int ch, size_t n)
int ffs(int i)
Definition vsf_linux_glibc_string.c:159
size_t strcspn(const char *str1, const char *str2)
const char * sigdescr_np(int sig)
Definition vsf_linux_glibc_string.c:174
int strncasecmp(const char *str1, const char *str2, size_t n)
void * memmove(void *dest, const void *src, size_t n)
char * stpncpy(char *dest, const char *src, size_t n)
Definition vsf_linux_glibc_string.c:137
char * strtok_r(char *str, const char *delim, char **saveptr)
_CONST_RETURN char * strchr(const char *str, int c)
char * strerror(int errnum)
Definition vsf_linux_glibc_string.c:148
size_t strlcpy(char *dest, const char *src, size_t n)
Definition vsf_xboot.c:39
char * strsignal(int sig)
Definition vsf_linux_glibc_string.c:170
int strerror_r(int errnum, char *buf, size_t buflen)
Definition vsf_linux_glibc_string.c:153
int strcmp(const char *str1, const char *str2)
_CONST_RETURN void * memrchr(const void *buf, int ch, size_t count)
Definition vsf_linux_glibc_string.c:105
char * strtok(char *str, const char *delim)
char * stpcpy(char *dest, const char *src)
Definition vsf_linux_glibc_string.c:131
int strcoll(const char *str1, const char *str2)
char * strncat(char *dest, const char *str, size_t n)
#define _CONST_RETURN
Definition string.h:344
int strcasecmp(const char *str1, const char *str2)
char * strncpy(char *dest, const char *src, size_t n)
char * ____strdup_ex(vsf_linux_process_t *process, const char *str, const char *file, const char *func, int line)
Definition vsf_linux_glibc_string.c:50
ssize_t strscpy(char *dest, const char *src, size_t n)
Definition vsf_linux_glibc_string.c:70
void * mempcpy(void *dest, const void *src, size_t n)
Definition vsf_linux_glibc_string.c:65
_CONST_RETURN void * memchr(const void *buf, int ch, size_t count)
_CONST_RETURN char * strstr(const char *str1, const char *str2)
int strncmp(const char *str1, const char *str2, size_t n)
void * memcpy(void *dest, const void *src, size_t n)
int strverscmp(const char *str1, const char *str2)
Definition vsf_linux_glibc_string.c:165
char * strcpy(char *dest, const char *src)
char * strcasestr(const char *haystack, const char *needle)
int memcmp(const void *str1, const void *str2, size_t n)
#define strndup
Definition string.h:32
const char * sigabbrev_np(int sig)
Definition vsf_linux_glibc_string.c:178
size_t strnlen(const char *str, size_t maxlen)
size_t strxfrm(char *dest, const char *src, size_t n)
#define strdup(__str)
Definition string.h:294
_CONST_RETURN char * strchrnul(const char *str, int c)
Definition vsf_linux_glibc_string.c:123
char * strsep(char **strp, const char *delim)
Definition vsf_xboot.c:44
__VSF_VPLT_DECORATOR__ vsf_linux_libc_string_vplt_t vsf_linux_libc_string_vplt
Definition vsf_linux_glibc_string.c:193
Definition string.h:36
VSF_APPLET_VPLT_ENTRY_FUNC_DEF(____strdup_ex)
VSF_APPLET_VPLT_ENTRY_FUNC_DEF(strcasecmp)
vsf_vplt_info_t info
Definition string.h:37
VSF_APPLET_VPLT_ENTRY_FUNC_DEF(sigabbrev_np)
VSF_APPLET_VPLT_ENTRY_FUNC_DEF(strtok_r)
VSF_APPLET_VPLT_ENTRY_FUNC_DEF(strncasecmp)
VSF_APPLET_VPLT_ENTRY_FUNC_DEF(strerror)
VSF_APPLET_VPLT_ENTRY_FUNC_DEF(strverscmp)
VSF_APPLET_VPLT_ENTRY_FUNC_DEF(strsignal)
VSF_APPLET_VPLT_ENTRY_FUNC_DEF(strchrnul)
VSF_APPLET_VPLT_ENTRY_FUNC_DEF(sigdescr_np)
VSF_APPLET_VPLT_ENTRY_FUNC_DEF(strcasestr)
Definition vsf_cfg.h:95
#define __VSF_VPLT_DECORATOR__
Definition vsf_cfg.h:93
#define VSF_APPLET_VPLT_ENTRY_FUNC_TRACE()
Definition vsf_cfg.h:165
int sig
Definition vsf_thread.h:421