FAQ Search Today's Posts Mark Forums Read
» Video Reviews

» Linux Archive

Linux-archive is a website aiming to archive linux email lists and to make them easily accessible for linux users/developers.


» Sponsor

» Partners

» Sponsor

Go Back   Linux Archive > Redhat > Device-mapper Development

 
 
LinkBack Thread Tools
 
Old 05-23-2012, 05:10 AM
Joe Perches
 
Default Add human-readable units modifier to vsnprintf()

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. It's also possible
to confuse it with printf's own 'h' /
integer precision use.

$ cat h.c
#include <stdio.h>
#include <stdlib.h>

int main(int argc, char** argv)
{
printf("%h02u
", 1);
return 0;
}

$ gcc h.c
h.c: In function ‘main’:
h.c:6:3: warning: unknown conversion type character ‘0’ in format [-Wformat]


--
dm-devel mailing list
dm-devel@redhat.com
https://www.redhat.com/mailman/listinfo/dm-devel
 
Old 05-23-2012, 05:22 AM
Kent Overstreet
 
Default Add human-readable units modifier to vsnprintf()

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 also possible
> to confuse it with printf's own 'h' /
> integer precision use.

Well, that's annoying. Any suggestions?

>
> $ cat h.c
> #include <stdio.h>
> #include <stdlib.h>
>
> int main(int argc, char** argv)
> {
> printf("%h02u
", 1);
> return 0;
> }
>
> $ gcc h.c
> h.c: In function ‘main’:
> h.c:6:3: warning: unknown conversion type character ‘0’ in format [-Wformat]
>
>

--
dm-devel mailing list
dm-devel@redhat.com
https://www.redhat.com/mailman/listinfo/dm-devel
 

Thread Tools




All times are GMT. The time now is 05:06 AM.

VBulletin, Copyright ©2000 - 2014, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO ©2007, Crawlability, Inc.
Copyright 2007 - 2008, www.linux-archive.org