shared/libc/string0: Don't include string.h, and provide __memcpy_chk.

Some toolchains will have string.h defining various macros which can lead
to compile errors for string function implementations.  Not including
string.h fixes this.

An implementation of __memcpy_chk is provided for toolchains that enable
_FORTIFY_SOURCE.

Fixes issue #6046.

Signed-off-by: Alexey 'alexxy' Shvetsov <alexxyum@gmail.com>
pull/5899/head
Alexey 'alexxy' Shvetsov 2020-05-15 23:26:08 +03:00 zatwierdzone przez Damien George
rodzic d11ff0499f
commit 5cf71b5596
1 zmienionych plików z 8 dodań i 1 usunięć

Wyświetl plik

@ -25,7 +25,7 @@
*/
#include <stdint.h>
#include <string.h>
#include <stddef.h>
#define likely(x) __builtin_expect((x), 1)
@ -64,6 +64,13 @@ void *memcpy(void *dst, const void *src, size_t n) {
return dst;
}
void *__memcpy_chk(void *dest, const void *src, size_t len, size_t slen) {
if (len > slen) {
return NULL;
}
return memcpy(dest, src, len);
}
void *memmove(void *dest, const void *src, size_t n) {
if (src < dest && (uint8_t*)dest < (const uint8_t*)src + n) {
// need to copy backwards