From patchwork Tue Jan 17 17:47:30 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Simon Glass X-Patchwork-Id: 1727630 X-Patchwork-Delegate: trini@ti.com Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=lists.denx.de (client-ip=2a01:238:438b:c500:173d:9f52:ddab:ee01; helo=phobos.denx.de; envelope-from=u-boot-bounces@lists.denx.de; receiver=) Authentication-Results: legolas.ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=chromium.org header.i=@chromium.org header.a=rsa-sha256 header.s=google header.b=UVUVXATb; dkim-atps=neutral Received: from phobos.denx.de (phobos.denx.de [IPv6:2a01:238:438b:c500:173d:9f52:ddab:ee01]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-384)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4NxGkW0Lf9z23fp for ; Wed, 18 Jan 2023 04:54:59 +1100 (AEDT) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id BB24585665; Tue, 17 Jan 2023 18:50:55 +0100 (CET) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=chromium.org Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=u-boot-bounces@lists.denx.de Authentication-Results: phobos.denx.de; dkim=pass (1024-bit key; unprotected) header.d=chromium.org header.i=@chromium.org header.b="UVUVXATb"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 32A4C855D3; Tue, 17 Jan 2023 18:49:08 +0100 (CET) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on phobos.denx.de X-Spam-Level: X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,SPF_HELO_NONE, SPF_PASS autolearn=ham autolearn_force=no version=3.4.2 Received: from mail-io1-xd34.google.com (mail-io1-xd34.google.com [IPv6:2607:f8b0:4864:20::d34]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits)) (No client certificate requested) by phobos.denx.de (Postfix) with ESMTPS id 4036B85602 for ; Tue, 17 Jan 2023 18:48:59 +0100 (CET) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=chromium.org Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=sjg@chromium.org Received: by mail-io1-xd34.google.com with SMTP id h184so5813402iof.9 for ; Tue, 17 Jan 2023 09:48:59 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=FZ+WgV8ncXsAd6KCWY2Vd06F2h/NRn1zhX3mwNn7g9g=; b=UVUVXATbxzhdNZYeu3X2mSQF5IlQVsk+FV452mR2eMUSw30Bvo0fqIAwmNkhu6fGrk xRC4fX9CWiyVg7hvZB2hGvLNAC2Q8b2EP0a4i34DXllPqF82+gDiCHTBUUoeyAcUp1VI GSUt0hF3Ni0iPAiPL+S+oGdycWUPCRZy2I1+k= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=FZ+WgV8ncXsAd6KCWY2Vd06F2h/NRn1zhX3mwNn7g9g=; b=6hXNqvci/kHwtB/YJFZv9VN1klr0c/R8a02UvZl3Dj/uEiCisGdRU6IBWP1gan7q4g 2w5uSjPEZQv4Slv+HsOAf5COSMBBMh2E7LRD7tgnp19LY430k8mtqNh19006QTlAfJZj lIfu802pfYLt9fS1uBt5T/bkSeSANoaXKAfMwPQrq/TEMGS49NqpouTOCp214LEqFtiN XNVbLDFpU/SHLvjtiI+4UGMzUV/502F5h/JI6l8KZus5l2l4mebuee+jgzQfDmXlshg8 AIUR1tmdoohWhfcRGGdDJCQF6+nSHbBf/CQUqtVHScHkQ5qlYZF6aq5s2VpUDOewa3Xp w++w== X-Gm-Message-State: AFqh2krXGl2dzZdo9t35StPVd4UJBvPjJncj/TXKn0Y78Wca2doW8/P5 08CERYZ+yCUErhuvWH3c6+qPoIT0JxEmZWkh X-Google-Smtp-Source: AMrXdXuW0+hwg8OkJftX589daOcfeKZaneWYKKUNaSHkKmdLPT2vALTTk/6BxAVrOycNOl2W90tXYw== X-Received: by 2002:a6b:8f10:0:b0:704:bc04:adfb with SMTP id r16-20020a6b8f10000000b00704bc04adfbmr5608826iod.3.1673977737597; Tue, 17 Jan 2023 09:48:57 -0800 (PST) Received: from kea.bld.corp.google.com ([2620:15c:183:200:28d1:224:8617:3704]) by smtp.gmail.com with ESMTPSA id c32-20020a023f60000000b0038a01eba60fsm9631668jaf.69.2023.01.17.09.48.56 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 17 Jan 2023 09:48:57 -0800 (PST) From: Simon Glass To: u-boot@lists.denx.de Cc: Simon Glass Subject: [PATCH v3 20/70] lib: Support printing an error string Date: Tue, 17 Jan 2023 10:47:30 -0700 Message-Id: <20230117174820.1281477-21-sjg@chromium.org> X-Mailer: git-send-email 2.39.0.246.g2a6d74b583-goog In-Reply-To: <20230117174820.1281477-1-sjg@chromium.org> References: <20230117174820.1281477-1-sjg@chromium.org> MIME-Version: 1.0 X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.39 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: u-boot-bounces@lists.denx.de Sender: "U-Boot" X-Virus-Scanned: clamav-milter 0.103.6 at phobos.denx.de X-Virus-Status: Clean It is often useful to show an error code to give the user a clue as to what went wrong. When error strings are compiled into U-Boot it is possible to show a message as well. But at present it is not very convenient, since code must check if the error strings are present, then obtain the error string and use it in a printf() string. Add a %dE option which shows an error code along with an error string, if available. This makes it easy to show one or both. Signed-off-by: Simon Glass --- (no changes since v1) lib/vsprintf.c | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/lib/vsprintf.c b/lib/vsprintf.c index 530d8088c7f..8de3882fb6c 100644 --- a/lib/vsprintf.c +++ b/lib/vsprintf.c @@ -145,6 +145,7 @@ static noinline char *put_dec(char *buf, uint64_t num) #define LEFT 16 /* left justified */ #define SMALL 32 /* Must be 32 == 0x20 */ #define SPECIAL 64 /* 0x */ +#define ERRSTR 128 /* %dE showing error string if enabled */ /* * Macro to add a new character to our output string, but only if it will @@ -678,6 +679,8 @@ repeat: break; case 'd': + if (fmt[1] == 'E') + flags |= ERRSTR; case 'i': flags |= SIGN; case 'u': @@ -712,6 +715,15 @@ repeat: } str = number(str, end, num, base, field_width, precision, flags); + if (IS_ENABLED(CONFIG_ERRNO_STR) && (flags & ERRSTR)) { + const char *p; + + ADDCH(str, ':'); + ADDCH(str, ' '); + for (p = errno_str(num); *p; p++) + ADDCH(str, *p); + fmt++; + } } if (size > 0) {