From owner-svn-src-all@freebsd.org Fri Dec 16 01:44:52 2016 Return-Path: Delivered-To: svn-src-all@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id 310F0C82937; Fri, 16 Dec 2016 01:44:52 +0000 (UTC) (envelope-from cem@FreeBSD.org) Received: from repo.freebsd.org (repo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:0]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by mx1.freebsd.org (Postfix) with ESMTPS id 00C201300; Fri, 16 Dec 2016 01:44:51 +0000 (UTC) (envelope-from cem@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.37]) by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id uBG1ipGA016737; Fri, 16 Dec 2016 01:44:51 GMT (envelope-from cem@FreeBSD.org) Received: (from cem@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id uBG1ipjW016736; Fri, 16 Dec 2016 01:44:51 GMT (envelope-from cem@FreeBSD.org) Message-Id: <201612160144.uBG1ipjW016736@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: cem set sender to cem@FreeBSD.org using -f From: "Conrad E. Meyer" Date: Fri, 16 Dec 2016 01:44:51 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r310138 - head/lib/libc/stdio X-SVN-Group: head MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-all@freebsd.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: "SVN commit messages for the entire src tree \(except for " user" and " projects" \)" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 16 Dec 2016 01:44:52 -0000 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*/