From nobody Thu Aug 01 16:16:49 2024 X-Original-To: dev-commits-src-all@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 4WZYxs5m3Kz5T0cG; Thu, 01 Aug 2024 16:16:49 +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 "R11" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4WZYxs52X8z4gDm; Thu, 1 Aug 2024 16:16:49 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1722529009; 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=SbTU3FdbcVFwTx5z78Ds81uGnNHuGWupdZNKZdppCh8=; b=i8lsH5GKN/HM3M1VEGYejHxa8Kke3c4Xnf1Zlla7mJfv7Vmx9FyPjIyB+u2rwlM2HDZK4l +q1mFZ3bM2p9Y0Ly5y+A7doyZMIWu8tT9UtFIfUEoJWiz5k4dmYspdWnYABNHh/J16zzyn qUXGCM20QFumSTkhHH1QrOAEW4a+QsEkxm+RUnzEIyPVvGFiPHX8F7LPqwAeBEgY3DO21+ /DDdudAu6dPowA8FoqxVGqcz/SaElBXafY9v/cux0+dxEGizKLtgrSmBYe+c3pVaF9gzC8 BdcijKjQoGAv0exkZYRpU3fDJbTCvABt8WarU/uhwq4ZdlXMwfZdFY+Eo6J6Fg== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1722529009; a=rsa-sha256; cv=none; b=tY/A36zJPGvU3xzyUtMhjUPnnXviRwQI5f3lB/itELUm3yxIgFgLj1VUuQ8Xw0pDhR5GrT mZ2ijbjcwSjJMqKcKQyIgOj7DYDDQnh9TiXgFWneodCsJSF7gcmRlPuSL/wRzJsh2rBPJ1 V4cgFS/FSnZKqEgH/fEXokBHWMpCQgEi7ZyWnWMTsh0zcV4lFrdqAxnmWVdfzUJ3tt6goO hGT6xZ6RgmNlqHFDkvjrxbeddi9+mRGp1IfwXNwl7dRrmZXXFlQjmCGlrN8cKba8BsBJOI do922ig9RJk8khmhDo/uqEibEJ6m83MBeP1B36cH/IuEozRq3JmoQ+xUaAHWhQ== 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=1722529009; 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=SbTU3FdbcVFwTx5z78Ds81uGnNHuGWupdZNKZdppCh8=; b=YJidV8vwNTAtcq6AQL9a+adK/40M/RXGIIhs+Ix4lWpOXKunMHUwaPK4nKdBDrq6qyPGPt 7yJOw/WSfRF8aQQsPw5Y3qWIltBGUocnL+RkFA3qUAEclnK7BEAyoSt3hIubscmUW2Ufr4 EavFR+5NdBdVFAXIpSYQdQ2wz7gyhtGArB/s0/A5q8kTb3ItSYFtE4cy2ySSirkjOqeOO0 qkS8eCqtWUdf8WOUUffSEWTuwPq2YlRE0qEEXCcFlbY/ZDcII2962TjCaCDf+NIv+SLmef /u/xCt16T3Pfi8BiQWguquK/0RvKhzS8vXBE9siKFbJiIfa9ISwlJFAHe1O5ug== 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 4WZYxs4L2hzs97; Thu, 1 Aug 2024 16:16:49 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.18.1/8.18.1) with ESMTP id 471GGnuj095683; Thu, 1 Aug 2024 16:16:49 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.18.1/8.18.1/Submit) id 471GGnTe095680; Thu, 1 Aug 2024 16:16:49 GMT (envelope-from git) Date: Thu, 1 Aug 2024 16:16:49 GMT Message-Id: <202408011616.471GGnTe095680@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org From: Dag-Erling =?utf-8?Q?Sm=C3=B8rgrav?= Subject: git: e6d9c11666f7 - stable/14 - ls: Make -, apply to -s as well as -l. List-Id: Commit messages for all branches of the src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-all List-Help: List-Post: List-Subscribe: List-Unsubscribe: X-BeenThere: dev-commits-src-all@freebsd.org Sender: owner-dev-commits-src-all@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/stable/14 X-Git-Reftype: branch X-Git-Commit: e6d9c11666f785ec45cb6f7e05fc87012d6bb4d5 Auto-Submitted: auto-generated The branch stable/14 has been updated by des: URL: https://cgit.FreeBSD.org/src/commit/?id=e6d9c11666f785ec45cb6f7e05fc87012d6bb4d5 commit e6d9c11666f785ec45cb6f7e05fc87012d6bb4d5 Author: Dag-Erling Smørgrav AuthorDate: 2024-07-24 20:06:39 +0000 Commit: Dag-Erling Smørgrav CommitDate: 2024-08-01 16:15:57 +0000 ls: Make -, apply to -s as well as -l. While here, remove a bogus comment about a gcc bug. The bug was in ls, which used an incorrect format string, and in libc, which accepted it. MFC after: 1 week Reviewed by: brooks Differential Revision: https://reviews.freebsd.org/D46067 (cherry picked from commit 647d4a8cafd2c9b291cab388191bc7fcfe12a66b) --- bin/ls/ls.1 | 4 +++- bin/ls/ls.c | 3 ++- bin/ls/print.c | 14 ++++++-------- bin/ls/tests/ls_tests.sh | 16 ++++++++++++++++ 4 files changed, 27 insertions(+), 10 deletions(-) diff --git a/bin/ls/ls.1 b/bin/ls/ls.1 index 1b0f24593adc..4d20f02261c9 100644 --- a/bin/ls/ls.1 +++ b/bin/ls/ls.1 @@ -31,7 +31,7 @@ .\" .\" @(#)ls.1 8.7 (Berkeley) 7/29/94 .\" -.Dd February 21, 2024 +.Dd July 22, 2024 .Dt LS 1 .Os .Sh NAME @@ -436,6 +436,8 @@ output is not to a terminal. .It Fl , (Comma) When the .Fl l +or +.Fl s option is set, print file sizes grouped and separated by thousands using the non-monetary separator returned by .Xr localeconv 3 , diff --git a/bin/ls/ls.c b/bin/ls/ls.c index 59ff12547787..1ad346440f02 100644 --- a/bin/ls/ls.c +++ b/bin/ls/ls.c @@ -981,7 +981,8 @@ label_out: d.maxlen = maxlen; if (needstats) { d.btotal = btotal; - d.s_block = snprintf(NULL, 0, "%lu", howmany(maxblock, blocksize)); + d.s_block = snprintf(NULL, 0, f_thousands ? "%'ld" : "%ld", + howmany(maxblock, blocksize)); d.s_flags = maxflags; d.s_label = maxlabelstr; d.s_group = maxgroup; diff --git a/bin/ls/print.c b/bin/ls/print.c index 16c4f48624d0..417586665eb1 100644 --- a/bin/ls/print.c +++ b/bin/ls/print.c @@ -227,7 +227,7 @@ printlong(const DISPLAY *dp) (void)printf("%*ju ", dp->s_inode, (uintmax_t)sp->st_ino); if (f_size) - (void)printf("%*jd ", + (void)printf(f_thousands ? "%'*jd " : "%*jd ", dp->s_block, howmany(sp->st_blocks, blocksize)); strmode(sp->st_mode, buf); aclmode(buf, p); @@ -406,7 +406,7 @@ printaname(const FTSENT *p, u_long inodefield, u_long sizefield) chcnt += printf("%*ju ", (int)inodefield, (uintmax_t)sp->st_ino); if (f_size) - chcnt += printf("%*jd ", + chcnt += printf(f_thousands ? "%'*jd " : "%*jd ", (int)sizefield, howmany(sp->st_blocks, blocksize)); #ifdef COLORLS if (f_color) @@ -759,12 +759,10 @@ printsize(size_t width, off_t bytes) humanize_number(buf, sizeof(buf), (int64_t)bytes, "", HN_AUTOSCALE, HN_B | HN_NOSPACE | HN_DECIMAL); (void)printf("%*s ", (u_int)width, buf); - } else if (f_thousands) { /* with commas */ - /* This format assignment needed to work round gcc bug. */ - const char *format = "%*j'd "; - (void)printf(format, (u_int)width, bytes); - } else - (void)printf("%*jd ", (u_int)width, bytes); + } else { + (void)printf(f_thousands ? "%'*jd " : "%*jd ", + (u_int)width, bytes); + } } /* diff --git a/bin/ls/tests/ls_tests.sh b/bin/ls/tests/ls_tests.sh index c82b4e8c8851..c732b60b21a4 100755 --- a/bin/ls/tests/ls_tests.sh +++ b/bin/ls/tests/ls_tests.sh @@ -800,6 +800,21 @@ s_flag_body() done } +atf_test_case scomma_flag +scomma_flag_head() +{ + atf_set "descr" "Verify that -s, prints out the size with ',' delimiters" +} + +scomma_flag_body() +{ + export LC_ALL=en_US.UTF-8 + atf_check -e ignore dd if=/dev/urandom of=file bs=65536 count=64 + blocks=$(stat -f "%b" file) + cblocks=$(printf "%'d" $blocks) + atf_check -e empty -o match:"$cblocks[[:space:]]+file" ls -s, file +} + atf_test_case t_flag t_flag_head() { @@ -972,6 +987,7 @@ atf_init_test_cases() atf_add_test_case q_flag_and_w_flag atf_add_test_case r_flag atf_add_test_case s_flag + atf_add_test_case scomma_flag atf_add_test_case t_flag atf_add_test_case u_flag atf_add_test_case v_flag