Author: cem
Date: Fri Dec 16 01:44:50 2016
New Revision: 310138
URL: https://svnweb.freebsd.org/changeset/base/310138

Log:
  vfprintf(3): Add support for kernel %b format
  
  This is a direct port of the kernel %b format.
  
  I'm unclear on if (more) non-portable printf extensions will be a
  problem. I think it's desirable to have userspace formats include all
  kernel formats, but there may be competing goals I'm not aware of.
  
  Reviewed by:  no one, unfortunately
  Sponsored by: Dell EMC Isilon
  Differential Revision:        https://reviews.freebsd.org/D8426

Modified:
  head/lib/libc/stdio/vfprintf.c

Modified: head/lib/libc/stdio/vfprintf.c
==============================================================================
--- head/lib/libc/stdio/vfprintf.c      Fri Dec 16 01:42:51 2016        
(r310137)
+++ head/lib/libc/stdio/vfprintf.c      Fri Dec 16 01:44:50 2016        
(r310138)
@@ -611,6 +611,37 @@ reswitch:  switch (ch) {
                case 'z':
                        flags |= SIZET;
                        goto rflag;
+               case 'b':
+                       {
+                       const char *q;
+                       int anybitset, bit;
+
+                       ulval = (u_int)GETARG(int);
+                       cp = GETARG(char *);
+
+                       q = __ultoa(ulval, buf + BUF, *cp++, 0, xdigs_lower);
+                       PRINT(q, buf + BUF - q);
+
+                       if (ulval == 0)
+                               break;
+
+                       for (anybitset = 0; *cp;) {
+                               bit = *cp++;
+                               if (ulval & (1 << (bit - 1))) {
+                                       PRINT(anybitset ? "," : "<", 1);
+                                       q = cp;
+                                       for (; (bit = *cp) > ' '; ++cp)
+                                               continue;
+                                       PRINT(q, cp - q);
+                                       anybitset = 1;
+                               } else
+                                       for (; *cp > ' '; ++cp)
+                                               continue;
+                       }
+                       if (anybitset)
+                               PRINT(">", 1);
+                       }
+                       continue;
                case 'C':
                        flags |= LONGINT;
                        /*FALLTHROUGH*/
_______________________________________________
svn-src-all@freebsd.org mailing list
https://lists.freebsd.org/mailman/listinfo/svn-src-all
To unsubscribe, send any mail to "svn-src-all-unsubscr...@freebsd.org"

Reply via email to