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
80 #define ZYAN_PUTC putc
81 #define ZYAN_PUTS puts
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_MALLOC malloc
103 #define ZYAN_REALLOC realloc
110 #define ZYAN_MEMCHR memchr
111 #define ZYAN_MEMCMP memcmp
112 #define ZYAN_MEMCPY memcpy
113 #define ZYAN_MEMMOVE memmove
114 #define ZYAN_MEMSET memset
115 #define ZYAN_STRCAT strcat
116 #define ZYAN_STRCHR strchr
117 #define ZYAN_STRCMP strcmp
118 #define ZYAN_STRCOLL strcoll
119 #define ZYAN_STRCPY strcpy
120 #define ZYAN_STRCSPN strcspn
121 #define ZYAN_STRLEN strlen
122 #define ZYAN_STRNCAT strncat
123 #define ZYAN_STRNCMP strncmp
124 #define ZYAN_STRNCPY strncpy
125 #define ZYAN_STRPBRK strpbrk
126 #define ZYAN_STRRCHR strrchr
127 #define ZYAN_STRSPN strspn
128 #define ZYAN_STRSTR strstr
129 #define ZYAN_STRTOK strtok
130 #define ZYAN_STRXFRM strxfrm
153 #if defined(ZYAN_MSVC) || defined(ZYAN_ICC)
160 # define ZYAN_VA_START __crt_va_start
161 # define ZYAN_VA_ARG __crt_va_arg
162 # define ZYAN_VA_END __crt_va_end
163 # define ZYAN_VA_COPY(destination, source) ((destination) = (source))
165 #elif defined(ZYAN_GNUC)
172 # define ZYAN_VA_START(v, l) __builtin_va_start(v, l)
173 # define ZYAN_VA_END(v) __builtin_va_end(v)
174 # define ZYAN_VA_ARG(v, l) __builtin_va_arg(v, l)
175 # define ZYAN_VA_COPY(d, s) __builtin_va_copy(d, s)
178 # error "Unsupported compiler for no-libc mode."
233 ZYAN_INLINE
void* ZYAN_MEMCHR(
const void* str,
int c, ZyanUSize n)
235 const ZyanU8* p = (ZyanU8*)str;
249 ZYAN_INLINE
int ZYAN_MEMCMP(
const void* s1,
const void* s2, ZyanUSize n)
251 const ZyanU8* p1 = s1, *p2 = s2;
263 ZYAN_INLINE
void* ZYAN_MEMCPY(
void* dst,
const void* src, ZyanUSize n)
265 volatile ZyanU8* dp = dst;
266 const ZyanU8* sp = src;
274 ZYAN_INLINE
void* ZYAN_MEMMOVE(
void* dst,
const void* src, ZyanUSize n)
276 volatile ZyanU8* pd = dst;
277 const ZyanU8* ps = src;
280 for (pd += n, ps += n; n--;)
294 ZYAN_INLINE
void* ZYAN_MEMSET(
void* dst,
int val, ZyanUSize n)
296 volatile ZyanU8* p = dst;
299 *p++ = (
unsigned char)val;
304 ZYAN_INLINE
char* ZYAN_STRCAT(
char* dest,
const char* src)
311 while ((*dest++ = *src++));
315 ZYAN_INLINE
char* ZYAN_STRCHR(
const char* s,
int c)
317 while (*s != (
char)c)
327 ZYAN_INLINE
int ZYAN_STRCMP(
const char* s1,
const char* s2)
329 while (*s1 && (*s1 == *s2))
333 return *(
const ZyanU8*)s1 - *(
const ZyanU8*)s2;
336 ZYAN_INLINE
int ZYAN_STRCOLL(
const char *s1,
const char *s2)
346 ZYAN_INLINE
char* ZYAN_STRCPY(
char* dest,
const char* src)
349 while ((*dest++ = *src++));
353 ZYAN_INLINE ZyanUSize ZYAN_STRCSPN(
const char *s1,
const char *s2)
358 if (ZYAN_STRCHR(s2, *s1))
367 ZYAN_INLINE ZyanUSize ZYAN_STRLEN(
const char* str)
377 ZYAN_INLINE
char* ZYAN_STRNCAT(
char* dest,
const char* src, ZyanUSize n)
386 if (!(*dest++ = *src++))
395 ZYAN_INLINE
int ZYAN_STRNCMP(
const char* s1,
const char* s2, ZyanUSize n)
401 return *(
unsigned char*)(s1 - 1) - *(
unsigned char*)(s2 - 1);
407 ZYAN_INLINE
char* ZYAN_STRNCPY(
char* dest,
const char* src, ZyanUSize n)
416 }
while ((*dest++ = *src++));
424 ZYAN_INLINE
char* ZYAN_STRPBRK(
const char* s1,
const char* s2)
428 if(ZYAN_STRCHR(s2, *s1++))
436 ZYAN_INLINE
char* ZYAN_STRRCHR(
const char* s,
int c)
449 ZYAN_INLINE ZyanUSize ZYAN_STRSPN(
const char* s1,
const char* s2)
452 while (*s1 && ZYAN_STRCHR(s2, *s1++))
459 ZYAN_INLINE
char* ZYAN_STRSTR(
const char* s1,
const char* s2)
461 const ZyanUSize n = ZYAN_STRLEN(s2);
464 if (!ZYAN_MEMCMP(s1++, s2, n))
466 return (
char*)(s1 - 1);
472 ZYAN_INLINE
char* ZYAN_STRTOK(
char* str,
const char* delim)
483 str = p + ZYAN_STRSPN(p, delim);
484 p = str + ZYAN_STRCSPN(str, delim);
489 p = *p ? *p = 0, p + 1 : 0;
493 ZYAN_INLINE ZyanUSize ZYAN_STRXFRM(
char* dest,
const char* src, ZyanUSize n)
495 const ZyanUSize n2 = ZYAN_STRLEN(src);
498 ZYAN_STRCPY(dest, src);
#define ZYAN_UNUSED(x)
Definition: Defines.h:331
va_list ZyanVAList
Definition: LibC.h:63
FILE ZyanFile
Definition: LibC.h:89