// SPDX-License-Identifier: Apache-2.0 // // for lwIP, shadowing the host's. // // lwIP includes in thirty-odd files. The kernel is built // -ffreestanding and has its own string functions, but the compiler's default // include path still finds /usr/include/string.h -- which declares strlen // returning size_t against a kernel that returns int, and drags sigset_t and // __float128 in behind it. So the lwIP include path puts this directory first. // // The prototypes are repeated here rather than taken from defs.h on purpose. // lwIP includes at the very top of a translation unit, before any // kernel header has been seen, so pulling defs.h in from here would drop the // whole kernel's declarations into a context where its own types are not // defined yet -- which shows up as errors in unrelated headers, like file.h // not knowing what NDIRECT is. // // They must match kernel/core/string.c exactly. Only what lwIP calls is here; // anything else should be added deliberately rather than by growing this into // a libc. #ifndef LWIP_SHIM_STRING_H #define LWIP_SHIM_STRING_H int memcmp(const void *, const void *, unsigned long); void *memmove(void *, const void *, unsigned long); void *memset(void *, int, unsigned long); int strlen(const char *); int strncmp(const char *, const char *, unsigned long); char *strncpy(char *, const char *, int); // The kernel deliberately provides only memmove, on the grounds that a copy // which happens to overlap should not be undefined behaviour. lwIP calls // memcpy in a handful of places, always on buffers it has just allocated, so // mapping it onto memmove is correct and costs nothing. #define memcpy(d, s, n) memmove((d), (s), (n)) #endif