From: Andrew Cooper Date: Tue, 12 Nov 2013 10:06:09 +0000 (+0100) Subject: common/vsprintf: Refactor string() out of vsnprintf() X-Git-Tag: archive/raspbian/4.8.0-1+rpi1~1^2~6002 X-Git-Url: https://dgit.raspbian.org/?a=commitdiff_plain;h=67a3542c5bc356e6452d8305991617c875f87de4;p=xen.git common/vsprintf: Refactor string() out of vsnprintf() No functional change. Signed-off-by: Andrew Cooper Reviewed-by: Jan Beulich Acked-by: Keir Fraser --- diff --git a/xen/common/vsprintf.c b/xen/common/vsprintf.c index 95bf85dfaf..4211ebee0d 100644 --- a/xen/common/vsprintf.c +++ b/xen/common/vsprintf.c @@ -235,6 +235,32 @@ static char *number( return buf; } +static char *string(char *str, char *end, const char *s, + int field_width, int precision, int flags) +{ + unsigned int i, len = strnlen(s, precision); + + if (!(flags & LEFT)) { + while (len < field_width--) { + if (str <= end) + *str = ' '; + ++str; + } + } + for (i = 0; i < len; ++i) { + if (str <= end) + *str = *s; + ++str; ++s; + } + while (len < field_width--) { + if (str <= end) + *str = ' '; + ++str; + } + + return str; +} + /** * vsnprintf - Format a string and place it in a buffer * @buf: The buffer to place the result into @@ -255,9 +281,8 @@ static char *number( */ int vsnprintf(char *buf, size_t size, const char *fmt, va_list args) { - int len; unsigned long long num; - int i, base; + int base; char *str, *end, c; const char *s; @@ -370,25 +395,7 @@ int vsnprintf(char *buf, size_t size, const char *fmt, va_list args) if ((unsigned long)s < PAGE_SIZE) s = ""; - len = strnlen(s, precision); - - if (!(flags & LEFT)) { - while (len < field_width--) { - if (str <= end) - *str = ' '; - ++str; - } - } - for (i = 0; i < len; ++i) { - if (str <= end) - *str = *s; - ++str; ++s; - } - while (len < field_width--) { - if (str <= end) - *str = ' '; - ++str; - } + str = string(str, end, s, field_width, precision, flags); continue; case 'p':