Skip site navigation (1)Skip section navigation (2)
Date:      Fri, 16 Dec 2016 01:44:51 +0000 (UTC)
From:      "Conrad E. Meyer" <cem@FreeBSD.org>
To:        src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org
Subject:   svn commit: r310138 - head/lib/libc/stdio
Message-ID:  <201612160144.uBG1ipjW016736@repo.freebsd.org>

next in thread | raw e-mail | index | archive | help
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*/



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201612160144.uBG1ipjW016736>