7 #if !defined(__ROMCC__)
8 #include <console/vtxprintf.h>
11 /* Stringify a token */
13 #define _STRINGIFY(x) #x
14 #define STRINGIFY(x) _STRINGIFY(x)
17 void *memcpy(void *dest
, const void *src
, size_t n
);
18 void *memmove(void *dest
, const void *src
, size_t n
);
19 void *memset(void *s
, int c
, size_t n
);
20 int memcmp(const void *s1
, const void *s2
, size_t n
);
21 void *memchr(const void *s
, int c
, size_t n
);
22 #if !defined(__ROMCC__)
23 int snprintf(char *buf
, size_t size
, const char *fmt
, ...);
24 int vsnprintf(char *buf
, size_t size
, const char *fmt
, va_list args
);
27 // simple string functions
29 static inline size_t strnlen(const char *src
, size_t max
)
32 while ((*src
++) && (i
< max
))
37 static inline size_t strlen(const char *src
)
45 static inline char *strchr(const char *s
, int c
)
54 #if !defined(__PRE_RAM__)
55 static inline char *strdup(const char *s
)
57 size_t sz
= strlen(s
) + 1;
63 static inline char *strconcat(const char *s1
, const char *s2
)
65 size_t sz_1
= strlen(s1
);
66 size_t sz_2
= strlen(s2
);
67 char *d
= malloc(sz_1
+ sz_2
+ 1);
69 memcpy(d
+ sz_1
, s2
, sz_2
+ 1);
75 * Find a character in a string.
77 * @param s The string.
78 * @param c The character.
79 * @return A pointer to the last occurrence of the character in the
80 * string, or NULL if the character was not encountered within the string.
82 static inline char *strrchr(const char *s
, int c
)
84 char *p
= (char *)s
+ strlen(s
);
94 static inline char *strncpy(char *to
, const char *from
, int count
)
96 register char *ret
= to
;
114 static inline char *strcpy(char *dst
, const char *src
)
125 static inline int strcmp(const char *s1
, const char *s2
)
129 while ((r
= (*s1
- *s2
)) == 0 && *s1
) {
136 static inline int strncmp(const char *s1
, const char *s2
, int maxlen
)
140 for (i
= 0; i
< maxlen
; i
++) {
141 if ((s1
[i
] != s2
[i
]) || (s1
[i
] == '\0'))
142 return s1
[i
] - s2
[i
];
148 static inline int isspace(int c
)
151 case ' ': case '\f': case '\n':
152 case '\r': case '\t': case '\v':
159 static inline int isdigit(int c
)
161 return (c
>= '0' && c
<= '9');
164 static inline int isxdigit(int c
)
166 return ((c
>= '0' && c
<= '9') ||
167 (c
>= 'a' && c
<= 'f') ||
168 (c
>= 'A' && c
<= 'F'));
171 static inline int isupper(int c
)
173 return (c
>= 'A' && c
<= 'Z');
176 static inline int islower(int c
)
178 return (c
>= 'a' && c
<= 'z');
181 static inline int toupper(int c
)
188 static inline int tolower(int c
)
194 #endif /* STRING_H */