cutils: add strpadcpy()

Backports commit 2a025ae454c361fb03aadf88e8a2f678b80b38e6 from qemu
This commit is contained in:
Paolo Bonzini 2018-02-15 08:21:38 -05:00 committed by Lioncash
parent 7d5ef87f8c
commit 542f162b35
No known key found for this signature in database
GPG key ID: 4E3C3CC1031BA9C7
2 changed files with 7 additions and 0 deletions

View file

@ -98,6 +98,7 @@ int qemu_ftruncate64(int, int64_t);
/* cutils.c */ /* cutils.c */
void pstrcpy(char *buf, int buf_size, const char *str); 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); char *pstrcat(char *buf, int buf_size, const char *s);
int strstart(const char *str, const char *val, const char **ptr); int strstart(const char *str, const char *val, const char **ptr);
int qemu_fls(int i); int qemu_fls(int i);

View file

@ -27,6 +27,12 @@
#include <limits.h> #include <limits.h>
#include <errno.h> #include <errno.h>
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) void pstrcpy(char *buf, int buf_size, const char *str)
{ {