From 542f162b3596dda849d63a6bfce5ff037854c17f Mon Sep 17 00:00:00 2001 From: Paolo Bonzini Date: Thu, 15 Feb 2018 08:21:38 -0500 Subject: [PATCH] cutils: add strpadcpy() Backports commit 2a025ae454c361fb03aadf88e8a2f678b80b38e6 from qemu --- qemu/include/qemu-common.h | 1 + qemu/util/cutils.c | 6 ++++++ 2 files changed, 7 insertions(+) diff --git a/qemu/include/qemu-common.h b/qemu/include/qemu-common.h index e2c3e3b1..29cc754a 100644 --- a/qemu/include/qemu-common.h +++ b/qemu/include/qemu-common.h @@ -98,6 +98,7 @@ int qemu_ftruncate64(int, int64_t); /* cutils.c */ void pstrcpy(char *buf, int buf_size, const char *str); +void strpadcpy(char *buf, int buf_size, const char *str, char pad); char *pstrcat(char *buf, int buf_size, const char *s); int strstart(const char *str, const char *val, const char **ptr); int qemu_fls(int i); diff --git a/qemu/util/cutils.c b/qemu/util/cutils.c index 0272f467..4190862e 100644 --- a/qemu/util/cutils.c +++ b/qemu/util/cutils.c @@ -27,6 +27,12 @@ #include #include +void strpadcpy(char *buf, int buf_size, const char *str, char pad) +{ + int len = qemu_strnlen(str, buf_size); + memcpy(buf, str, len); + memset(buf + len, pad, buf_size - len); +} void pstrcpy(char *buf, int buf_size, const char *str) {