[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <1337751760.13111.47.camel@joe2Laptop>
Date: Tue, 22 May 2012 22:42:40 -0700
From: Joe Perches <joe@...ches.com>
To: Kent Overstreet <koverstreet@...gle.com>
Cc: Tejun Heo <tejun@...gle.com>, linux-bcache@...r.kernel.org,
linux-kernel@...r.kernel.org, dm-devel@...hat.com, agk@...hat.com
Subject: Re: [PATCH] Add human-readable units modifier to vsnprintf()
On Wed, 2012-05-23 at 01:22 -0400, Kent Overstreet wrote:
> On Tue, May 22, 2012 at 10:10:48PM -0700, Joe Perches wrote:
> > On Wed, 2012-05-23 at 00:50 -0400, Kent Overstreet wrote:
> > > diff --git a/lib/vsprintf.c b/lib/vsprintf.c
> > []
> > > @@ -1002,6 +1023,7 @@ int format_decode(const char *fmt, struct printf_spec *spec)
> > > case ' ': spec->flags |= SPACE; break;
> > > case '#': spec->flags |= SPECIAL; break;
> > > case '0': spec->flags |= ZEROPAD; break;
> > > + case 'h': spec->flags |= HUNITS; break;
> > > default: found = false;
> > > }
> > >
> >
> > I think that doesn't work well because
> > gcc __attribute__((format(printf, x, y)))
> > verification fails.
>
> Yeah, I already ran into that. I was looking through the gcc docs to see
> if there was a way to add modifiers (how is it done for the other kernel
> specific format strings?) but I haven't found anything yet
It's done via %p extensions.
gcc doesn't care as long as the %p argument is a pointer.
> > It's also possible
> > to confuse it with printf's own 'h' /
> > integer precision use.
>
> Well, that's annoying. Any suggestions?
I gave you one already.
Use a new lib/vsprintf.c %p pointer extension like
"%pD" or "%pH" and use a pointer to the type as the
argument.
It's how it's done for an ipv4 address.
For instance:
be32 address = cpu_to_be32(0xc0a80101);
printk("%pI4" &address);
emits "192.168.1.1"
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@...r.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/
Powered by blists - more mailing lists