From 321337c9e82f016a0cd64f81573c18b5731ffa8d Mon Sep 17 00:00:00 2001 From: Raghuram Subramani Date: Thu, 17 Oct 2024 17:33:46 +0530 Subject: Merge remote-tracking branch 'msm8998/lineage-20' into lineage-20 Change-Id: I126075a330f305c85f8fe1b8c9d408f368be95d1 --- lib/string_helpers.c | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) (limited to 'lib/string_helpers.c') diff --git a/lib/string_helpers.c b/lib/string_helpers.c index 5c88204b6f1f..f46075b3d9e4 100644 --- a/lib/string_helpers.c +++ b/lib/string_helpers.c @@ -534,3 +534,23 @@ int string_escape_mem(const char *src, size_t isz, char *dst, size_t osz, return p - dst; } EXPORT_SYMBOL(string_escape_mem); + +/** + * memcpy_and_pad - Copy one buffer to another with padding + * @dest: Where to copy to + * @dest_len: The destination buffer size + * @src: Where to copy from + * @count: The number of bytes to copy + * @pad: Character to use for padding if space is left in destination. + */ +void memcpy_and_pad(void *dest, size_t dest_len, const void *src, size_t count, + int pad) +{ + if (dest_len > count) { + memcpy(dest, src, count); + memset(dest + count, pad, dest_len - count); + } else { + memcpy(dest, src, dest_len); + } +} +EXPORT_SYMBOL(memcpy_and_pad); -- cgit v1.2.3