From mboxrd@z Thu Jan 1 00:00:00 1970 From: Andrew Cooper Subject: [Patch v3 1/7] common/vsprintf: Refactor string() out of vsnprintf() Date: Tue, 5 Nov 2013 14:38:38 +0000 Message-ID: <1383662324-3397-2-git-send-email-andrew.cooper3@citrix.com> References: <1383662324-3397-1-git-send-email-andrew.cooper3@citrix.com> Mime-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Return-path: In-Reply-To: <1383662324-3397-1-git-send-email-andrew.cooper3@citrix.com> List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Sender: xen-devel-bounces@lists.xen.org Errors-To: xen-devel-bounces@lists.xen.org To: Xen-devel Cc: Andrew Cooper , Keir Fraser , Jan Beulich List-Id: xen-devel@lists.xenproject.org No functional change Signed-off-by: Andrew Cooper CC: Keir Fraser CC: Jan Beulich --- xen/common/vsprintf.c | 49 ++++++++++++++++++++++++++++--------------------- 1 file changed, 28 insertions(+), 21 deletions(-) diff --git a/xen/common/vsprintf.c b/xen/common/vsprintf.c index 95bf85d..1bcbd79 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) +{ + 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': -- 1.7.10.4