From: Vasily Gorbik Date: Thu, 10 Apr 2025 23:45:47 +0000 (+0200) Subject: s390/boot: Add sized_strscpy() to enable strscpy() usage X-Git-Url: https://www.infradead.org/git/?a=commitdiff_plain;h=f271df9d41c216f6189c40fa1cb83839a6117c3e;p=users%2Fdwmw2%2Flinux.git s390/boot: Add sized_strscpy() to enable strscpy() usage Add a simple sized_strscpy() implementation to allow the use of strscpy() in the decompressor. Signed-off-by: Vasily Gorbik Reviewed-by: Heiko Carstens Signed-off-by: Heiko Carstens --- diff --git a/arch/s390/boot/string.c b/arch/s390/boot/string.c index f6b9b1df48a82..bd68161434a60 100644 --- a/arch/s390/boot/string.c +++ b/arch/s390/boot/string.c @@ -29,6 +29,18 @@ int strncmp(const char *cs, const char *ct, size_t count) return 0; } +ssize_t sized_strscpy(char *dst, const char *src, size_t count) +{ + size_t len; + + if (count == 0) + return -E2BIG; + len = strnlen(src, count - 1); + memcpy(dst, src, len); + dst[len] = '\0'; + return src[len] ? -E2BIG : len; +} + void *memset64(uint64_t *s, uint64_t v, size_t count) { uint64_t *xs = s;