Date: Thu, 24 Jul 2003 01:41:38 +1000 (EST) From: andyf@speednet.com.au To: FreeBSD-gnats-submit@FreeBSD.org Subject: bin/54784: find -ls wastes space Message-ID: <200307231541.h6NFfcai051671@johnny.speednet.com.au> Resent-Message-ID: <200307231550.h6NFoCOS025922@freefall.freebsd.org>
next in thread | raw e-mail | index | archive | help
>Number: 54784 >Category: bin >Synopsis: find -ls wastes space >Confidential: no >Severity: non-critical >Priority: low >Responsible: freebsd-bugs >State: open >Quarter: >Keywords: >Date-Required: >Class: change-request >Submitter-Id: current-users >Arrival-Date: Wed Jul 23 08:50:11 PDT 2003 >Closed-Date: >Last-Modified: >Originator: andyf@speednet.com.au >Release: FreeBSD 4.8-RELEASE i386 >Organization: >Environment: >Description: When using the -ls option of find(1) the username and groupname are formatted into a fixed length field of UT_NAMESIZE (MAXLOGNAME on -current). This patch does what top(1) does and scans for the long- est username, then formats the field to this dynamic value. The patches to operater.c fix compile warnings. >How-To-Repeat: find . -ls >Fix: diff -u ./extern.h ./new/extern.h --- ./extern.h Sun May 6 19:53:22 2001 +++ ./new/extern.h Thu Jul 24 00:58:54 2003 @@ -111,5 +111,5 @@ exec_f f_user; extern int ftsoptions, isdeprecated, isdepth, isoutput, issort, isxargs; -extern int mindepth, maxdepth; +extern int namelength, mindepth, maxdepth; extern int regexp_flags; diff -u ./function.c ./new/function.c --- ./function.c Fri Nov 15 21:38:15 2002 +++ ./new/function.c Thu Jul 24 00:02:45 2003 @@ -49,6 +49,7 @@ #include <sys/wait.h> #include <sys/mount.h> #include <sys/timeb.h> +#include <sys/types.h> #include <dirent.h> #include <err.h> @@ -926,8 +927,17 @@ OPTION *option; char ***argvp; { + struct passwd *pw; + ftsoptions &= ~FTS_NOSTAT; isoutput = 1; + + while ((pw = getpwent()) != NULL) { + if (strlen(pw->pw_name) > namelength) + namelength = strlen(pw->pw_name); + } + if (namelength < 8) + namelength = 8; return palloc(option); } diff -u ./ls.c ./new/ls.c --- ./ls.c Wed Mar 13 05:34:50 2002 +++ ./new/ls.c Thu Jul 24 00:12:57 2003 @@ -52,6 +52,8 @@ #include <unistd.h> #include <utmp.h> +extern int namelength; + /* Derived from the print routines in the ls(1) source code. */ static void printlink __P((char *)); @@ -67,9 +69,9 @@ (void)printf("%6lu %4qd ", (u_long) sb->st_ino, sb->st_blocks); (void)strmode(sb->st_mode, modep); - (void)printf("%s %3u %-*s %-*s ", modep, sb->st_nlink, UT_NAMESIZE, - user_from_uid(sb->st_uid, 0), UT_NAMESIZE, - group_from_gid(sb->st_gid, 0)); + (void)printf("%s %3u %-*s %-*s ", modep, sb->st_nlink, + namelength, user_from_uid(sb->st_uid, 0), + namelength, group_from_gid(sb->st_gid, 0)); if (S_ISCHR(sb->st_mode) || S_ISBLK(sb->st_mode)) (void)printf("%3d, %3d ", major(sb->st_rdev), diff -u ./main.c ./new/main.c --- ./main.c Mon Feb 26 07:56:59 2001 +++ ./new/main.c Thu Jul 24 00:10:57 2003 @@ -74,6 +74,7 @@ int issort; /* do hierarchies in lexicographical order */ int isxargs; /* don't permit xargs delimiting chars */ int mindepth = -1, maxdepth = -1; /* minimum and maximum depth */ +int namelength; /* longest username */ int regexp_flags = REG_BASIC; /* use the "basic" regexp by default*/ static void usage __P((void)); diff -u ./operator.c ./new/operator.c --- ./operator.c Sun May 6 19:53:22 2001 +++ ./new/operator.c Mon Jul 21 22:19:03 2003 @@ -37,7 +37,9 @@ */ #ifndef lint +#if 0 static char sccsid[] = "@(#)operator.c 8.1 (Berkeley) 6/6/93"; +#endif #endif /* not lint */ #include <sys/types.h> @@ -173,7 +175,7 @@ tail = result = NULL; - while (next = yanknode(&plan)) { + while ((next = yanknode(&plan)) != NULL) { /* * if we encounter a ( expression ) then look for nots in * the expr subplan. >Release-Note: >Audit-Trail: >Unformatted:
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?200307231541.h6NFfcai051671>