From a3abad203a86fb23d104550acbf5ba685a6ee812 Mon Sep 17 00:00:00 2001 From: Martijn Dekker Date: Fri, 5 Nov 2021 03:01:28 +0000 Subject: [PATCH] libcmd: update unit suffix doc in head(1) & tail(1) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The documentation for the supported unit suffixes for options accepting numeric arguments was woefully outdated in 'head --man' and 'tail --man'. A quick look at the very short head(1) code shows that it does not know or care about unit suffixes at all – it leaves that to libast optget(3) which in turn calls strtoll() which is implemented in strtoi.h where the multiplier suffixes are handled. Note that on GNU head/tail, single-letter suffixes use power-of-2 units, e.g. k == KiB, etc. Libast used to do the same but this is not standards compliant and AT&T changed/fixed this in 2011. From libast/RELEASE: 10-04-11 string/strtoi.h: k (1000) and ki (1024) now differentiated (They didn't mention the same change applies to all handled units.) Note that the tail(1) builtin is currently not compiled in by default. This can be changed in src/cmd/ksh93/data/builtins.c. src/lib/libcmd/head.c, src/lib/libcmd/tail.c: - Update the internal head/tail man pages to reflect what is handled in strtoi.h. Resolves: https://github.com/ksh93/ksh/issues/319 --- src/lib/libcmd/head.c | 19 +++++++++++-------- src/lib/libcmd/tail.c | 17 ++++++++++------- 2 files changed, 21 insertions(+), 15 deletions(-) diff --git a/src/lib/libcmd/head.c b/src/lib/libcmd/head.c index d6c5f744d..415b1b3d9 100644 --- a/src/lib/libcmd/head.c +++ b/src/lib/libcmd/head.c @@ -39,14 +39,17 @@ static const char usage[] = "with the \b-q\b and \b-v\b options.]" "[+?If no \afile\a is given, or if the \afile\a is \b-\b, \bhead\b " "copies from standard input starting at the current location.]" -"[+?The option argument for \b-c\b, and \b-s\b can optionally be " - "followed by one of the following characters to specify a different unit " - "other than a single byte:]" - "{" - "[+b?512 bytes.]" - "[+k?1-kilobyte.]" - "[+m?1-megabyte.]" - "}" +"[+?The option argument for \b-n\b, \b-c\b and \b-s\b may end in one of the following " + "case-insensitive unit suffixes, with an optional trailing \bB\b ignored:]{" + "[+b?512 (block)]" + "[+k?1000 (kilo)]" + "[+Ki?1024 (kibi)]" + "[+M?1000*1000 (mega)]" + "[+Mi?1024*1024 (mebi)]" + "[+G?1000*1000*1000 (giga)]" + "[+Gi?1024*1024*1024 (gibi)]" + "[+...?and so on for T, Ti, P, Pi, E, and Ei.]" + "}" "[+?For backwards compatibility, \b-\b\anumber\a is equivalent to \b-n\b " "\anumber\a.]" "[n:lines?Copy \alines\a lines from each file.]#[lines:=10]" diff --git a/src/lib/libcmd/tail.c b/src/lib/libcmd/tail.c index 2316dd7e2..f69ed7664 100644 --- a/src/lib/libcmd/tail.c +++ b/src/lib/libcmd/tail.c @@ -41,13 +41,16 @@ static const char usage[] = "[+?If no \afile\a is given, or if the \afile\a is \b-\b, \btail\b " "copies from standard input. The start of the file is defined " "as the current offset.]" -"[+?The option argument for \b-c\b can optionally be " - "followed by one of the following characters to specify a different " - "unit other than a single byte:]{" - "[+b?512 bytes.]" - "[+k?1 KiB.]" - "[+m?1 MiB.]" - "[+g?1 GiB.]" +"[+?The option argument for \b-n\b and \b-c\b may end in one of the following " + "case-insensitive unit suffixes, with an optional trailing \bB\b ignored:]{" + "[+b?512 (block)]" + "[+k?1000 (kilo)]" + "[+Ki?1024 (kibi)]" + "[+M?1000*1000 (mega)]" + "[+Mi?1024*1024 (mebi)]" + "[+G?1000*1000*1000 (giga)]" + "[+Gi?1024*1024*1024 (gibi)]" + "[+...?and so on for T, Ti, P, Pi, E, and Ei.]" "}" "[+?For backwards compatibility, \b-\b\anumber\a is equivalent to " "\b-n\b \anumber\a and \b+\b\anumber\a is equivalent to "