summaryrefslogtreecommitdiff
path: root/lib/string_helpers.c
diff options
context:
space:
mode:
authorRaghuram Subramani <raghus2247@gmail.com>2024-10-13 13:36:36 +0530
committerRaghuram Subramani <raghus2247@gmail.com>2024-10-13 13:36:36 +0530
commit6a21d8496b038d1e71fd6a9bd8a95880135665d9 (patch)
tree8f96e9273400c0eb8794f92aef733bb5fe52b658 /lib/string_helpers.c
parentb73f506bc0ae7119f5f629b222596a27d7b2e99b (diff)
parent17d850f5a5bc1318b67a974b16d32a2dd3bab5cf (diff)
Merge remote-tracking branch 'msm8998/lineage-20'master
Diffstat (limited to 'lib/string_helpers.c')
-rw-r--r--lib/string_helpers.c20
1 files changed, 20 insertions, 0 deletions
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);