1
0
mirror of https://github.com/openbsd/src.git synced 2025-01-04 23:35:36 -08:00
Commit Graph

56 Commits

Author SHA1 Message Date
schwarze
772e31c152 Simplify the display() function by getting rid of a useless buffer
on the stack.  No functional change, +8 -15 LOC.

Suggested by and OK millert@.
2023-10-07 13:29:08 +00:00
schwarze
09b34e9cf9 Improve horizontal alignment in long format when printing minor
device numbers greater than 999 by measuring the two widths needed
for device numbers just like it is already done for other numbers.
In the output, this only changes whitespace, but not the text.

Ugly formatting reported by
Crystal Kolipe <kolipe dot c at exoticsilicon dot com>.

OK millert.  Also tested by Crystal Kolipe.
2023-10-07 11:51:08 +00:00
millert
bc2593c5af If we are asked to print the total number of blocks, do so even if
we have no entries to print (either due to an empty directory or
an error).  This makes the -l and -s options more consistent, and
matches the behavior of AT&T and GNU ls.  From FreeBSD (das).
OK kn@
2020-10-07 21:03:09 +00:00
millert
b3b446690c Always print the directory name in -R mode; matches historical behavior.
Previously, our ls would only print the directory name when listing
more than one directory, which is the correct behavior for non-recursive
ls but not for -R mode.  OK deraadt@
2020-07-06 00:55:05 +00:00
millert
b352e5558a Fix skipping of directories that begin with a '.' in -R mode.
It is not enough to avoid displaying the contents of the directory,
we need to set FTS_SKIP to avoid descending into any subdirs too.
Otherwise, if a ".foo" directory has a subdirectory "bar", ls will
descend into bar and display its contents.  OK deraadt@
2020-07-06 00:51:51 +00:00
millert
cdc5a29bb5 Fix warnings caused by user_from_uid() and group_from_gid() now
returning const char *.
2018-09-13 15:23:32 +00:00
deraadt
c4db6faa7f use sizeof, rather than the constant. on change in binary. 2018-02-04 22:09:33 +00:00
deraadt
55333ed9ed repair ugly indents 2018-02-04 21:53:54 +00:00
krw
9b082f83dc Nuke some erroneous leading whitespace. 2016-08-16 16:13:32 +00:00
krw
4442fdb76b Bring types of variables used with struct stat into the modern world.
Replace a couple of u_long paramaters with int as they were only passed int
values and the function re-cast them to (int) anyway. Weird.

ok tedu@
2016-08-16 16:09:24 +00:00
chl
cf28062479 remove unused variable
ok schwarze@
2016-03-28 11:25:35 +00:00
bentley
7220d8ecee Switch (non-curses, non-ksh) programs that use COLUMNS to a single idiom.
Previously behaviors were all over the map. This changes them to
use COLUMNS first, and either terminal width or a hardcoded value
(typically 80) as appropriate.

ok deraadt@; man bits ok jmc@
2016-03-17 05:27:10 +00:00
schwarze
b6203726b0 Support UTF-8: use wcwidth(3) for column adjustment and replace
non-printable Unicode codepoints and invalid bytes with ASCII
question marks.  No change for the SMALL version.

Using ideas developed by tedu@, phessler@, bentley@ and feedback from many.
OK yasuoka@ czarkoff@ sthen@.
2015-12-01 18:36:13 +00:00
deraadt
0bd1216cbf Change all tame callers to namechange to pledge(2). 2015-10-09 01:37:06 +00:00
deraadt
9978c3c0a0 ls can use tame "stdio rpath getpw". It does uid/gid lookups, using
the 4.4bsd libc caching varients called user_from_uid/group_from_uid,
which are backed by getpw*/getgr* type functions.
ok semarie
2015-10-04 16:00:43 +00:00
uebayasi
f12e5d267f Put fts_close() where missing.
Not bugs in short-lived commands that call exit() -> _exit() immediately,
but for idempotency.

Originally found in ls(1) by Valgrind.  Changes for other commands are
from deraadt@.  Reviewed by me, tested in snapshots.

OK deraadt@
2015-06-25 02:04:07 +00:00
deraadt
a47b6461a1 Convert many atoi() calls to strtonum(), adding range checks and failure
handling along the way.
Reviews by Brendan MacDonell, Jeremy Devenport, florian, doug, millert
2015-04-18 18:28:36 +00:00
sobrado
cad8a15cb1 restore the traditional behavior of -f implying -a; apparently Keith Bostic
forgot to restore it when the -f flag was put back on 2nd of September 1989,
after being removed on 16th of August as a consequence of issues getting it
working over NFS, so deviation from traditional UNIX behavior in all BSDs
looks like an historical accident; as a side effect, this change accommodates
behavior of this option to IEEE Std 1003.1-2008 (``POSIX.1'').

joint work with jmc@ (who found the inaccuracy in our implementation),
schwarze@ (who provided a detailed tracking of historical facts) and millert@

ok millert@, schwarze@
2014-03-31 20:54:37 +00:00
guenther
3e12fe88c8 Fix column padding of inode numbers and block counts >2^32, as well as
display of directory block totals >2^32

