static __attribute__((unused)) int memcmp(constvoid *s1, constvoid *s2, size_t n)
{
size_t ofs = 0; int c1 = 0;
while (ofs < n && !(c1 = ((unsignedchar *)s1)[ofs] - ((unsignedchar *)s2)[ofs])) {
ofs++;
} return c1;
}
#ifndef NOLIBC_ARCH_HAS_MEMMOVE /* might be ignored by the compiler without -ffreestanding, then found as *missing.
*/ void *memmove(void *dst, constvoid *src, size_t len);
__attribute__((weak,unused,section(".text.nolibc_memmove"))) void *memmove(void *dst, constvoid *src, size_t len)
{
size_t dir, pos;
#ifndef NOLIBC_ARCH_HAS_MEMCPY /* must be exported, as it's used by libgcc on ARM */ void *memcpy(void *dst, constvoid *src, size_t len);
__attribute__((weak,unused,section(".text.nolibc_memcpy"))) void *memcpy(void *dst, constvoid *src, size_t len)
{
size_t pos = 0;
#ifndef NOLIBC_ARCH_HAS_MEMSET /* might be ignored by the compiler without -ffreestanding, then found as *missing.
*/ void *memset(void *dst, int b, size_t len);
__attribute__((weak,unused,section(".text.nolibc_memset"))) void *memset(void *dst, int b, size_t len)
{ char *p = dst;
while (len--) { /* prevent gcc from recognizing memset() here */
__asm__ volatile("");
*(p++) = b;
} return dst;
} #endif/* #ifndef NOLIBC_ARCH_HAS_MEMSET */
static __attribute__((unused)) char *strchr(constchar *s, int c)
{ while (*s) { if (*s == (char)c) return (char *)s;
s++;
} return NULL;
}
static __attribute__((unused)) int strcmp(constchar *a, constchar *b)
{ unsignedint c; int diff;
while (!(diff = (unsignedchar)*a++ - (c = (unsignedchar)*b++)) && c)
; return diff;
}
/* this function is only used with arguments that are not constants or when *it'snotknownbecauseoptimizationsaredisabled.Notethatgcc12 *recognizesanstrlen()patternandreplacesitwithajumptostrlen(), *thusitself,hencetheasm()statementbelowthat'smeanttodisablethis *confusingpractice.
*/
size_t strlen(constchar *str);
__attribute__((weak,unused,section(".text.nolibc_strlen")))
size_t strlen(constchar *str)
{
size_t len;
for (len = 0; str[len]; len++)
__asm__(""); return len;
}
/* do not trust __builtin_constant_p() at -O0, as clang will emit a test and *thetwobranches,thenwillrelyonanexternaldefinitionofstrlen().
*/ #ifdefined(__OPTIMIZE__) #define nolibc_strlen(x) strlen(x) #define strlen(str) ({ \
__builtin_constant_p((str)) ? \
__builtin_strlen((str)) : \
nolibc_strlen((str)); \
}) #endif
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.