From nobody Mon Aug 28 15:38:23 2023 X-Original-To: dev-commits-src-main@mlmmj.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mlmmj.nyi.freebsd.org (Postfix) with ESMTP id 4RZF7z495dz4rgHp; Mon, 28 Aug 2023 15:38:23 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256 client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "R3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4RZF7z3RQmz4cWj; Mon, 28 Aug 2023 15:38:23 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1693237103; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=i40K6M7gmwHgT0Ds9dv/bHsfNSEEZaA19JbFVg8UBCM=; b=ruJddITkR7+Oo5pYrW2I52P88h6YKaz73ilHu78bkX4SQn7hCpMgmxMJLweTNYKiiC+jFu 7zpnZ/JINQ5EaLjI+kU2Cl9Q93+jabjYxStgD1soIsEDH9nxxb28v7V+Bp6HN65fSNLHaW VqZX+mUS7z1wpW0W/JdYa1h6X2YIFBDbo/2G0SoBJohnnrOFAj6Mmm5XYH1rbjlbW7ofue VmCSD6z2nyDMzQzQ+ExWrLC8lJCil/sLYvlCIuvNZOudsKeHYYZKjEmIZeYt/v5rsI4HtD I6CVhHFVZCJZBJmq9+hP2JjdkEOPOT4ggMYEpNq2Ku/8xzE8MVU2hSb+f5cAYg== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1693237103; a=rsa-sha256; cv=none; b=B7fWjvk0T0JiPQEluAPbmUXObw8C1YSSIrX8GqVUevMRQHMSxfQ823NceO8NMHzEfATRIM 4EaTfbsmf75KhQWlFW8j8dRFwFF69CytQgZeDBqlD8ilXCc7jBhVWWoViwqeW/dkH0qPAK WV9LnVztxE23kWozKihvquIIDzuBzZiTaB4YkAt8FV1c+Vq2upVF2QdpRrXNmw0TgGZapw m8Drja/UbREv/2GH4YKJpe83FhG96nNbpdcZ+SYrGiOu8gHbTUkdvmWJ4NapAG89FSYXao AwSm7Kn7JLhNHYZUq71RYMZrGcDzcEv+P1VQuOJJc45agsGYaEXIeWKeRbV0ww== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1693237103; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=i40K6M7gmwHgT0Ds9dv/bHsfNSEEZaA19JbFVg8UBCM=; b=lGM/BJG5OuJnXeKWB9Wxt8CHuLSVzayKv2sCkdZV+Xg7ppBLZd/5EOTicKKiAYBG4Oh35X 42xFQoS72r/t/LUdca+iK1/WV1PQrSSYJHF5fjIqXbuxlwGWwZI6zr30CB+vjJl8NK/Qdy FV8H3IgQ7f61sSx01u9cRrj74hjCIS0+BhZPaPVDW9GtdSJw+F5ApKbTt4h9WiPHTETuEe fRMZXrf3fvtVekCAUy0meShGvnDzilFn9hXuNdqN6mUmw+ehm/bG7IUBHRB6934xTeCOx5 6wHPO5Pbhg+TZsu6hnql1j8e/jrngKLUvQGhGHbXn4OBKYoYYFJAmzjBOoknTQ== Received: from gitrepo.freebsd.org (gitrepo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:5]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id 4RZF7z2CJ9zNq; Mon, 28 Aug 2023 15:38:23 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.17.1/8.17.1) with ESMTP id 37SFcNV9077948; Mon, 28 Aug 2023 15:38:23 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.17.1/8.17.1/Submit) id 37SFcNNm077945; Mon, 28 Aug 2023 15:38:23 GMT (envelope-from git) Date: Mon, 28 Aug 2023 15:38:23 GMT Message-Id: <202308281538.37SFcNNm077945@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: Dag-Erling =?utf-8?Q?Sm=C3=B8rgrav?= Subject: git: 76edfabbecde - main - libc: Document support for binary integers. List-Id: Commit messages for the main branch of the src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-main List-Help: List-Post: List-Subscribe: List-Unsubscribe: Sender: owner-dev-commits-src-main@freebsd.org X-BeenThere: dev-commits-src-main@freebsd.org MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: des X-Git-Repository: src X-Git-Refname: refs/heads/main X-Git-Reftype: branch X-Git-Commit: 76edfabbecdec686a570b8e009d5ea4112f943e0 Auto-Submitted: auto-generated The branch main has been updated by des: URL: https://cgit.FreeBSD.org/src/commit/?id=76edfabbecdec686a570b8e009d5ea4112f943e0 commit 76edfabbecdec686a570b8e009d5ea4112f943e0 Author: Dag-Erling Smørgrav AuthorDate: 2023-08-28 15:34:17 +0000 Commit: Dag-Erling Smørgrav CommitDate: 2023-08-28 15:34:17 +0000 libc: Document support for binary integers. Reviewed by: debdrup, emaste Differential Revision: https://reviews.freebsd.org/D41522 --- lib/libc/stdio/printf.3 | 34 +++++++++++++++++++++++++--------- lib/libc/stdio/scanf.3 | 29 +++++++++++++++++++---------- lib/libc/stdlib/strtol.3 | 4 +++- lib/libc/stdlib/strtoul.3 | 4 +++- 4 files changed, 50 insertions(+), 21 deletions(-) diff --git a/lib/libc/stdio/printf.3 b/lib/libc/stdio/printf.3 index 3e5c6ca23511..110851e2a421 100644 --- a/lib/libc/stdio/printf.3 +++ b/lib/libc/stdio/printf.3 @@ -31,7 +31,7 @@ .\" .\" @(#)printf.3 8.1 (Berkeley) 6/4/93 .\" -.Dd May 22, 2018 +.Dd August 21, 2023 .Dt PRINTF 3 .Os .Sh NAME @@ -212,6 +212,17 @@ and .Cm u conversions, this option has no effect. For +.Cm b +and +.Cm B +conversions, a non-zero result has the string +.Ql 0b +(or +.Ql 0B +for +.Cm B +conversions) prepended to it. +For .Cm o conversions, the precision of the number is increased to force the first character of the output string to a zero. @@ -245,7 +256,7 @@ For all conversions except .Cm n , the converted value is padded on the left with zeros rather than blanks. If a precision is given with a numeric conversion -.Cm ( d , i , o , u , i , x , +.Cm ( b , B , d , i , o , u , i , x , and .Cm X ) , the @@ -301,7 +312,7 @@ followed by an optional digit string. If the digit string is omitted, the precision is taken as zero. This gives the minimum number of digits to appear for -.Cm d , i , o , u , x , +.Cm b , B , d , i , o , u , x , and .Cm X conversions, the number of digits to appear after the decimal-point for @@ -319,12 +330,12 @@ conversions. .It An optional length modifier, that specifies the size of the argument. The following length modifiers are valid for the -.Cm d , i , n , o , u , x , +.Cm b , B , d , i , n , o , u , x , or .Cm X conversion: .Bl -column ".Cm q Em (deprecated)" ".Vt signed char" ".Vt unsigned long long" ".Vt long long *" -.It Sy Modifier Ta Cm d , i Ta Cm o , u , x , X Ta Cm n +.It Sy Modifier Ta Cm d , i Ta Cm b , B , o , u , x , X Ta Cm n .It Cm hh Ta Vt "signed char" Ta Vt "unsigned char" Ta Vt "signed char *" .It Cm h Ta Vt short Ta Vt "unsigned short" Ta Vt "short *" .It Cm l No (ell) Ta Vt long Ta Vt "unsigned long" Ta Vt "long *" @@ -339,7 +350,7 @@ Note: the .Cm t modifier, when applied to a -.Cm o , u , x , +.Cm b , B , o , u , x , or .Cm X conversion, indicates that the argument is of an unsigned type @@ -403,11 +414,16 @@ If a single format directive mixes positional and non-positional arguments, the results are undefined. .Pp The conversion specifiers and their meanings are: -.Bl -tag -width ".Cm diouxX" -.It Cm diouxX +.Bl -tag -width ".Cm bBdiouxX" +.It Cm bBdiouxX The .Vt int -(or appropriate variant) argument is converted to signed decimal +(or appropriate variant) argument is converted to +unsigned binary +.Cm ( b +and +.Cm B ) , +signed decimal .Cm ( d and .Cm i ) , diff --git a/lib/libc/stdio/scanf.3 b/lib/libc/stdio/scanf.3 index b1c50e10a795..6cefdb133983 100644 --- a/lib/libc/stdio/scanf.3 +++ b/lib/libc/stdio/scanf.3 @@ -31,7 +31,7 @@ .\" .\" @(#)scanf.3 8.2 (Berkeley) 12/11/93 .\" -.Dd April 2, 2022 +.Dd August 21, 2023 .Dt SCANF 3 .Os .Sh NAME @@ -141,7 +141,7 @@ The conversion that follows occurs as usual, but no pointer is used; the result of the conversion is simply discarded. .It Cm hh Indicates that the conversion will be one of -.Cm dioux +.Cm bdioux or .Cm n and the next pointer is a pointer to a @@ -150,7 +150,7 @@ and the next pointer is a pointer to a .Vt int ) . .It Cm h Indicates that the conversion will be one of -.Cm dioux +.Cm bdioux or .Cm n and the next pointer is a pointer to a @@ -159,7 +159,7 @@ and the next pointer is a pointer to a .Vt int ) . .It Cm l No (ell) Indicates that the conversion will be one of -.Cm dioux +.Cm bdioux or .Cm n and the next pointer is a pointer to a @@ -185,7 +185,7 @@ and the next pointer is a pointer to an array of .Vt char ) . .It Cm ll No (ell ell) Indicates that the conversion will be one of -.Cm dioux +.Cm bdioux or .Cm n and the next pointer is a pointer to a @@ -201,7 +201,7 @@ and the next pointer is a pointer to .Vt "long double" . .It Cm j Indicates that the conversion will be one of -.Cm dioux +.Cm bdioux or .Cm n and the next pointer is a pointer to a @@ -210,7 +210,7 @@ and the next pointer is a pointer to a .Vt int ) . .It Cm t Indicates that the conversion will be one of -.Cm dioux +.Cm bdioux or .Cm n and the next pointer is a pointer to a @@ -219,7 +219,7 @@ and the next pointer is a pointer to a .Vt int ) . .It Cm z Indicates that the conversion will be one of -.Cm dioux +.Cm bdioux or .Cm n and the next pointer is a pointer to a @@ -229,7 +229,7 @@ and the next pointer is a pointer to a .It Cm q (deprecated.) Indicates that the conversion will be one of -.Cm dioux +.Cm bdioux or .Cm n and the next pointer is a pointer to a @@ -273,6 +273,10 @@ matches a single input .Ql % character. No conversion is done, and assignment does not occur. +.It Cm b , B +Matches an optionally signed binary integer; +the next pointer must be a pointer to +.Vt "unsigned int" . .It Cm d Matches an optionally signed decimal integer; the next pointer must be a pointer to @@ -281,7 +285,12 @@ the next pointer must be a pointer to Matches an optionally signed integer; the next pointer must be a pointer to .Vt int . -The integer is read in base 16 if it begins +The integer is read +in base 2 if it begins with +.Ql 0b +or +.Ql 0B , +in base 16 if it begins with .Ql 0x or diff --git a/lib/libc/stdlib/strtol.3 b/lib/libc/stdlib/strtol.3 index 9656ba546915..e2c5ff7ae3cb 100644 --- a/lib/libc/stdlib/strtol.3 +++ b/lib/libc/stdlib/strtol.3 @@ -31,7 +31,7 @@ .\" .\" @(#)strtol.3 8.1 (Berkeley) 6/4/93 .\" -.Dd November 28, 2001 +.Dd August 21, 2023 .Dt STRTOL 3 .Os .Sh NAME @@ -108,6 +108,8 @@ If .Fa base is zero or 16, the string may then include a +.Dq Li 0b +prefix, and the number will be read in base 2; or it may include a .Dq Li 0x prefix, and the number will be read in base 16; otherwise, a zero diff --git a/lib/libc/stdlib/strtoul.3 b/lib/libc/stdlib/strtoul.3 index e05d7a7728cd..41b3b2c578bc 100644 --- a/lib/libc/stdlib/strtoul.3 +++ b/lib/libc/stdlib/strtoul.3 @@ -31,7 +31,7 @@ .\" .\" @(#)strtoul.3 8.1 (Berkeley) 6/4/93 .\" -.Dd November 28, 2001 +.Dd August 21, 2023 .Dt STRTOUL 3 .Os .Sh NAME @@ -108,6 +108,8 @@ If .Fa base is zero or 16, the string may then include a +.Dq Li 0b +prefix, and the number will be read in base 2; or it may include a .Dq Li 0x prefix, and the number will be read in base 16; otherwise, a zero