18#if defined(__GNUC__) && !defined(__clang__)
19#pragma GCC optimize("no-tree-loop-distribute-patterns")
27#if !defined(RA8_OFF_TARGET) || defined(RA8_TEST_FREESTANDING)
45 while (s[len] !=
'\0') {
65size_t strnlen(
const char* s,
size_t maxlen)
68 while (len < maxlen) {
93int strcmp(
const char* s1,
const char* s2)
95 const uint8_t* p1 = (
const uint8_t*)s1;
96 const uint8_t* p2 = (
const uint8_t*)s2;
104 return (
int)*p1 - (int)*p2;
124int strncmp(
const char* s1,
const char* s2,
size_t n)
129 const uint8_t* p1 = (
const uint8_t*)s1;
130 const uint8_t* p2 = (
const uint8_t*)s2;
131 for (
size_t i = 0U; i < n; ++i) {
132 if (p1[i] != p2[i]) {
133 return (
int)p1[i] - (int)p2[i];
159 const char target = (char)c;
160 const char* cursor = s;
161 char* result =
nullptr;
162 while (*cursor !=
'\0') {
163 if (*cursor == target) {
164 (void)
memcpy((
void*)&result, (
const void*)&cursor,
sizeof(result));
169 if (target ==
'\0') {
170 (void)
memcpy((
void*)&result, (
const void*)&cursor,
sizeof(result));
192 const char target = (char)c;
193 const char* cursor = s;
194 const char* last =
nullptr;
195 while (*cursor !=
'\0') {
196 if (*cursor == target) {
201 const char* result_source = (target ==
'\0') ? cursor : last;
202 char* result =
nullptr;
203 (void)
memcpy((
void*)&result, (
const void*)&result_source,
sizeof(result));
222char*
strstr(
const char* haystack,
const char* needle)
224 if (needle[0] ==
'\0') {
225 char* result =
nullptr;
226 (void)
memcpy((
void*)&result, (
const void*)&haystack,
sizeof(result));
229 for (
size_t i = 0U; haystack[i] !=
'\0'; ++i) {
231 while (needle[j] !=
'\0') {
232 if (haystack[i + j] != needle[j]) {
237 if (needle[j] ==
'\0') {
238 const char* result_source = &haystack[i];
239 char* result =
nullptr;
240 (void)
memcpy((
void*)&result, (
const void*)&result_source,
sizeof(result));
264 while (src[i] !=
'\0') {
288char*
strncpy(
char* dst,
const char* src,
size_t n)
292 if (src[i] ==
'\0') {
Project-owned freestanding C runtime ABI primitives.
void * memcpy(void *dst, const void *src, size_t n)
Copy memory area between non-overlapping regions.
int strncmp(const char *s1, const char *s2, size_t n)
Compare two strings up to a specified length.
int strcmp(const char *s1, const char *s2)
Compare two null-terminated strings.
char * strcpy(char *dst, const char *src)
Copy string to destination buffer.
char * strncpy(char *dst, const char *src, size_t n)
Copy bounded string to destination buffer.
size_t strlen(const char *s)
Calculate string length.
char * strstr(const char *haystack, const char *needle)
Locate substring in string.
char * strchr(const char *s, int c)
Locate first occurrence of character in string.
char * strrchr(const char *s, int c)
Locate last occurrence of character in string.
size_t strnlen(const char *s, size_t maxlen)
Calculate bounded string length.