Received: by 2002:a5b:505:0:0:0:0:0 with SMTP id o5csp4531496ybp; Mon, 14 Oct 2019 06:12:46 -0700 (PDT) X-Google-Smtp-Source: APXvYqze64Q2CKzZhSF8YymgH0SUmd/YAcHOPTGWExmecx0kr9JDReFZuvQ1SH6foDNqp2bHqX+Q X-Received: by 2002:a17:906:524b:: with SMTP id y11mr12821216ejm.82.1571058766109; Mon, 14 Oct 2019 06:12:46 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1571058766; cv=none; d=google.com; s=arc-20160816; b=YWV7Ol/hTTXnC/FxVfqlWDc9PdYVZ+zqJr2VXov8RlaIw6vuy+L6aKY/jwlaj471j0 +TSfXKVTJz5+3cYTJ4ngONjr3lCve00vCcGrocd0BXCnWQw2mx2blgmaOkgYPBT2zdM2 H0UnBb6XywO6UV7Cy/k8yNvWzBrUb6CpMlU8IKKvMs4yE8jhhw9Dlnasxmc9bxFHtS4x XeLESQbElh7B8XA4H88X7DuPlPwP6Rv2ertlXUByJWAQ45L1+ixWi6xNBu2qKNE1KIfg yE5GUbzFlSLMkQZ9GKivDP3Jx9mAbHPx2y+cl6gmq47D9/q8KVrVZniY4/5J9VpG6ooR +5rQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:dkim-signature; bh=IkhUxI/cuatLueNhPw35isDgOKo7L+7bC3FLEO0Oaxw=; b=SDuj8MbIGAPleDivjCpP0ooqDYzToB+yw5wvwGnUEweX4R8F0C3aYnz2yMRtO1grgN GyAWyVpYZ7CPzIozQ1Ih6/1Hppny207XN0RmP0Ss3y4VQZqLAq/5+x+JuU5VfKEdT1+9 vZJKbrI2ps0/98CbzPG+Axi8wy7EVlENIDFPmOQdLpPSMbkZi4NtTz7oyV9Syg3luAd7 AZKTYgsKopEg0LeldMlunjAD+QmGgPajCW+m7VByw6qPq9q0CiKHwpLN8afU06QcTv5M VsWVg1CJd44jfEVFv5wXAmPyHo+OXnTD7YVbsHbO5Bwbn8Jgl6AB1Q9HbTAeye7ZjU8O agMA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b="c3UqyF4/"; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id z42si13461287edz.23.2019.10.14.06.12.23; Mon, 14 Oct 2019 06:12:46 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b="c3UqyF4/"; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730800AbfJNNLF (ORCPT + 99 others); Mon, 14 Oct 2019 09:11:05 -0400 Received: from mail-pl1-f196.google.com ([209.85.214.196]:44976 "EHLO mail-pl1-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725989AbfJNNLF (ORCPT ); Mon, 14 Oct 2019 09:11:05 -0400 Received: by mail-pl1-f196.google.com with SMTP id q15so7999666pll.11 for ; Mon, 14 Oct 2019 06:11:05 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=IkhUxI/cuatLueNhPw35isDgOKo7L+7bC3FLEO0Oaxw=; b=c3UqyF4/zasaXCdf3v34YxktIHDSJVJePa4Fll1ChyITLykL6bYrwIifXDgxznwUNd 1KnWFD0GbZH7eIMcu15/fArGWE0Mn3zrfIMX8tYVaNQxL8r5VRS6DsWmnQ4Jbuz9q5cJ HTWu02vEYgHLJEzFzakbuaX//tFWgGGtTfvXqrAqiY14Yu83EShTjmEsfA/xqG2ST8Za IOShyUL7GC8sg6q1F0Y4kknE8fg+K6KMmxujj4sFbFz3TegPE37EggjwZvhT37Ujmo0s bqNiNAp0WD2e5bgtAtBFc5Aqnn6qETe5lueiuM/lrSlF1PDfoiDrVFBI//rjMaUvrDIv 8N/A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=IkhUxI/cuatLueNhPw35isDgOKo7L+7bC3FLEO0Oaxw=; b=OT6/HnVFX3C+W0BZN1/2IRoD0CmFbPXBzUyB8Z7FgF/07jgXdiyrJKHa6FJ1TsFzIc FsitaY793iAcnvRZUUAgEMH0XK4m8449zte98nurfHYROU47sR1nVvR9kSW4VWEYwQ2p lR6NC4z3VDCUCtZ42Lv6O4CYiLlrZQtmfLzsi+WQTxhbROvz6NXtkS+VjzLMz0k5qW8v hy3opjlBYhdvPOxuDKajJoc9uUoYaoYA4EAl0rTIS6LdEaxj2xN5hSNDQiZRsF4R2+7M 33rfSaBxY8BA9dglgk8lFYTDNy9laxDil7ROAaO82DcYfgXGFmUIiOsJZguMjAHoA6LW cIHw== X-Gm-Message-State: APjAAAXr/nqsIlw/k3HwaHS5hlMeaQLEetltjry7ZjSoifrtnWyh27Mc wvntp8EvEF/R+geEF5IaCsMGUGlbe/ZqmnSNoko= X-Received: by 2002:a17:902:9881:: with SMTP id s1mr30804278plp.18.1571058664842; Mon, 14 Oct 2019 06:11:04 -0700 (PDT) MIME-Version: 1.0 References: <20190917065959.5560-1-linux@rasmusvillemoes.dk> <20191011133617.9963-1-linux@rasmusvillemoes.dk> <20191011133617.9963-2-linux@rasmusvillemoes.dk> <20191014130247.rag2g7qz54uiw54z@pathway.suse.cz> In-Reply-To: <20191014130247.rag2g7qz54uiw54z@pathway.suse.cz> From: Andy Shevchenko Date: Mon, 14 Oct 2019 16:10:54 +0300 Message-ID: Subject: Re: [PATCH v4 1/1] printf: add support for printing symbolic error names To: Petr Mladek Cc: Rasmus Villemoes , =?UTF-8?Q?Uwe_Kleine=2DK=C3=B6nig?= , Joe Perches , Andrew Morton , Jonathan Corbet , Linux Kernel Mailing List Content-Type: text/plain; charset="UTF-8" Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Mon, Oct 14, 2019 at 4:02 PM Petr Mladek wrote: > On Fri 2019-10-11 15:36:17, Rasmus Villemoes wrote: > > It has been suggested several times to extend vsnprintf() to be able > > to convert the numeric value of ENOSPC to print "ENOSPC". This > > implements that as a %p extension: With %pe, one can do > > +const char *errname(int err) > > +{ > > + bool pos = err > 0; > > + const char *name = __errname(err > 0 ? err : -err); > > + > > + return name ? name + pos : NULL; > > This made me to check C standard. It seems that "true" really has > to be "1". You may guarantee it by using !!. return name ? name + !!(err > 0) : NULL; But to me it seems like forgotten use of pos in the other case above. Anyway, I would rather do abs(err) in the first place and simple use name + 1 in the second as you suggested with maybe a comment that we skip E letter. > But I think that I am not the only one who is not sure. > I would prefer to make it less tricky and use, for example: > > const char *name = __errname(err > 0 ? err : -err); > if (!name) > return NULL; > > return err > 0 ? name + 1 : name; > > +} -- With Best Regards, Andy Shevchenko