ok tedu@
2013-05-30 16:34:32 +00:00
okan
9079317df9 add support for the (POSIX) -H flag
feedback and ok millert@, sobrado@, jmc@
2011-03-04 21:03:19 +00:00
sobrado
8e74991cd6 remove trailing spaces and tabs from source code; no binary change. 2010-09-12 20:16:29 +00:00
deraadt
043fbe51c1 rcsid[] and sccsid[] and copyright[] are essentially unmaintained (and
unmaintainable).  these days, people use source.  these id's do not provide
any benefit, and do hurt the small install media
(the 33,000 line diff is essentially mechanical)
ok with the idea millert, ok dms
2009-10-27 23:59:19 +00:00
todd
92806c0e4f do not ignore COLUMNS in -C mode, even if !isatty(STDOUT_FILENO)
from FreeBSD
ok millert@, posix checked by jmc@
2009-05-06 18:47:32 +00:00
otto
b721e737e1 add a comment explaining the rather obscure decision when to recurse
or not; ok millert@ pedro@
2008-12-30 15:37:30 +00:00
otto
1bc65825a6 fix previous; e.g. ls /var/spool/mqueue as an oridinary user. ok
millert@ thib@
2008-12-29 14:49:27 +00:00
otto
a9129fda85 Kill a race condition which occurs when listing a directory containing
an empty dir non-recursively. By not setting FTS_SKIP on the empty
subdir, a next iteration of the fts_read loop recurses into the
subdir, which might not be empty any more.  Report by jacekm@,
troublespot identified by pedro@; ok pedro@ millert@
2008-12-24 20:57:21 +00:00
jmc
a40a3c37ed - make -ln and -nl combinations behave identically. currently -l overrides -n.
behaviour now similar to netbsd/freebsd/solaris.

- make -gn and -ng combinations behave identically: long listing, numeric
group ID, no user ID. currently -g overrides -n. behaviour now similar to
netbsd/solaris.

- allow -m and -x to override -1Cgln (and each other) if specified last.
currently -m and -x can be overriden even if they are specified last.
behaviour now similar to netbsd/freebsd. fixes PR 5785 from
Jacek Masiulaniec.

- update man page to reflect reality.

ls.c diff based on Jacek Masiulaniec's diff from PR 5785, and extended by
sobrado. this work is really a joint effort from sobrado and myself.
i don't know about igor, but this particular diff has nearly killed me...

ok millert otto
2008-09-04 15:44:41 +00:00
millert
947f7ba6d0 Change the -g flag from a no-op to be POSIX conforming. We allow the
-l flag to override -g regardless of its position on the command line
for backwards compat with 4.3BSD.  From NetBSD.
OK jmc@, tom@, sobrado@
2007-05-07 18:39:28 +00:00
dhill
4857c473aa Change maxsize to type off_t.
Add a cast for portability's sake.

"Right..." @deraadt
2006-04-13 03:14:18 +00:00
deraadt
7cc1b54ae0 another unused variable found by lint 2005-11-30 00:57:25 +00:00
otto
ed3e8c994f kill unused var found by lint. ok deraadt@ 2005-11-29 20:32:22 +00:00
deraadt
4e4bc84146 do not exit from ls_main() but return; spotted by lint 2005-11-25 20:37:45 +00:00
millert
0278adda01 remove whiteout support 2005-06-15 17:47:17 +00:00
jaredy
bb6ffffeff use fts_path if fts_name is not available, tweak and ok millert 2005-03-10 00:22:08 +00:00
otto
445ea396fe Unbreak alignment of fields when using -lh.
ok deraadt@
2004-04-02 07:31:06 +00:00
tedu
91ea06e0c5 -h, human readable sizes. from a jonathon gray mail to tech@
ok ian@ millert@
2003-08-06 19:09:09 +00:00
deraadt
28416801cb ansification, art ok 2003-06-11 23:42:12 +00:00
millert
29295d1c5c Remove the advertising clause in the UCB license which Berkeley
rescinded 22 July 1999.  Proofed by myself and Theo.
2003-06-02 23:27:43 +00:00
deraadt
150e4ac30a strlcpy; millert ok 2003-04-02 19:43:52 +00:00
millert
21162ec0e3 o Remove local prototypes for group_from_gid() and user_from_uid()
since they are prototyped in grp.h and pwd.h.
o Increase size of 'buf' to 21 since we store the string representation
  of a u_quad_t in it (max 20 chars + the NUL).
o Minor KNF wrt pointers in boolean context.
From Denis Afonin
2002-03-12 01:05:15 +00:00
millert
c72b5b24e1 Part one of userland __P removal. Done with a simple regexp with some minor hand editing to make comments line up correctly. Another pass is forthcoming that handles the cases that could not be done automatically. 2002-02-16 21:27:05 +00:00
deraadt
c28fedd73d -Wall 2001-07-09 00:37:53 +00:00
mickey
b802a6c280 new strtofflags/fflagstostr 2000-07-19 19:27:35 +00:00
deraadt
413925e680 defer conversion of unprintable filenames till final display, permitting
badly named symbolic links to be handled; bug noted by dm@ fixed by d@
1999-05-01 23:54:47 +00:00
aaron
4884558f02 save cpu cycles by being more sensible about how we check conditionals 1999-02-24 16:48:02 +00:00
art
415ae12781 Break out main to an own file so we can include ls in ftpd. 1999-02-23 23:54:16 +00:00
deraadt
b94f2f8772 add -x, -p, and -m options, based on netbsd work 1999-02-20 18:59:24 +00:00
deraadt
fa39892572 fix exit code; problem reported by jsh@sun470.rd.qms.com; fix from freebsd 1998-08-07 19:45:06 +00:00
deraadt
817b1966d7 make ls -d still sort files in the regular order; reported by
roberte@MEP.Ruhr-Uni-Bochum.de, fixed by sef@Kithrup.COM
1997-09-18 07:58:41 +00:00
deraadt
404227c865 option 'n' was unused, so let's come up with a feature to use it!!! YEAH!!
add -n (numeric uid/gid), fix some man page errors; tv@pobox.com
1997-04-01 22:59:36 +00:00