From patchwork Sat May 14 20:02:53 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Simon Glass X-Patchwork-Id: 622267 X-Patchwork-Delegate: sjg@chromium.org Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from theia.denx.de (theia.denx.de [85.214.87.163]) by ozlabs.org (Postfix) with ESMTP id 3r6d2s18tfz9t5Y for ; Sun, 15 May 2016 06:03:49 +1000 (AEST) Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=google.com header.i=@google.com header.b=iwzg3/Rm; dkim-atps=neutral Received: from localhost (localhost [127.0.0.1]) by theia.denx.de (Postfix) with ESMTP id CE787A76F6; Sat, 14 May 2016 22:03:46 +0200 (CEST) Received: from theia.denx.de ([127.0.0.1]) by localhost (theia.denx.de [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id SdaiM9uKyHET; Sat, 14 May 2016 22:03:46 +0200 (CEST) Received: from theia.denx.de (localhost [127.0.0.1]) by theia.denx.de (Postfix) with ESMTP id 2FD94A7658; Sat, 14 May 2016 22:03:40 +0200 (CEST) Received: from localhost (localhost [127.0.0.1]) by theia.denx.de (Postfix) with ESMTP id 7981BA7506 for ; Sat, 14 May 2016 22:03:35 +0200 (CEST) Received: from theia.denx.de ([127.0.0.1]) by localhost (theia.denx.de [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id zQUTVAvuZWVZ for ; Sat, 14 May 2016 22:03:35 +0200 (CEST) X-policyd-weight: NOT_IN_SBL_XBL_SPAMHAUS=-1.5 NOT_IN_SPAMCOP=-1.5 NOT_IN_BL_NJABL=-1.5 (only DNSBL check requested) Received: from mail-io0-f179.google.com (mail-io0-f179.google.com [209.85.223.179]) by theia.denx.de (Postfix) with ESMTPS id 119DCA74DB for ; Sat, 14 May 2016 22:03:30 +0200 (CEST) Received: by mail-io0-f179.google.com with SMTP id d62so170101344iof.2 for ; Sat, 14 May 2016 13:03:30 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20120113; h=sender:from:to:cc:subject:date:message-id:in-reply-to:references; bh=ywGSG3RehVyJB/hnivFteMIMH4UXFuRCA/dqOzFhKq8=; b=iwzg3/Rm9c6bOt8NcZiplP/2yYVDR0a36sYsoymblyadfu7JbEPP3nM5E4r2FYuGNF LfyCaB8Vs0jYBfbHuzZMb7+PVXxWuBq244Gsum/Pps+6xj94OGsZxNaJMef8jygEEQwn ZP9AqzzgiB8THmLLvPhIKmBvkqE8S1iFWmevlNXldlko8Yk7rEjHsEJnbiGmEdt041SK aZSno5cBRlT9ir6uHFLWlh1ws6SEdx6oUT/Wc2Zdby0BVpGUrHzfmPBXjnpIvef7uxYf wCE1x5vb0llDml/IuOgw5GSNRahtL6yY8Z9+XqVyaQF9QJgwm11sUJ3PRXyy9D8EwGuK v/iA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:sender:from:to:cc:subject:date:message-id :in-reply-to:references; bh=ywGSG3RehVyJB/hnivFteMIMH4UXFuRCA/dqOzFhKq8=; b=kzRfBy9m3Rq85Rge0hRqmcPTeQ7SDWFFZcDfmfS7jnl+CzerDicKmABWJKNC5ylD8q VvAe6CKzX3hvQ8AYxZrYDsj/O1bU/Ekeab+qiiR65hGQGKJFMQ2ieJXE6nE8ehnsA6Ss LHCDyS7dGghtAr88NPIGFTSYbqCIKw6NE+4t1c45gh8TgDmXRXt4otaeTR3IYrlFTokt Vu3bSiYPxnQ20Derv53VTprFukzIA+6vnaCcchncdKVx1EyyuOwcppNavuYk69VMUj3j RvfAM2PGRsN+1mT5WTKF4A7WhxaXecScYlO5mkVIr7C8Sgb7RpU3/PtgSQ/q8j4wj9Px 77DA== X-Gm-Message-State: AOPr4FXa1VK8OsSDBs2QgfFbb+GSmTvSm2hthy85LKJ0DYBW76QaItq0WA+3Y19oacrcImoS X-Received: by 10.36.120.87 with SMTP id p84mr6011658itc.38.1463256209254; Sat, 14 May 2016 13:03:29 -0700 (PDT) Received: from kaki.bld.corp.google.com ([100.100.202.57]) by smtp.gmail.com with ESMTPSA id n75sm8108774ioe.9.2016.05.14.13.03.27 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sat, 14 May 2016 13:03:28 -0700 (PDT) Received: by kaki.bld.corp.google.com (Postfix, from userid 121222) id 88104220B58; Sat, 14 May 2016 14:03:27 -0600 (MDT) From: Simon Glass To: U-Boot Mailing List Date: Sat, 14 May 2016 14:02:53 -0600 Message-Id: <1463256198-3829-3-git-send-email-sjg@chromium.org> X-Mailer: git-send-email 2.8.0.rc3.226.g39d4020 In-Reply-To: <1463256198-3829-1-git-send-email-sjg@chromium.org> References: <1463256198-3829-1-git-send-email-sjg@chromium.org> Cc: Stefan Roese , Jeffy Chen , huang lin Subject: [U-Boot] [PATCH 02/20] tiny-printf: Support snprintf() X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.15 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Errors-To: u-boot-bounces@lists.denx.de Sender: "U-Boot" Add a simple version of this function for SPL. It does not check the buffer size as this would add to the code size. Signed-off-by: Simon Glass Reviewed-by: Stefan Roese --- lib/tiny-printf.c | 27 +++++++++++++++++++++++++-- 1 file changed, 25 insertions(+), 2 deletions(-) diff --git a/lib/tiny-printf.c b/lib/tiny-printf.c index fbd5368..4b70263 100644 --- a/lib/tiny-printf.c +++ b/lib/tiny-printf.c @@ -16,6 +16,9 @@ static char *bf; static char zs; +/* Current position in sprintf() output string */ +static char *outstr; + static void out(char c) { *bf++ = c; @@ -40,7 +43,7 @@ static void div_out(unsigned int *num, unsigned int div) out_dgt(dgt); } -int vprintf(const char *fmt, va_list va) +int _vprintf(const char *fmt, va_list va, void (*putc)(const char ch)) { char ch; char *p; @@ -133,8 +136,28 @@ int printf(const char *fmt, ...) int ret; va_start(va, fmt); - ret = vprintf(fmt, va); + ret = _vprintf(fmt, va, putc); + va_end(va); + + return ret; +} + +static void putc_outstr(char ch) +{ + *outstr++ = ch; +} + +/* Note that size is ignored */ +int snprintf(char *buf, size_t size, const char *fmt, ...) +{ + va_list va; + int ret; + + va_start(va, fmt); + outstr = buf; + ret = _vprintf(fmt, va, putc_outstr); va_end(va); + *outstr = '\0'; return ret; }