35#ifndef ZYAN_CUSTOM_LIBC
52#define ZYAN_ERRNO errno
65#define ZYAN_VA_START va_start
66#define ZYAN_VA_ARG va_arg
67#define ZYAN_VA_END va_end
68#define ZYAN_VA_COPY(dest, source) va_copy((dest), (source))
76#define ZYAN_FPUTS fputs
77#define ZYAN_FPUTC fputc
78#define ZYAN_FPRINTF fprintf
79#define ZYAN_PRINTF printf
82#define ZYAN_SCANF scanf
83#define ZYAN_SSCANF sscanf
84#define ZYAN_VSNPRINTF vsnprintf
91#define ZYAN_STDIN stdin
92#define ZYAN_STDOUT stdout
93#define ZYAN_STDERR stderr
100#define ZYAN_CALLOC calloc
101#define ZYAN_FREE free
102#define ZYAN_GETENV getenv
103#define ZYAN_MALLOC malloc
104#define ZYAN_REALLOC realloc
111#define ZYAN_MEMCHR memchr
112#define ZYAN_MEMCMP memcmp
113#define ZYAN_MEMCPY memcpy
114#define ZYAN_MEMMOVE memmove
115#define ZYAN_MEMSET memset
116#define ZYAN_STRCAT strcat
117#define ZYAN_STRCHR strchr
118#define ZYAN_STRCMP strcmp
119#define ZYAN_STRCOLL strcoll
120#define ZYAN_STRCPY strcpy
121#define ZYAN_STRCSPN strcspn
122#define ZYAN_STRLEN strlen
123#define ZYAN_STRNCAT strncat
124#define ZYAN_STRNCMP strncmp
125#define ZYAN_STRNCPY strncpy
126#define ZYAN_STRPBRK strpbrk
127#define ZYAN_STRRCHR strrchr
128#define ZYAN_STRSPN strspn
129#define ZYAN_STRSTR strstr
130#define ZYAN_STRTOK strtok
131#define ZYAN_STRXFRM strxfrm
154#if defined(ZYAN_MSVC) || defined(ZYAN_ICC)
161# define ZYAN_VA_START __crt_va_start
162# define ZYAN_VA_ARG __crt_va_arg
163# define ZYAN_VA_END __crt_va_end
164# define ZYAN_VA_COPY(destination, source) ((destination) = (source))
166#elif defined(ZYAN_GNUC)
173# define ZYAN_VA_START(v, l) __builtin_va_start(v, l)
174# define ZYAN_VA_END(v) __builtin_va_end(v)
175# define ZYAN_VA_ARG(v, l) __builtin_va_arg(v, l)
176# define ZYAN_VA_COPY(d, s) __builtin_va_copy(d, s)
179# error "Unsupported compiler for no-libc mode."
234ZYAN_INLINE
void* ZYAN_MEMCHR(
const void* str,
int c, ZyanUSize n)
236 const ZyanU8* p = (ZyanU8*)str;
250ZYAN_INLINE
int ZYAN_MEMCMP(
const void* s1,
const void* s2, ZyanUSize n)
252 const ZyanU8* p1 = s1, *p2 = s2;
264ZYAN_INLINE
void* ZYAN_MEMCPY(
void* dst,
const void* src, ZyanUSize n)
266 volatile ZyanU8* dp = dst;
267 const ZyanU8* sp = src;
275ZYAN_INLINE
void* ZYAN_MEMMOVE(
void* dst,
const void* src, ZyanUSize n)
277 volatile ZyanU8* pd = dst;
278 const ZyanU8* ps = src;
281 for (pd += n, ps += n; n--;)
295ZYAN_INLINE
void* ZYAN_MEMSET(
void* dst,
int val, ZyanUSize n)
297 volatile ZyanU8* p = dst;
300 *p++ = (
unsigned char)val;
305ZYAN_INLINE
char* ZYAN_STRCAT(
char* dest,
const char* src)
312 while ((*dest++ = *src++));
316ZYAN_INLINE
char* ZYAN_STRCHR(
const char* s,
int c)
318 while (*s != (
char)c)
328ZYAN_INLINE
int ZYAN_STRCMP(
const char* s1,
const char* s2)
330 while (*s1 && (*s1 == *s2))
334 return *(
const ZyanU8*)s1 - *(
const ZyanU8*)s2;
337ZYAN_INLINE
int ZYAN_STRCOLL(
const char *s1,
const char *s2)
347ZYAN_INLINE
char* ZYAN_STRCPY(
char* dest,
const char* src)
350 while ((*dest++ = *src++));
354ZYAN_INLINE ZyanUSize ZYAN_STRCSPN(
const char *s1,
const char *s2)
359 if (ZYAN_STRCHR(s2, *s1))
368ZYAN_INLINE ZyanUSize ZYAN_STRLEN(
const char* str)
378ZYAN_INLINE
char* ZYAN_STRNCAT(
char* dest,
const char* src, ZyanUSize n)
387 if (!(*dest++ = *src++))
396ZYAN_INLINE
int ZYAN_STRNCMP(
const char* s1,
const char* s2, ZyanUSize n)
402 return *(
unsigned char*)(s1 - 1) - *(
unsigned char*)(s2 - 1);
408ZYAN_INLINE
char* ZYAN_STRNCPY(
char* dest,
const char* src, ZyanUSize n)
417 }
while ((*dest++ = *src++));
425ZYAN_INLINE
char* ZYAN_STRPBRK(
const char* s1,
const char* s2)
429 if(ZYAN_STRCHR(s2, *s1++))
437ZYAN_INLINE
char* ZYAN_STRRCHR(
const char* s,
int c)
450ZYAN_INLINE ZyanUSize ZYAN_STRSPN(
const char* s1,
const char* s2)
453 while (*s1 && ZYAN_STRCHR(s2, *s1++))
460ZYAN_INLINE
char* ZYAN_STRSTR(
const char* s1,
const char* s2)
462 const ZyanUSize n = ZYAN_STRLEN(s2);
465 if (!ZYAN_MEMCMP(s1++, s2, n))
467 return (
char*)(s1 - 1);
473ZYAN_INLINE
char* ZYAN_STRTOK(
char* str,
const char* delim)
484 str = p + ZYAN_STRSPN(p, delim);
485 p = str + ZYAN_STRCSPN(str, delim);
490 p = *p ? *p = 0, p + 1 : 0;
494ZYAN_INLINE ZyanUSize ZYAN_STRXFRM(
char* dest,
const char* src, ZyanUSize n)
496 const ZyanUSize n2 = ZYAN_STRLEN(src);
499 ZYAN_STRCPY(dest, src);
#define ZYAN_UNUSED(x)
Definition Defines.h:345
va_list ZyanVAList
Definition LibC.h:63
FILE ZyanFile
Definition LibC.h:89