From owner-freebsd-bugs@FreeBSD.ORG Wed Jul 16 15:10:01 2008 Return-Path: Delivered-To: freebsd-bugs@hub.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 9F488106567D for ; Wed, 16 Jul 2008 15:10:01 +0000 (UTC) (envelope-from gnats@FreeBSD.org) Received: from freefall.freebsd.org (freefall.freebsd.org [IPv6:2001:4f8:fff6::28]) by mx1.freebsd.org (Postfix) with ESMTP id 7D7CB8FC1F for ; Wed, 16 Jul 2008 15:10:01 +0000 (UTC) (envelope-from gnats@FreeBSD.org) Received: from freefall.freebsd.org (gnats@localhost [127.0.0.1]) by freefall.freebsd.org (8.14.2/8.14.2) with ESMTP id m6GFA1et053420 for ; Wed, 16 Jul 2008 15:10:01 GMT (envelope-from gnats@freefall.freebsd.org) Received: (from gnats@localhost) by freefall.freebsd.org (8.14.2/8.14.1/Submit) id m6GFA1gY053419; Wed, 16 Jul 2008 15:10:01 GMT (envelope-from gnats) Resent-Date: Wed, 16 Jul 2008 15:10:01 GMT Resent-Message-Id: <200807161510.m6GFA1gY053419@freefall.freebsd.org> Resent-From: FreeBSD-gnats-submit@FreeBSD.org (GNATS Filer) Resent-To: freebsd-bugs@FreeBSD.org Resent-Reply-To: FreeBSD-gnats-submit@FreeBSD.org, Jaakko Heinonen Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id C17981065675 for ; Wed, 16 Jul 2008 15:08:12 +0000 (UTC) (envelope-from jaakko@saunalahti.fi) Received: from gw02.mail.saunalahti.fi (gw02.mail.saunalahti.fi [195.197.172.116]) by mx1.freebsd.org (Postfix) with ESMTP id 57EC78FC32 for ; Wed, 16 Jul 2008 15:08:12 +0000 (UTC) (envelope-from jaakko@saunalahti.fi) Received: from ws64.jh.dy.fi (a91-153-120-204.elisa-laajakaista.fi [91.153.120.204]) by gw02.mail.saunalahti.fi (Postfix) with ESMTP id 58C3D1396E0 for ; Wed, 16 Jul 2008 18:08:10 +0300 (EEST) Received: from ws64.jh.dy.fi (localhost [127.0.0.1]) by ws64.jh.dy.fi (8.14.2/8.14.2) with ESMTP id m6GF8AxA004184 for ; Wed, 16 Jul 2008 18:08:10 +0300 (EEST) (envelope-from jaakko@ws64.jh.dy.fi) Received: (from jaakko@localhost) by ws64.jh.dy.fi (8.14.2/8.14.2/Submit) id m6GF89PP004183; Wed, 16 Jul 2008 18:08:09 +0300 (EEST) (envelope-from jaakko) Message-Id: <200807161508.m6GF89PP004183@ws64.jh.dy.fi> Date: Wed, 16 Jul 2008 18:08:09 +0300 (EEST) From: Jaakko Heinonen To: FreeBSD-gnats-submit@FreeBSD.org X-Send-Pr-Version: 3.113 Cc: Subject: bin/125678: [patch] ls(1) -h option doesn't work if the listing contains a device file X-BeenThere: freebsd-bugs@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: Bug reports List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 16 Jul 2008 15:10:01 -0000 >Number: 125678 >Category: bin >Synopsis: [patch] ls(1) -h option doesn't work if the listing contains a device file >Confidential: no >Severity: non-critical >Priority: low >Responsible: freebsd-bugs >State: open >Quarter: >Keywords: >Date-Required: >Class: sw-bug >Submitter-Id: current-users >Arrival-Date: Wed Jul 16 15:10:01 UTC 2008 >Closed-Date: >Last-Modified: >Originator: Jaakko Heinonen >Release: FreeBSD 7.0-STABLE / 8.0-CURRENT >Organization: >Environment: >Description: If a ls(1) long formatted listing has at least one character or block device file the -h switch has no effect. >How-To-Repeat: $ ls -lh 10MBnull -rw-r--r-- 1 jaakko jaakko 10M Jul 16 13:29 10MBnull $ ls -lh /dev/null 10MBnull crw-rw-rw- 1 root wheel 0, 26 Jul 16 13:22 /dev/null -rw-r--r-- 1 jaakko jaakko 10485760 Jul 16 13:29 10MBnull After applying the patch: $ ls -lh 10MBnull -rw-r--r-- 1 jaakko jaakko 10M Jul 16 13:29 10MBnull $ ls -lh /dev/null 10MBnull crw-rw-rw- 1 root wheel 0, 26 Jul 16 13:33 /dev/null -rw-r--r-- 1 jaakko jaakko 10M Jul 16 13:29 10MBnull >Fix: --- ls--h-with-device-files.diff begins here --- Index: bin/ls/print.c =================================================================== --- bin/ls/print.c (revision 180487) +++ bin/ls/print.c (working copy) @@ -65,7 +65,7 @@ static int printaname(const FTSENT *, u_ static void printlink(const FTSENT *); static void printtime(time_t); static int printtype(u_int); -static void printsize(size_t, off_t); +static void printsize(size_t, off_t, int); #ifdef COLORLS static void endcolor(int); static int colortype(mode_t); @@ -183,11 +183,8 @@ printlong(const DISPLAY *dp) else (void)printf("%3d, %3d ", major(sp->st_rdev), minor(sp->st_rdev)); - else if (dp->bcfile) - (void)printf("%*s%*jd ", - 8 - dp->s_size, "", dp->s_size, sp->st_size); else - printsize(dp->s_size, sp->st_size); + printsize(dp->s_size, sp->st_size, dp->bcfile); if (f_accesstime) printtime(sp->st_atime); else if (f_birthtime) @@ -599,7 +596,7 @@ printlink(const FTSENT *p) } static void -printsize(size_t width, off_t bytes) +printsize(size_t width, off_t bytes, int bcfile) { if (f_humanval) { @@ -607,8 +604,11 @@ 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("%5s ", buf); - } else + (void)printf("%*s ", bcfile ? 8 : 5, buf); + } else if (bcfile) + (void)printf("%*s%*jd ", + 8 - (u_int)width, "", (u_int)width, bytes); + else (void)printf("%*jd ", (u_int)width, bytes); } --- ls--h-with-device-files.diff ends here --- >Release-Note: >Audit-Trail: >Unformatted: