[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[avr-libc-dev] Implementing the vprintf "%*s" and "%.*s" formats
From: |
Paul \"LeoNerd\" Evans |
Subject: |
[avr-libc-dev] Implementing the vprintf "%*s" and "%.*s" formats |
Date: |
Tue, 17 Oct 2017 21:10:14 +0100 |
I often find it useful to be able to print a character buffer of
dynamically-known size by using some variant on
printf("%.*s", len, buf);
It appears to me that avr-libc doesn't recognise this particular flag.
It is documented that
The variable width or precision field (an asterisk * symbol) is not
realized and will to abort the output.
But it's unclear from this whether the absence is deliberate, or simply
not implemented yet.
Would folk be amenable to a patch to add this feature? I have an
(as-yet untested) attempt at it it. I don't think it would massively
increase code size, and it doesn't consume any more RAM at runtime.
But I thought I'd ask, in case there's some specific reason for its
absence.
-----
=== modified file 'libc/stdio/vfprintf.c'
--- libc/stdio/vfprintf.c 2017-10-17 19:56:22 +0000
+++ libc/stdio/vfprintf.c 2017-10-17 19:57:23 +0000
@@ -344,6 +344,12 @@
flags |= FL_WIDTH;
continue;
}
+ if (c == '*') {
+ if (flags & FL_PREC)
+ prec = va_arg(ap, int);
+ else
+ width = va_arg(ap, int);
+ }
if (c == '.') {
if (flags & FL_PREC)
goto ret;
--
Paul "LeoNerd" Evans
address@hidden | https://metacpan.org/author/PEVANS
http://www.leonerd.org.uk/ | https://www.tindie.com/stores/leonerd/
pgp8rg7m16I3x.pgp
Description: OpenPGP digital signature
- [avr-libc-dev] Implementing the vprintf "%*s" and "%.*s" formats,
Paul \"LeoNerd\" Evans <=