]> git.ipfire.org Git - thirdparty/coreutils.git/commit
ls: compute defaults more lazily
authorPaul Eggert <eggert@cs.ucla.edu>
Tue, 27 Jul 2021 21:27:00 +0000 (14:27 -0700)
committerPaul Eggert <eggert@cs.ucla.edu>
Wed, 28 Jul 2021 01:08:38 +0000 (18:08 -0700)
commit9e4a6101f239b8168144078edd04843dea4dc69f
treebf88cc241a68119b3f83452b3ef2862283b7367f
parente094d2e3e1216a9511087f4fe1fe0d0dbc10013d
ls: compute defaults more lazily

* src/ls.c (enum time_type, enum sort_type, enum indicator_style)
(enum Dereference_symlink, ignore_mode):
Put ‘= 0’ after default values, since the code relies
on static storage defaulting to zero.
(enum sort_type): Reorder so that -1 can be used to represent unset.
(main): Test print_with_color after parse_ls_color may have reset it.
(decode_line_length): Return the line length instead of setting
static storage.  All uses changed.  Treat line lengths exceeding
PTRDIFF_MAX as infinite, to avoid pointer-subtraction glitches.
(stdout_isatty): New function, to avoid calling isatty twice.
(decode_switches): Calculate defaults more lazily, to avoid using
syscalls or getenv during startup unless the results are more
likely to be needed.  Use -1 to indicate options that haven’t been
set on the command line yet.  Move print_with_color test from
here to ‘main’.  Suppress bogus GCC warning.
(getenv_quoting_style): Return the quoting style instead of
setting static storage.
(init_column_info): New arg MAX_COLS, to avoid recalculating it.
Caller changed.
src/ls.c