OpenCoverage

ls.c

Absolute File Name:/home/opencoverage/opencoverage/guest-scripts/coreutils/src/src/ls.c
Source codeSwitch to Preprocessed file
LineSourceCount
1/* 'dir', 'vdir' and 'ls' directory listing programs for GNU.-
2 Copyright (C) 1985-2018 Free Software Foundation, Inc.-
3-
4 This program is free software: you can redistribute it and/or modify-
5 it under the terms of the GNU General Public License as published by-
6 the Free Software Foundation, either version 3 of the License, or-
7 (at your option) any later version.-
8-
9 This program is distributed in the hope that it will be useful,-
10 but WITHOUT ANY WARRANTY; without even the implied warranty of-
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the-
12 GNU General Public License for more details.-
13-
14 You should have received a copy of the GNU General Public License-
15 along with this program. If not, see <https://www.gnu.org/licenses/>. */-
16-
17/* If ls_mode is LS_MULTI_COL,-
18 the multi-column format is the default regardless-
19 of the type of output device.-
20 This is for the 'dir' program.-
21-
22 If ls_mode is LS_LONG_FORMAT,-
23 the long format is the default regardless of the-
24 type of output device.-
25 This is for the 'vdir' program.-
26-
27 If ls_mode is LS_LS,-
28 the output format depends on whether the output-
29 device is a terminal.-
30 This is for the 'ls' program. */-
31-
32/* Written by Richard Stallman and David MacKenzie. */-
33-
34/* Color support by Peter Anvin <Peter.Anvin@linux.org> and Dennis-
35 Flaherty <dennisf@denix.elk.miles.com> based on original patches by-
36 Greg Lee <lee@uhunix.uhcc.hawaii.edu>. */-
37-
38#include <config.h>-
39#include <sys/types.h>-
40-
41#include <termios.h>-
42#if HAVE_STROPTS_H-
43# include <stropts.h>-
44#endif-
45#include <sys/ioctl.h>-
46-
47#ifdef WINSIZE_IN_PTEM-
48# include <sys/stream.h>-
49# include <sys/ptem.h>-
50#endif-
51-
52#include <stdio.h>-
53#include <assert.h>-
54#include <setjmp.h>-
55#include <pwd.h>-
56#include <getopt.h>-
57#include <signal.h>-
58#include <selinux/selinux.h>-
59#include <wchar.h>-
60-
61#if HAVE_LANGINFO_CODESET-
62# include <langinfo.h>-
63#endif-
64-
65/* Use SA_NOCLDSTOP as a proxy for whether the sigaction machinery is-
66 present. */-
67#ifndef SA_NOCLDSTOP-
68# define SA_NOCLDSTOP 0-
69# define sigprocmask(How, Set, Oset) /* empty */-
70# define sigset_t int-
71# if ! HAVE_SIGINTERRUPT-
72# define siginterrupt(sig, flag) /* empty */-
73# endif-
74#endif-
75-
76/* NonStop circa 2011 lacks both SA_RESTART and siginterrupt, so don't-
77 restart syscalls after a signal handler fires. This may cause-
78 colors to get messed up on the screen if 'ls' is interrupted, but-
79 that's the best we can do on such a platform. */-
80#ifndef SA_RESTART-
81# define SA_RESTART 0-
82#endif-
83-
84#include "system.h"-
85#include <fnmatch.h>-
86-
87#include "acl.h"-
88#include "argmatch.h"-
89#include "dev-ino.h"-
90#include "die.h"-
91#include "error.h"-
92#include "filenamecat.h"-
93#include "hard-locale.h"-
94#include "hash.h"-
95#include "human.h"-
96#include "filemode.h"-
97#include "filevercmp.h"-
98#include "idcache.h"-
99#include "ls.h"-
100#include "mbswidth.h"-
101#include "mpsort.h"-
102#include "obstack.h"-
103#include "quote.h"-
104#include "smack.h"-
105#include "stat-size.h"-
106#include "stat-time.h"-
107#include "strftime.h"-
108#include "xdectoint.h"-
109#include "xstrtol.h"-
110#include "areadlink.h"-
111#include "mbsalign.h"-
112#include "dircolors.h"-
113#include "xgethostname.h"-
114#include "c-ctype.h"-
115#include "canonicalize.h"-
116-
117/* Include <sys/capability.h> last to avoid a clash of <sys/types.h>-
118 include guards with some premature versions of libcap.-
119 For more details, see <https://bugzilla.redhat.com/483548>. */-
120#ifdef HAVE_CAP-
121# include <sys/capability.h>-
122#endif-
123-
124#define PROGRAM_NAME (ls_mode == LS_LS ? "ls" \-
125 : (ls_mode == LS_MULTI_COL \-
126 ? "dir" : "vdir"))-
127-
128#define AUTHORS \-
129 proper_name ("Richard M. Stallman"), \-
130 proper_name ("David MacKenzie")-
131-
132#define obstack_chunk_alloc malloc-
133#define obstack_chunk_free free-
134-
135/* Return an int indicating the result of comparing two integers.-
136 Subtracting doesn't always work, due to overflow. */-
137#define longdiff(a, b) ((a) < (b) ? -1 : (a) > (b))-
138-
139/* Unix-based readdir implementations have historically returned a dirent.d_ino-
140 value that is sometimes not equal to the stat-obtained st_ino value for-
141 that same entry. This error occurs for a readdir entry that refers-
142 to a mount point. readdir's error is to return the inode number of-
143 the underlying directory -- one that typically cannot be stat'ed, as-
144 long as a file system is mounted on that directory. RELIABLE_D_INO-
145 encapsulates whether we can use the more efficient approach of relying-
146 on readdir-supplied d_ino values, or whether we must incur the cost of-
147 calling stat or lstat to obtain each guaranteed-valid inode number. */-
148-
149#ifndef READDIR_LIES_ABOUT_MOUNTPOINT_D_INO-
150# define READDIR_LIES_ABOUT_MOUNTPOINT_D_INO 1-
151#endif-
152-
153#if READDIR_LIES_ABOUT_MOUNTPOINT_D_INO-
154# define RELIABLE_D_INO(dp) NOT_AN_INODE_NUMBER-
155#else-
156# define RELIABLE_D_INO(dp) D_INO (dp)-
157#endif-
158-
159#if ! HAVE_STRUCT_STAT_ST_AUTHOR-
160# define st_author st_uid-
161#endif-
162-
163enum filetype-
164 {-
165 unknown,-
166 fifo,-
167 chardev,-
168 directory,-
169 blockdev,-
170 normal,-
171 symbolic_link,-
172 sock,-
173 whiteout,-
174 arg_directory-
175 };-
176-
177/* Display letters and indicators for each filetype.-
178 Keep these in sync with enum filetype. */-
179static char const filetype_letter[] = "?pcdb-lswd";-
180-
181/* Ensure that filetype and filetype_letter have the same-
182 number of elements. */-
183verify (sizeof filetype_letter - 1 == arg_directory + 1);-
184-
185#define FILETYPE_INDICATORS \-
186 { \-
187 C_ORPHAN, C_FIFO, C_CHR, C_DIR, C_BLK, C_FILE, \-
188 C_LINK, C_SOCK, C_FILE, C_DIR \-
189 }-
190-
191enum acl_type-
192 {-
193 ACL_T_NONE,-
194 ACL_T_LSM_CONTEXT_ONLY,-
195 ACL_T_YES-
196 };-
197-
198struct fileinfo-
199 {-
200 /* The file name. */-
201 char *name;-
202-
203 /* For symbolic link, name of the file linked to, otherwise zero. */-
204 char *linkname;-
205-
206 /* For terminal hyperlinks. */-
207 char *absolute_name;-
208-
209 struct stat stat;-
210-
211 enum filetype filetype;-
212-
213 /* For symbolic link and long listing, st_mode of file linked to, otherwise-
214 zero. */-
215 mode_t linkmode;-
216-
217 /* security context. */-
218 char *scontext;-
219-
220 bool stat_ok;-
221-
222 /* For symbolic link and color printing, true if linked-to file-
223 exists, otherwise false. */-
224 bool linkok;-
225-
226 /* For long listings, true if the file has an access control list,-
227 or a security context. */-
228 enum acl_type acl_type;-
229-
230 /* For color listings, true if a regular file has capability info. */-
231 bool has_capability;-
232-
233 /* Whether file name needs quoting. tri-state with -1 == unknown. */-
234 int quoted;-
235 };-
236-
237#define LEN_STR_PAIR(s) sizeof (s) - 1, s-
238-
239/* Null is a valid character in a color indicator (think about Epson-
240 printers, for example) so we have to use a length/buffer string-
241 type. */-
242-
243struct bin_str-
244 {-
245 size_t len; /* Number of bytes */-
246 const char *string; /* Pointer to the same */-
247 };-
248-
249#if ! HAVE_TCGETPGRP-
250# define tcgetpgrp(Fd) 0-
251#endif-
252-
253static size_t quote_name (char const *name,-
254 struct quoting_options const *options,-
255 int needs_general_quoting,-
256 const struct bin_str *color,-
257 bool allow_pad, struct obstack *stack,-
258 char const *absolute_name);-
259static size_t quote_name_buf (char **inbuf, size_t bufsize, char *name,-
260 struct quoting_options const *options,-
261 int needs_general_quoting, size_t *width,-
262 bool *pad);-
263static char *make_link_name (char const *name, char const *linkname);-
264static int decode_switches (int argc, char **argv);-
265static bool file_ignored (char const *name);-
266static uintmax_t gobble_file (char const *name, enum filetype type,-
267 ino_t inode, bool command_line_arg,-
268 char const *dirname);-
269static const struct bin_str * get_color_indicator (const struct fileinfo *f,-
270 bool symlink_target);-
271static bool print_color_indicator (const struct bin_str *ind);-
272static void put_indicator (const struct bin_str *ind);-
273static void add_ignore_pattern (const char *pattern);-
274static void attach (char *dest, const char *dirname, const char *name);-
275static void clear_files (void);-
276static void extract_dirs_from_files (char const *dirname,-
277 bool command_line_arg);-
278static void get_link_name (char const *filename, struct fileinfo *f,-
279 bool command_line_arg);-
280static void indent (size_t from, size_t to);-
281static size_t calculate_columns (bool by_columns);-
282static void print_current_files (void);-
283static void print_dir (char const *name, char const *realname,-
284 bool command_line_arg);-
285static size_t print_file_name_and_frills (const struct fileinfo *f,-
286 size_t start_col);-
287static void print_horizontal (void);-
288static int format_user_width (uid_t u);-
289static int format_group_width (gid_t g);-
290static void print_long_format (const struct fileinfo *f);-
291static void print_many_per_line (void);-
292static size_t print_name_with_quoting (const struct fileinfo *f,-
293 bool symlink_target,-
294 struct obstack *stack,-
295 size_t start_col);-
296static void prep_non_filename_text (void);-
297static bool print_type_indicator (bool stat_ok, mode_t mode,-
298 enum filetype type);-
299static void print_with_separator (char sep);-
300static void queue_directory (char const *name, char const *realname,-
301 bool command_line_arg);-
302static void sort_files (void);-
303static void parse_ls_color (void);-
304-
305static void getenv_quoting_style (void);-
306-
307/* Initial size of hash table.-
308 Most hierarchies are likely to be shallower than this. */-
309#define INITIAL_TABLE_SIZE 30-
310-
311/* The set of 'active' directories, from the current command-line argument-
312 to the level in the hierarchy at which files are being listed.-
313 A directory is represented by its device and inode numbers (struct dev_ino).-
314 A directory is added to this set when ls begins listing it or its-
315 entries, and it is removed from the set just after ls has finished-
316 processing it. This set is used solely to detect loops, e.g., with-
317 mkdir loop; cd loop; ln -s ../loop sub; ls -RL */-
318static Hash_table *active_dir_set;-
319-
320#define LOOP_DETECT (!!active_dir_set)-
321-
322/* The table of files in the current directory:-
323-
324 'cwd_file' points to a vector of 'struct fileinfo', one per file.-
325 'cwd_n_alloc' is the number of elements space has been allocated for.-
326 'cwd_n_used' is the number actually in use. */-
327-
328/* Address of block containing the files that are described. */-
329static struct fileinfo *cwd_file;-
330-
331/* Length of block that 'cwd_file' points to, measured in files. */-
332static size_t cwd_n_alloc;-
333-
334/* Index of first unused slot in 'cwd_file'. */-
335static size_t cwd_n_used;-
336-
337/* Whether files needs may need padding due to quoting. */-
338static bool cwd_some_quoted;-
339-
340/* Whether quoting style _may_ add outer quotes,-
341 and whether aligning those is useful. */-
342static bool align_variable_outer_quotes;-
343-
344/* Vector of pointers to files, in proper sorted order, and the number-
345 of entries allocated for it. */-
346static void **sorted_file;-
347static size_t sorted_file_alloc;-
348-
349/* When true, in a color listing, color each symlink name according to the-
350 type of file it points to. Otherwise, color them according to the 'ln'-
351 directive in LS_COLORS. Dangling (orphan) symlinks are treated specially,-
352 regardless. This is set when 'ln=target' appears in LS_COLORS. */-
353-
354static bool color_symlink_as_referent;-
355-
356static char const *hostname;-
357-
358/* mode of appropriate file for colorization */-
359#define FILE_OR_LINK_MODE(File) \-
360 ((color_symlink_as_referent && (File)->linkok) \-
361 ? (File)->linkmode : (File)->stat.st_mode)-
362-
363-
364/* Record of one pending directory waiting to be listed. */-
365-
366struct pending-
367 {-
368 char *name;-
369 /* If the directory is actually the file pointed to by a symbolic link we-
370 were told to list, 'realname' will contain the name of the symbolic-
371 link, otherwise zero. */-
372 char *realname;-
373 bool command_line_arg;-
374 struct pending *next;-
375 };-
376-
377static struct pending *pending_dirs;-
378-
379/* Current time in seconds and nanoseconds since 1970, updated as-
380 needed when deciding whether a file is recent. */-
381-
382static struct timespec current_time;-
383-
384static bool print_scontext;-
385static char UNKNOWN_SECURITY_CONTEXT[] = "?";-
386-
387/* Whether any of the files has an ACL. This affects the width of the-
388 mode column. */-
389-
390static bool any_has_acl;-
391-
392/* The number of columns to use for columns containing inode numbers,-
393 block sizes, link counts, owners, groups, authors, major device-
394 numbers, minor device numbers, and file sizes, respectively. */-
395-
396static int inode_number_width;-
397static int block_size_width;-
398static int nlink_width;-
399static int scontext_width;-
400static int owner_width;-
401static int group_width;-
402static int author_width;-
403static int major_device_number_width;-
404static int minor_device_number_width;-
405static int file_size_width;-
406-
407/* Option flags */-
408-
409/* long_format for lots of info, one per line.-
410 one_per_line for just names, one per line.-
411 many_per_line for just names, many per line, sorted vertically.-
412 horizontal for just names, many per line, sorted horizontally.-
413 with_commas for just names, many per line, separated by commas.-
414-
415 -l (and other options that imply -l), -1, -C, -x and -m control-
416 this parameter. */-
417-
418enum format-
419 {-
420 long_format, /* -l and other options that imply -l */-
421 one_per_line, /* -1 */-
422 many_per_line, /* -C */-
423 horizontal, /* -x */-
424 with_commas /* -m */-
425 };-
426-
427static enum format format;-
428-
429/* 'full-iso' uses full ISO-style dates and times. 'long-iso' uses longer-
430 ISO-style timestamps, though shorter than 'full-iso'. 'iso' uses shorter-
431 ISO-style timestamps. 'locale' uses locale-dependent timestamps. */-
432enum time_style-
433 {-
434 full_iso_time_style, /* --time-style=full-iso */-
435 long_iso_time_style, /* --time-style=long-iso */-
436 iso_time_style, /* --time-style=iso */-
437 locale_time_style /* --time-style=locale */-
438 };-
439-
440static char const *const time_style_args[] =-
441{-
442 "full-iso", "long-iso", "iso", "locale", NULL-
443};-
444static enum time_style const time_style_types[] =-
445{-
446 full_iso_time_style, long_iso_time_style, iso_time_style,-
447 locale_time_style-
448};-
449ARGMATCH_VERIFY (time_style_args, time_style_types);-
450-
451/* Type of time to print or sort by. Controlled by -c and -u.-
452 The values of each item of this enum are important since they are-
453 used as indices in the sort functions array (see sort_files()). */-
454-
455enum time_type-
456 {-
457 time_mtime, /* default */-
458 time_ctime, /* -c */-
459 time_atime, /* -u */-
460 time_numtypes /* the number of elements of this enum */-
461 };-
462-
463static enum time_type time_type;-
464-
465/* The file characteristic to sort by. Controlled by -t, -S, -U, -X, -v.-
466 The values of each item of this enum are important since they are-
467 used as indices in the sort functions array (see sort_files()). */-
468-
469enum sort_type-
470 {-
471 sort_none = -1, /* -U */-
472 sort_name, /* default */-
473 sort_extension, /* -X */-
474 sort_size, /* -S */-
475 sort_version, /* -v */-
476 sort_time, /* -t */-
477 sort_numtypes /* the number of elements of this enum */-
478 };-
479-
480static enum sort_type sort_type;-
481-
482/* Direction of sort.-
483 false means highest first if numeric,-
484 lowest first if alphabetic;-
485 these are the defaults.-
486 true means the opposite order in each case. -r */-
487-
488static bool sort_reverse;-
489-
490/* True means to display owner information. -g turns this off. */-
491-
492static bool print_owner = true;-
493-
494/* True means to display author information. */-
495-
496static bool print_author;-
497-
498/* True means to display group information. -G and -o turn this off. */-
499-
500static bool print_group = true;-
501-
502/* True means print the user and group id's as numbers rather-
503 than as names. -n */-
504-
505static bool numeric_ids;-
506-
507/* True means mention the size in blocks of each file. -s */-
508-
509static bool print_block_size;-
510-
511/* Human-readable options for output, when printing block counts. */-
512static int human_output_opts;-
513-
514/* The units to use when printing block counts. */-
515static uintmax_t output_block_size;-
516-
517/* Likewise, but for file sizes. */-
518static int file_human_output_opts;-
519static uintmax_t file_output_block_size = 1;-
520-
521/* Follow the output with a special string. Using this format,-
522 Emacs' dired mode starts up twice as fast, and can handle all-
523 strange characters in file names. */-
524static bool dired;-
525-
526/* 'none' means don't mention the type of files.-
527 'slash' means mention directories only, with a '/'.-
528 'file_type' means mention file types.-
529 'classify' means mention file types and mark executables.-
530-
531 Controlled by -F, -p, and --indicator-style. */-
532-
533enum indicator_style-
534 {-
535 none, /* --indicator-style=none */-
536 slash, /* -p, --indicator-style=slash */-
537 file_type, /* --indicator-style=file-type */-
538 classify /* -F, --indicator-style=classify */-
539 };-
540-
541static enum indicator_style indicator_style;-
542-
543/* Names of indicator styles. */-
544static char const *const indicator_style_args[] =-
545{-
546 "none", "slash", "file-type", "classify", NULL-
547};-
548static enum indicator_style const indicator_style_types[] =-
549{-
550 none, slash, file_type, classify-
551};-
552ARGMATCH_VERIFY (indicator_style_args, indicator_style_types);-
553-
554/* True means use colors to mark types. Also define the different-
555 colors as well as the stuff for the LS_COLORS environment variable.-
556 The LS_COLORS variable is now in a termcap-like format. */-
557-
558static bool print_with_color;-
559-
560static bool print_hyperlink;-
561-
562/* Whether we used any colors in the output so far. If so, we will-
563 need to restore the default color later. If not, we will need to-
564 call prep_non_filename_text before using color for the first time. */-
565-
566static bool used_color = false;-
567-
568enum when_type-
569 {-
570 when_never, /* 0: default or --color=never */-
571 when_always, /* 1: --color=always */-
572 when_if_tty /* 2: --color=tty */-
573 };-
574-
575enum Dereference_symlink-
576 {-
577 DEREF_UNDEFINED = 1,-
578 DEREF_NEVER,-
579 DEREF_COMMAND_LINE_ARGUMENTS, /* -H */-
580 DEREF_COMMAND_LINE_SYMLINK_TO_DIR, /* the default, in certain cases */-
581 DEREF_ALWAYS /* -L */-
582 };-
583-
584enum indicator_no-
585 {-
586 C_LEFT, C_RIGHT, C_END, C_RESET, C_NORM, C_FILE, C_DIR, C_LINK,-
587 C_FIFO, C_SOCK,-
588 C_BLK, C_CHR, C_MISSING, C_ORPHAN, C_EXEC, C_DOOR, C_SETUID, C_SETGID,-
589 C_STICKY, C_OTHER_WRITABLE, C_STICKY_OTHER_WRITABLE, C_CAP, C_MULTIHARDLINK,-
590 C_CLR_TO_EOL-
591 };-
592-
593static const char *const indicator_name[]=-
594 {-
595 "lc", "rc", "ec", "rs", "no", "fi", "di", "ln", "pi", "so",-
596 "bd", "cd", "mi", "or", "ex", "do", "su", "sg", "st",-
597 "ow", "tw", "ca", "mh", "cl", NULL-
598 };-
599-
600struct color_ext_type-
601 {-
602 struct bin_str ext; /* The extension we're looking for */-
603 struct bin_str seq; /* The sequence to output when we do */-
604 struct color_ext_type *next; /* Next in list */-
605 };-
606-
607static struct bin_str color_indicator[] =-
608 {-
609 { LEN_STR_PAIR ("\033[") }, /* lc: Left of color sequence */-
610 { LEN_STR_PAIR ("m") }, /* rc: Right of color sequence */-
611 { 0, NULL }, /* ec: End color (replaces lc+rs+rc) */-
612 { LEN_STR_PAIR ("0") }, /* rs: Reset to ordinary colors */-
613 { 0, NULL }, /* no: Normal */-
614 { 0, NULL }, /* fi: File: default */-
615 { LEN_STR_PAIR ("01;34") }, /* di: Directory: bright blue */-
616 { LEN_STR_PAIR ("01;36") }, /* ln: Symlink: bright cyan */-
617 { LEN_STR_PAIR ("33") }, /* pi: Pipe: yellow/brown */-
618 { LEN_STR_PAIR ("01;35") }, /* so: Socket: bright magenta */-
619 { LEN_STR_PAIR ("01;33") }, /* bd: Block device: bright yellow */-
620 { LEN_STR_PAIR ("01;33") }, /* cd: Char device: bright yellow */-
621 { 0, NULL }, /* mi: Missing file: undefined */-
622 { 0, NULL }, /* or: Orphaned symlink: undefined */-
623 { LEN_STR_PAIR ("01;32") }, /* ex: Executable: bright green */-
624 { LEN_STR_PAIR ("01;35") }, /* do: Door: bright magenta */-
625 { LEN_STR_PAIR ("37;41") }, /* su: setuid: white on red */-
626 { LEN_STR_PAIR ("30;43") }, /* sg: setgid: black on yellow */-
627 { LEN_STR_PAIR ("37;44") }, /* st: sticky: black on blue */-
628 { LEN_STR_PAIR ("34;42") }, /* ow: other-writable: blue on green */-
629 { LEN_STR_PAIR ("30;42") }, /* tw: ow w/ sticky: black on green */-
630 { LEN_STR_PAIR ("30;41") }, /* ca: black on red */-
631 { 0, NULL }, /* mh: disabled by default */-
632 { LEN_STR_PAIR ("\033[K") }, /* cl: clear to end of line */-
633 };-
634-
635/* FIXME: comment */-
636static struct color_ext_type *color_ext_list = NULL;-
637-
638/* Buffer for color sequences */-
639static char *color_buf;-
640-
641/* True means to check for orphaned symbolic link, for displaying-
642 colors. */-
643-
644static bool check_symlink_color;-
645-
646/* True means mention the inode number of each file. -i */-
647-
648static bool print_inode;-
649-
650/* What to do with symbolic links. Affected by -d, -F, -H, -l (and-
651 other options that imply -l), and -L. */-
652-
653static enum Dereference_symlink dereference;-
654-
655/* True means when a directory is found, display info on its-
656 contents. -R */-
657-
658static bool recursive;-
659-
660/* True means when an argument is a directory name, display info-
661 on it itself. -d */-
662-
663static bool immediate_dirs;-
664-
665/* True means that directories are grouped before files. */-
666-
667static bool directories_first;-
668-
669/* Which files to ignore. */-
670-
671static enum-
672{-
673 /* Ignore files whose names start with '.', and files specified by-
674 --hide and --ignore. */-
675 IGNORE_DEFAULT,-
676-
677 /* Ignore '.', '..', and files specified by --ignore. */-
678 IGNORE_DOT_AND_DOTDOT,-
679-
680 /* Ignore only files specified by --ignore. */-
681 IGNORE_MINIMAL-
682} ignore_mode;-
683-
684/* A linked list of shell-style globbing patterns. If a non-argument-
685 file name matches any of these patterns, it is ignored.-
686 Controlled by -I. Multiple -I options accumulate.-
687 The -B option adds '*~' and '.*~' to this list. */-
688-
689struct ignore_pattern-
690 {-
691 const char *pattern;-
692 struct ignore_pattern *next;-
693 };-
694-
695static struct ignore_pattern *ignore_patterns;-
696-
697/* Similar to IGNORE_PATTERNS, except that -a or -A causes this-
698 variable itself to be ignored. */-
699static struct ignore_pattern *hide_patterns;-
700-
701/* True means output nongraphic chars in file names as '?'.-
702 (-q, --hide-control-chars)-
703 qmark_funny_chars and the quoting style (-Q, --quoting-style=WORD) are-
704 independent. The algorithm is: first, obey the quoting style to get a-
705 string representing the file name; then, if qmark_funny_chars is set,-
706 replace all nonprintable chars in that string with '?'. It's necessary-
707 to replace nonprintable chars even in quoted strings, because we don't-
708 want to mess up the terminal if control chars get sent to it, and some-
709 quoting methods pass through control chars as-is. */-
710static bool qmark_funny_chars;-
711-
712/* Quoting options for file and dir name output. */-
713-
714static struct quoting_options *filename_quoting_options;-
715static struct quoting_options *dirname_quoting_options;-
716-
717/* The number of chars per hardware tab stop. Setting this to zero-
718 inhibits the use of TAB characters for separating columns. -T */-
719static size_t tabsize;-
720-
721/* True means print each directory name before listing it. */-
722-
723static bool print_dir_name;-
724-
725/* The line length to use for breaking lines in many-per-line format.-
726 Can be set with -w. */-
727-
728static size_t line_length;-
729-
730/* The local time zone rules, as per the TZ environment variable. */-
731-
732static timezone_t localtz;-
733-
734/* If true, the file listing format requires that stat be called on-
735 each file. */-
736-
737static bool format_needs_stat;-
738-
739/* Similar to 'format_needs_stat', but set if only the file type is-
740 needed. */-
741-
742static bool format_needs_type;-
743-
744/* An arbitrary limit on the number of bytes in a printed timestamp.-
745 This is set to a relatively small value to avoid the need to worry-
746 about denial-of-service attacks on servers that run "ls" on behalf-
747 of remote clients. 1000 bytes should be enough for any practical-
748 timestamp format. */-
749-
750enum { TIME_STAMP_LEN_MAXIMUM = MAX (1000, INT_STRLEN_BOUND (time_t)) };-
751-
752/* strftime formats for non-recent and recent files, respectively, in-
753 -l output. */-
754-
755static char const *long_time_format[2] =-
756 {-
757 /* strftime format for non-recent files (older than 6 months), in-
758 -l output. This should contain the year, month and day (at-
759 least), in an order that is understood by people in your-
760 locale's territory. Please try to keep the number of used-
761 screen columns small, because many people work in windows with-
762 only 80 columns. But make this as wide as the other string-
763 below, for recent files. */-
764 /* TRANSLATORS: ls output needs to be aligned for ease of reading,-
765 so be wary of using variable width fields from the locale.-
766 Note %b is handled specially by ls and aligned correctly.-
767 Note also that specifying a width as in %5b is erroneous as strftime-
768 will count bytes rather than characters in multibyte locales. */-
769 N_("%b %e %Y"),-
770 /* strftime format for recent files (younger than 6 months), in -l-
771 output. This should contain the month, day and time (at-
772 least), in an order that is understood by people in your-
773 locale's territory. Please try to keep the number of used-
774 screen columns small, because many people work in windows with-
775 only 80 columns. But make this as wide as the other string-
776 above, for non-recent files. */-
777 /* TRANSLATORS: ls output needs to be aligned for ease of reading,-
778 so be wary of using variable width fields from the locale.-
779 Note %b is handled specially by ls and aligned correctly.-
780 Note also that specifying a width as in %5b is erroneous as strftime-
781 will count bytes rather than characters in multibyte locales. */-
782 N_("%b %e %H:%M")-
783 };-
784-
785/* The set of signals that are caught. */-
786-
787static sigset_t caught_signals;-
788-
789/* If nonzero, the value of the pending fatal signal. */-
790-
791static sig_atomic_t volatile interrupt_signal;-
792-
793/* A count of the number of pending stop signals that have been received. */-
794-
795static sig_atomic_t volatile stop_signal_count;-
796-
797/* Desired exit status. */-
798-
799static int exit_status;-
800-
801/* Exit statuses. */-
802enum-
803 {-
804 /* "ls" had a minor problem. E.g., while processing a directory,-
805 ls obtained the name of an entry via readdir, yet was later-
806 unable to stat that name. This happens when listing a directory-
807 in which entries are actively being removed or renamed. */-
808 LS_MINOR_PROBLEM = 1,-
809-
810 /* "ls" had more serious trouble (e.g., memory exhausted, invalid-
811 option or failure to stat a command line argument. */-
812 LS_FAILURE = 2-
813 };-
814-
815/* For long options that have no equivalent short option, use a-
816 non-character as a pseudo short option, starting with CHAR_MAX + 1. */-
817enum-
818{-
819 AUTHOR_OPTION = CHAR_MAX + 1,-
820 BLOCK_SIZE_OPTION,-
821 COLOR_OPTION,-
822 DEREFERENCE_COMMAND_LINE_SYMLINK_TO_DIR_OPTION,-
823 FILE_TYPE_INDICATOR_OPTION,-
824 FORMAT_OPTION,-
825 FULL_TIME_OPTION,-
826 GROUP_DIRECTORIES_FIRST_OPTION,-
827 HIDE_OPTION,-
828 HYPERLINK_OPTION,-
829 INDICATOR_STYLE_OPTION,-
830 QUOTING_STYLE_OPTION,-
831 SHOW_CONTROL_CHARS_OPTION,-
832 SI_OPTION,-
833 SORT_OPTION,-
834 TIME_OPTION,-
835 TIME_STYLE_OPTION-
836};-
837-
838static struct option const long_options[] =-
839{-
840 {"all", no_argument, NULL, 'a'},-
841 {"escape", no_argument, NULL, 'b'},-
842 {"directory", no_argument, NULL, 'd'},-
843 {"dired", no_argument, NULL, 'D'},-
844 {"full-time", no_argument, NULL, FULL_TIME_OPTION},-
845 {"group-directories-first", no_argument, NULL,-
846 GROUP_DIRECTORIES_FIRST_OPTION},-
847 {"human-readable", no_argument, NULL, 'h'},-
848 {"inode", no_argument, NULL, 'i'},-
849 {"kibibytes", no_argument, NULL, 'k'},-
850 {"numeric-uid-gid", no_argument, NULL, 'n'},-
851 {"no-group", no_argument, NULL, 'G'},-
852 {"hide-control-chars", no_argument, NULL, 'q'},-
853 {"reverse", no_argument, NULL, 'r'},-
854 {"size", no_argument, NULL, 's'},-
855 {"width", required_argument, NULL, 'w'},-
856 {"almost-all", no_argument, NULL, 'A'},-
857 {"ignore-backups", no_argument, NULL, 'B'},-
858 {"classify", no_argument, NULL, 'F'},-
859 {"file-type", no_argument, NULL, FILE_TYPE_INDICATOR_OPTION},-
860 {"si", no_argument, NULL, SI_OPTION},-
861 {"dereference-command-line", no_argument, NULL, 'H'},-
862 {"dereference-command-line-symlink-to-dir", no_argument, NULL,-
863 DEREFERENCE_COMMAND_LINE_SYMLINK_TO_DIR_OPTION},-
864 {"hide", required_argument, NULL, HIDE_OPTION},-
865 {"ignore", required_argument, NULL, 'I'},-
866 {"indicator-style", required_argument, NULL, INDICATOR_STYLE_OPTION},-
867 {"dereference", no_argument, NULL, 'L'},-
868 {"literal", no_argument, NULL, 'N'},-
869 {"quote-name", no_argument, NULL, 'Q'},-
870 {"quoting-style", required_argument, NULL, QUOTING_STYLE_OPTION},-
871 {"recursive", no_argument, NULL, 'R'},-
872 {"format", required_argument, NULL, FORMAT_OPTION},-
873 {"show-control-chars", no_argument, NULL, SHOW_CONTROL_CHARS_OPTION},-
874 {"sort", required_argument, NULL, SORT_OPTION},-
875 {"tabsize", required_argument, NULL, 'T'},-
876 {"time", required_argument, NULL, TIME_OPTION},-
877 {"time-style", required_argument, NULL, TIME_STYLE_OPTION},-
878 {"color", optional_argument, NULL, COLOR_OPTION},-
879 {"hyperlink", optional_argument, NULL, HYPERLINK_OPTION},-
880 {"block-size", required_argument, NULL, BLOCK_SIZE_OPTION},-
881 {"context", no_argument, 0, 'Z'},-
882 {"author", no_argument, NULL, AUTHOR_OPTION},-
883 {GETOPT_HELP_OPTION_DECL},-
884 {GETOPT_VERSION_OPTION_DECL},-
885 {NULL, 0, NULL, 0}-
886};-
887-
888static char const *const format_args[] =-
889{-
890 "verbose", "long", "commas", "horizontal", "across",-
891 "vertical", "single-column", NULL-
892};-
893static enum format const format_types[] =-
894{-
895 long_format, long_format, with_commas, horizontal, horizontal,-
896 many_per_line, one_per_line-
897};-
898ARGMATCH_VERIFY (format_args, format_types);-
899-
900static char const *const sort_args[] =-
901{-
902 "none", "time", "size", "extension", "version", NULL-
903};-
904static enum sort_type const sort_types[] =-
905{-
906 sort_none, sort_time, sort_size, sort_extension, sort_version-
907};-
908ARGMATCH_VERIFY (sort_args, sort_types);-
909-
910static char const *const time_args[] =-
911{-
912 "atime", "access", "use", "ctime", "status", NULL-
913};-
914static enum time_type const time_types[] =-
915{-
916 time_atime, time_atime, time_atime, time_ctime, time_ctime-
917};-
918ARGMATCH_VERIFY (time_args, time_types);-
919-
920static char const *const when_args[] =-
921{-
922 /* force and none are for compatibility with another color-ls version */-
923 "always", "yes", "force",-
924 "never", "no", "none",-
925 "auto", "tty", "if-tty", NULL-
926};-
927static enum when_type const when_types[] =-
928{-
929 when_always, when_always, when_always,-
930 when_never, when_never, when_never,-
931 when_if_tty, when_if_tty, when_if_tty-
932};-
933ARGMATCH_VERIFY (when_args, when_types);-
934-
935/* Information about filling a column. */-
936struct column_info-
937{-
938 bool valid_len;-
939 size_t line_len;-
940 size_t *col_arr;-
941};-
942-
943/* Array with information about column filledness. */-
944static struct column_info *column_info;-
945-
946/* Maximum number of columns ever possible for this display. */-
947static size_t max_idx;-
948-
949/* The minimum width of a column is 3: 1 character for the name and 2-
950 for the separating white space. */-
951#define MIN_COLUMN_WIDTH 3-
952-
953-
954/* This zero-based index is used solely with the --dired option.-
955 When that option is in effect, this counter is incremented for each-
956 byte of output generated by this program so that the beginning-
957 and ending indices (in that output) of every file name can be recorded-
958 and later output themselves. */-
959static size_t dired_pos;-
960-
961#define DIRED_PUTCHAR(c) do {putchar ((c)); ++dired_pos;} while (0)-
962-
963/* Write S to STREAM and increment DIRED_POS by S_LEN. */-
964#define DIRED_FPUTS(s, stream, s_len) \-
965 do {fputs (s, stream); dired_pos += s_len;} while (0)-
966-
967/* Like DIRED_FPUTS, but for use when S is a literal string. */-
968#define DIRED_FPUTS_LITERAL(s, stream) \-
969 do {fputs (s, stream); dired_pos += sizeof (s) - 1;} while (0)-
970-
971#define DIRED_INDENT() \-
972 do \-
973 { \-
974 if (dired) \-
975 DIRED_FPUTS_LITERAL (" ", stdout); \-
976 } \-
977 while (0)-
978-
979/* With --dired, store pairs of beginning and ending indices of file names. */-
980static struct obstack dired_obstack;-
981-
982/* With --dired, store pairs of beginning and ending indices of any-
983 directory names that appear as headers (just before 'total' line)-
984 for lists of directory entries. Such directory names are seen when-
985 listing hierarchies using -R and when a directory is listed with at-
986 least one other command line argument. */-
987static struct obstack subdired_obstack;-
988-
989/* Save the current index on the specified obstack, OBS. */-
990#define PUSH_CURRENT_DIRED_POS(obs) \-
991 do \-
992 { \-
993 if (dired) \-
994 obstack_grow (obs, &dired_pos, sizeof (dired_pos)); \-
995 } \-
996 while (0)-
997-
998/* With -R, this stack is used to help detect directory cycles.-
999 The device/inode pairs on this stack mirror the pairs in the-
1000 active_dir_set hash table. */-
1001static struct obstack dev_ino_obstack;-
1002-
1003/* Push a pair onto the device/inode stack. */-
1004static void-
1005dev_ino_push (dev_t dev, ino_t ino)-
1006{-
1007 void *vdi;-
1008 struct dev_ino *di;-
1009 int dev_ino_size = sizeof *di;-
1010 obstack_blank (&dev_ino_obstack, dev_ino_size);
never executed: _obstack_newchunk (__o, __len);
__extension__ ...e); }) < __lenDescription
TRUEnever evaluated
FALSEevaluated 10 times by 1 test
Evaluated by:
  • ls
0-10
1011 vdi = obstack_next_free (&dev_ino_obstack);-
1012 di = vdi;-
1013 di--;-
1014 di->st_dev = dev;-
1015 di->st_ino = ino;-
1016}
executed 10 times by 1 test: end of block
Executed by:
  • ls
10
1017-
1018/* Pop a dev/ino struct off the global dev_ino_obstack-
1019 and return that struct. */-
1020static struct dev_ino-
1021dev_ino_pop (void)-
1022{-
1023 void *vdi;-
1024 struct dev_ino *di;-
1025 int dev_ino_size = sizeof *di;-
1026 assert (dev_ino_size <= obstack_object_size (&dev_ino_obstack));-
1027 obstack_blank_fast (&dev_ino_obstack, -dev_ino_size);-
1028 vdi = obstack_next_free (&dev_ino_obstack);-
1029 di = vdi;-
1030 return *di;
executed 10 times by 1 test: return *di;
Executed by:
  • ls
10
1031}-
1032-
1033/* Note the use commented out below:-
1034#define ASSERT_MATCHING_DEV_INO(Name, Di) \-
1035 do \-
1036 { \-
1037 struct stat sb; \-
1038 assert (Name); \-
1039 assert (0 <= stat (Name, &sb)); \-
1040 assert (sb.st_dev == Di.st_dev); \-
1041 assert (sb.st_ino == Di.st_ino); \-
1042 } \-
1043 while (0)-
1044*/-
1045-
1046/* Write to standard output PREFIX, followed by the quoting style and-
1047 a space-separated list of the integers stored in OS all on one line. */-
1048-
1049static void-
1050dired_dump_obstack (const char *prefix, struct obstack *os)-
1051{-
1052 size_t n_pos;-
1053-
1054 n_pos = obstack_object_size (os) / sizeof (dired_pos);-
1055 if (n_pos > 0)
n_pos > 0Description
TRUEnever evaluated
FALSEnever evaluated
0
1056 {-
1057 size_t *pos = (size_t *) obstack_finish (os);
never executed: __o1->maybe_empty_object = 1;
never executed: __o1->next_free = __o1->chunk_limit;
__o1->next_free == __valueDescription
TRUEnever evaluated
FALSEnever evaluated
(size_t) (__o1...) __o1->chunk)Description
TRUEnever evaluated
FALSEnever evaluated
0
1058 fputs (prefix, stdout);-
1059 for (size_t i = 0; i < n_pos; i++)
i < n_posDescription
TRUEnever evaluated
FALSEnever evaluated
0
1060 printf (" %lu", (unsigned long int) pos[i]);
never executed: printf (" %lu", (unsigned long int) pos[i]);
0
1061 putchar ('\n');-
1062 }
never executed: end of block
0
1063}
never executed: end of block
0
1064-
1065/* Return the address of the first plain %b spec in FMT, or NULL if-
1066 there is no such spec. %5b etc. do not match, so that user-
1067 widths/flags are honored. */-
1068-
1069static char const * _GL_ATTRIBUTE_PURE-
1070first_percent_b (char const *fmt)-
1071{-
1072 for (; *fmt; fmt++)
*fmtDescription
TRUEevaluated 492 times by 2 tests
Evaluated by:
  • ls
  • vdir
FALSEevaluated 22 times by 1 test
Evaluated by:
  • ls
22-492
1073 if (fmt[0] == '%')
fmt[0] == '%'Description
TRUEevaluated 318 times by 2 tests
Evaluated by:
  • ls
  • vdir
FALSEevaluated 174 times by 1 test
Evaluated by:
  • ls
174-318
1074 switch (fmt[1])-
1075 {-
1076 case 'b': return fmt;
executed 276 times by 2 tests: return fmt;
Executed by:
  • ls
  • vdir
executed 276 times by 2 tests: case 'b':
Executed by:
  • ls
  • vdir
276
1077 case '%': fmt++; break;
never executed: break;
never executed: case '%':
0
1078 }
never executed: end of block
0
1079 return NULL;
executed 22 times by 1 test: return ((void *)0) ;
Executed by:
  • ls
22
1080}-
1081-
1082static char RFC3986[256];-
1083static void-
1084file_escape_init (void)-
1085{-
1086 for (int i = 0; i < 256; i++)
i < 256Description
TRUEnever evaluated
FALSEnever evaluated
0
1087 RFC3986[i] |= c_isalnum (i) || i == '~' || i == '-' || i == '.' || i == '_';
never executed: RFC3986[i] |= c_isalnum (i) || i == '~' || i == '-' || i == '.' || i == '_';
c_isalnum (i)Description
TRUEnever evaluated
FALSEnever evaluated
i == '~'Description
TRUEnever evaluated
FALSEnever evaluated
i == '-'Description
TRUEnever evaluated
FALSEnever evaluated
i == '.'Description
TRUEnever evaluated
FALSEnever evaluated
i == '_'Description
TRUEnever evaluated
FALSEnever evaluated
0
1088}
never executed: end of block
0
1089-
1090/* Read the abbreviated month names from the locale, to align them-
1091 and to determine the max width of the field and to truncate names-
1092 greater than our max allowed.-
1093 Note even though this handles multibyte locales correctly-
1094 it's not restricted to them as single byte locales can have-
1095 variable width abbreviated months and also precomputing/caching-
1096 the names was seen to increase the performance of ls significantly. */-
1097-
1098/* max number of display cells to use.-
1099 As of 2018 the abmon for Arabic has entries with width 12.-
1100 It doesn't make much sense to support wider than this-
1101 and locales should aim for abmon entries of width <= 5. */-
1102enum { MAX_MON_WIDTH = 12 };-
1103/* abformat[RECENT][MON] is the format to use for timestamps with-
1104 recentness RECENT and month MON. */-
1105enum { ABFORMAT_SIZE = 128 };-
1106static char abformat[2][12][ABFORMAT_SIZE];-
1107/* True if precomputed formats should be used. This can be false if-
1108 nl_langinfo fails, if a format or month abbreviation is unusually-
1109 long, or if a month abbreviation contains '%'. */-
1110static bool use_abformat;-
1111-
1112/* Store into ABMON the abbreviated month names, suitably aligned.-
1113 Return true if successful. */-
1114-
1115static bool-
1116abmon_init (char abmon[12][ABFORMAT_SIZE])-
1117{-
1118#ifndef HAVE_NL_LANGINFO-
1119 return false;-
1120#else-
1121 size_t required_mon_width = MAX_MON_WIDTH;-
1122 size_t curr_max_width;-
1123 do-
1124 {-
1125 curr_max_width = required_mon_width;-
1126 required_mon_width = 0;-
1127 for (int i = 0; i < 12; i++)
i < 12Description
TRUEevaluated 3312 times by 2 tests
Evaluated by:
  • ls
  • vdir
FALSEevaluated 276 times by 2 tests
Evaluated by:
  • ls
  • vdir
276-3312
1128 {-
1129 size_t width = curr_max_width;-
1130 char const *abbr = nl_langinfo (ABMON_1 + i);-
1131 if (strchr (abbr, '%'))
(__extension__...abbr , '%' )))Description
TRUEnever evaluated
FALSEevaluated 3312 times by 2 tests
Evaluated by:
  • ls
  • vdir
__builtin_constant_p ( '%' )Description
TRUEevaluated 3312 times by 2 tests
Evaluated by:
  • ls
  • vdir
FALSEnever evaluated
!__builtin_constant_p ( abbr )Description
TRUEevaluated 3312 times by 2 tests
Evaluated by:
  • ls
  • vdir
FALSEnever evaluated
( '%' ) == '\0'Description
TRUEnever evaluated
FALSEevaluated 3312 times by 2 tests
Evaluated by:
  • ls
  • vdir
0-3312
1132 return false;
never executed: return 0 ;
0
1133 size_t req = mbsalign (abbr, abmon[i], ABFORMAT_SIZE,-
1134 &width, MBS_ALIGN_LEFT, 0);-
1135 if (! (req < ABFORMAT_SIZE))
! (req < ABFORMAT_SIZE)Description
TRUEnever evaluated
FALSEevaluated 3312 times by 2 tests
Evaluated by:
  • ls
  • vdir
0-3312
1136 return false;
never executed: return 0 ;
0
1137 required_mon_width = MAX (required_mon_width, width);
(( required_mo...h )>( width ))Description
TRUEnever evaluated
FALSEevaluated 3312 times by 2 tests
Evaluated by:
  • ls
  • vdir
0-3312
1138 }
executed 3312 times by 2 tests: end of block
Executed by:
  • ls
  • vdir
3312
1139 }
executed 276 times by 2 tests: end of block
Executed by:
  • ls
  • vdir
276
1140 while (curr_max_width > required_mon_width);
curr_max_width...ired_mon_widthDescription
TRUEevaluated 138 times by 2 tests
Evaluated by:
  • ls
  • vdir
FALSEevaluated 138 times by 2 tests
Evaluated by:
  • ls
  • vdir
138
1141-
1142 return true;
executed 138 times by 2 tests: return 1 ;
Executed by:
  • ls
  • vdir
138
1143#endif-
1144}-
1145-
1146/* Initialize ABFORMAT and USE_ABFORMAT. */-
1147-
1148static void-
1149abformat_init (void)-
1150{-
1151 char const *pb[2];-
1152 for (int recent = 0; recent < 2; recent++)
recent < 2Description
TRUEevaluated 298 times by 2 tests
Evaluated by:
  • ls
  • vdir
FALSEevaluated 149 times by 2 tests
Evaluated by:
  • ls
  • vdir
149-298
1153 pb[recent] = first_percent_b (long_time_format[recent]);
executed 298 times by 2 tests: pb[recent] = first_percent_b (long_time_format[recent]);
Executed by:
  • ls
  • vdir
298
1154 if (! (pb[0] || pb[1]))
pb[0]Description
TRUEevaluated 138 times by 2 tests
Evaluated by:
  • ls
  • vdir
FALSEevaluated 11 times by 1 test
Evaluated by:
  • ls
pb[1]Description
TRUEnever evaluated
FALSEevaluated 11 times by 1 test
Evaluated by:
  • ls
0-138
1155 return;
executed 11 times by 1 test: return;
Executed by:
  • ls
11
1156-
1157 char abmon[12][ABFORMAT_SIZE];-
1158 if (! abmon_init (abmon))
! abmon_init (abmon)Description
TRUEnever evaluated
FALSEevaluated 138 times by 2 tests
Evaluated by:
  • ls
  • vdir
0-138
1159 return;
never executed: return;
0
1160-
1161 for (int recent = 0; recent < 2; recent++)
recent < 2Description
TRUEevaluated 276 times by 2 tests
Evaluated by:
  • ls
  • vdir
FALSEevaluated 138 times by 2 tests
Evaluated by:
  • ls
  • vdir
138-276
1162 {-
1163 char const *fmt = long_time_format[recent];-
1164 for (int i = 0; i < 12; i++)
i < 12Description
TRUEevaluated 3312 times by 2 tests
Evaluated by:
  • ls
  • vdir
FALSEevaluated 276 times by 2 tests
Evaluated by:
  • ls
  • vdir
276-3312
1165 {-
1166 char *nfmt = abformat[recent][i];-
1167 int nbytes;-
1168-
1169 if (! pb[recent])
! pb[recent]Description
TRUEnever evaluated
FALSEevaluated 3312 times by 2 tests
Evaluated by:
  • ls
  • vdir
0-3312
1170 nbytes = snprintf (nfmt, ABFORMAT_SIZE, "%s", fmt);
never executed: nbytes = snprintf (nfmt, ABFORMAT_SIZE, "%s", fmt);
0
1171 else-
1172 {-
1173 if (! (pb[recent] - fmt <= MIN (ABFORMAT_SIZE, INT_MAX)))
! (pb[recent] ...0x7fffffff)) )Description
TRUEnever evaluated
FALSEevaluated 3312 times by 2 tests
Evaluated by:
  • ls
  • vdir
(( ABFORMAT_SI...<(0x7fffffff))Description
TRUEevaluated 3312 times by 2 tests
Evaluated by:
  • ls
  • vdir
FALSEnever evaluated
0-3312
1174 return;
never executed: return;
0
1175 int prefix_len = pb[recent] - fmt;-
1176 nbytes = snprintf (nfmt, ABFORMAT_SIZE, "%.*s%s%s",-
1177 prefix_len, fmt, abmon[i], pb[recent] + 2);-
1178 }
executed 3312 times by 2 tests: end of block
Executed by:
  • ls
  • vdir
3312
1179-
1180 if (! (0 <= nbytes && nbytes < ABFORMAT_SIZE))
0 <= nbytesDescription
TRUEevaluated 3312 times by 2 tests
Evaluated by:
  • ls
  • vdir
FALSEnever evaluated
nbytes < ABFORMAT_SIZEDescription
TRUEevaluated 3312 times by 2 tests
Evaluated by:
  • ls
  • vdir
FALSEnever evaluated
0-3312
1181 return;
never executed: return;
0
1182 }
executed 3312 times by 2 tests: end of block
Executed by:
  • ls
  • vdir
3312
1183 }
executed 276 times by 2 tests: end of block
Executed by:
  • ls
  • vdir
276
1184-
1185 use_abformat = true;-
1186}
executed 138 times by 2 tests: end of block
Executed by:
  • ls
  • vdir
138
1187-
1188static size_t-
1189dev_ino_hash (void const *x, size_t table_size)-
1190{-
1191 struct dev_ino const *p = x;-
1192 return (uintmax_t) p->st_ino % table_size;
executed 20 times by 1 test: return (uintmax_t) p->st_ino % table_size;
Executed by:
  • ls
20
1193}-
1194-
1195static bool-
1196dev_ino_compare (void const *x, void const *y)-
1197{-
1198 struct dev_ino const *a = x;-
1199 struct dev_ino const *b = y;-
1200 return SAME_INODE (*a, *b) ? true : false;
executed 10 times by 1 test: return ((*a).st_ino == (*b).st_ino && (*a).st_dev == (*b).st_dev) ? 1 : 0 ;
Executed by:
  • ls
10
1201}-
1202-
1203static void-
1204dev_ino_free (void *x)-
1205{-
1206 free (x);-
1207}
executed 10 times by 1 test: end of block
Executed by:
  • ls
10
1208-
1209/* Add the device/inode pair (P->st_dev/P->st_ino) to the set of-
1210 active directories. Return true if there is already a matching-
1211 entry in the table. */-
1212-
1213static bool-
1214visit_dir (dev_t dev, ino_t ino)-
1215{-
1216 struct dev_ino *ent;-
1217 struct dev_ino *ent_from_table;-
1218 bool found_match;-
1219-
1220 ent = xmalloc (sizeof *ent);-
1221 ent->st_ino = ino;-
1222 ent->st_dev = dev;-
1223-
1224 /* Attempt to insert this entry into the table. */-
1225 ent_from_table = hash_insert (active_dir_set, ent);-
1226-
1227 if (ent_from_table == NULL)
ent_from_table == ((void *)0)Description
TRUEnever evaluated
FALSEevaluated 10 times by 1 test
Evaluated by:
  • ls
0-10
1228 {-
1229 /* Insertion failed due to lack of memory. */-
1230 xalloc_die ();-
1231 }
never executed: end of block
0
1232-
1233 found_match = (ent_from_table != ent);-
1234-
1235 if (found_match)
found_matchDescription
TRUEnever evaluated
FALSEevaluated 10 times by 1 test
Evaluated by:
  • ls
0-10
1236 {-
1237 /* ent was not inserted, so free it. */-
1238 free (ent);-
1239 }
never executed: end of block
0
1240-
1241 return found_match;
executed 10 times by 1 test: return found_match;
Executed by:
  • ls
10
1242}-
1243-
1244static void-
1245free_pending_ent (struct pending *p)-
1246{-
1247 free (p->name);-
1248 free (p->realname);-
1249 free (p);-
1250}
executed 51 times by 3 tests: end of block
Executed by:
  • dir
  • ls
  • vdir
51
1251-
1252static bool-
1253is_colored (enum indicator_no type)-
1254{-
1255 size_t len = color_indicator[type].len;-
1256 char const *s = color_indicator[type].string;-
1257 return ! (len == 0
executed 178 times by 1 test: return ! (len == 0 || (len == 1 && (__extension__ (__builtin_constant_p ( sizeof ("0") - 1 ) && ((__builtin_constant_p ( s ) && strlen ( s ) < ((size_t) ( sizeof ("0") - 1 ))) || (__builtin_constant_p ( "" "0" "" ) && strlen ( "" "0" "" ) < ((size_t) ( si...2] - __s2[2]); if (__s2_len > 2 && __result == 0) __result = (((const unsigned char *) (const char *) ( "" "00" "" ))[3] - __s2[3]); } } __result; }))) : __builtin_strcmp ( s , "" "00" "" )))); }) : strncmp ( s , "" "00" "" , sizeof ("00") - 1 ))) == 0));
Executed by:
  • ls
178
1258 || (len == 1 && STRNCMP_LIT (s, "0") == 0)
executed 178 times by 1 test: return ! (len == 0 || (len == 1 && (__extension__ (__builtin_constant_p ( sizeof ("0") - 1 ) && ((__builtin_constant_p ( s ) && strlen ( s ) < ((size_t) ( sizeof ("0") - 1 ))) || (__builtin_constant_p ( "" "0" "" ) && strlen ( "" "0" "" ) < ((size_t) ( si...2] - __s2[2]); if (__s2_len > 2 && __result == 0) __result = (((const unsigned char *) (const char *) ( "" "00" "" ))[3] - __s2[3]); } } __result; }))) : __builtin_strcmp ( s , "" "00" "" )))); }) : strncmp ( s , "" "00" "" , sizeof ("00") - 1 ))) == 0));
Executed by:
  • ls
never executed: __result = (((const unsigned char *) (const char *) ( s ))[3] - __s2[3]);
never executed: end of block
never executed: end of block
never executed: __result = (((const unsigned char *) (const char *) ( "" "0" "" ))[3] - __s2[3]);
never executed: end of block
never executed: end of block
__s1_len > 0Description
TRUEnever evaluated
FALSEnever evaluated
__result == 0Description
TRUEnever evaluated
FALSEnever evaluated
__s1_len > 1Description
TRUEnever evaluated
FALSEnever evaluated
__result == 0Description
TRUEnever evaluated
FALSEnever evaluated
__s1_len > 2Description
TRUEnever evaluated
FALSEnever evaluated
__result == 0Description
TRUEnever evaluated
FALSEnever evaluated
__s2_len > 0Description
TRUEnever evaluated
FALSEnever evaluated
__result == 0Description
TRUEnever evaluated
FALSEnever evaluated
__s2_len > 1Description
TRUEnever evaluated
FALSEnever evaluated
__result == 0Description
TRUEnever evaluated
FALSEnever evaluated
__s2_len > 2Description
TRUEnever evaluated
FALSEnever evaluated
__result == 0Description
TRUEnever evaluated
FALSEnever evaluated
0-178
1259 || (len == 2 && STRNCMP_LIT (s, "00") == 0));
executed 178 times by 1 test: return ! (len == 0 || (len == 1 && (__extension__ (__builtin_constant_p ( sizeof ("0") - 1 ) && ((__builtin_constant_p ( s ) && strlen ( s ) < ((size_t) ( sizeof ("0") - 1 ))) || (__builtin_constant_p ( "" "0" "" ) && strlen ( "" "0" "" ) < ((size_t) ( si...2] - __s2[2]); if (__s2_len > 2 && __result == 0) __result = (((const unsigned char *) (const char *) ( "" "00" "" ))[3] - __s2[3]); } } __result; }))) : __builtin_strcmp ( s , "" "00" "" )))); }) : strncmp ( s , "" "00" "" , sizeof ("00") - 1 ))) == 0));
Executed by:
  • ls
never executed: __result = (((const unsigned char *) (const char *) ( s ))[3] - __s2[3]);
never executed: end of block
never executed: end of block
never executed: __result = (((const unsigned char *) (const char *) ( "" "00" "" ))[3] - __s2[3]);
never executed: end of block
never executed: end of block
__s1_len > 0Description
TRUEnever evaluated
FALSEnever evaluated
__result == 0Description
TRUEnever evaluated
FALSEnever evaluated
__s1_len > 1Description
TRUEnever evaluated
FALSEnever evaluated
__result == 0Description
TRUEnever evaluated
FALSEnever evaluated
__s1_len > 2Description
TRUEnever evaluated
FALSEnever evaluated
__result == 0Description
TRUEnever evaluated
FALSEnever evaluated
__s2_len > 0Description
TRUEnever evaluated
FALSEnever evaluated
__result == 0Description
TRUEnever evaluated
FALSEnever evaluated
__s2_len > 1Description
TRUEnever evaluated
FALSEnever evaluated
__result == 0Description
TRUEnever evaluated
FALSEnever evaluated
__s2_len > 2Description
TRUEnever evaluated
FALSEnever evaluated
__result == 0Description
TRUEnever evaluated
FALSEnever evaluated
0-178
1260}-
1261-
1262static void-
1263restore_default_color (void)-
1264{-
1265 put_indicator (&color_indicator[C_LEFT]);-
1266 put_indicator (&color_indicator[C_RIGHT]);-
1267}
never executed: end of block
0
1268-
1269static void-
1270set_normal_color (void)-
1271{-
1272 if (print_with_color && is_colored (C_NORM))
print_with_colorDescription
TRUEevaluated 36 times by 1 test
Evaluated by:
  • ls
FALSEevaluated 1091 times by 3 tests
Evaluated by:
  • dir
  • ls
  • vdir
is_colored (C_NORM)Description
TRUEnever evaluated
FALSEevaluated 36 times by 1 test
Evaluated by:
  • ls
0-1091
1273 {-
1274 put_indicator (&color_indicator[C_LEFT]);-
1275 put_indicator (&color_indicator[C_NORM]);-
1276 put_indicator (&color_indicator[C_RIGHT]);-
1277 }
never executed: end of block
0
1278}
executed 1127 times by 3 tests: end of block
Executed by:
  • dir
  • ls
  • vdir
1127
1279-
1280/* An ordinary signal was received; arrange for the program to exit. */-
1281-
1282static void-
1283sighandler (int sig)-
1284{-
1285 if (! SA_NOCLDSTOP)
! 1Description
TRUEnever evaluated
FALSEnever evaluated
dead code: signal (sig, ((__sighandler_t) 1) );
-
1286 signal (sig, SIG_IGN);
dead code: signal (sig, ((__sighandler_t) 1) );
-
1287 if (! interrupt_signal)
! interrupt_signalDescription
TRUEnever evaluated
FALSEnever evaluated
0
1288 interrupt_signal = sig;
never executed: interrupt_signal = sig;
0
1289}
never executed: end of block
0
1290-
1291/* A SIGTSTP was received; arrange for the program to suspend itself. */-
1292-
1293static void-
1294stophandler (int sig)-
1295{-
1296 if (! SA_NOCLDSTOP)
! 1Description
TRUEnever evaluated
FALSEnever evaluated
dead code: signal (sig, stophandler);
-
1297 signal (sig, stophandler);
dead code: signal (sig, stophandler);
-
1298 if (! interrupt_signal)
! interrupt_signalDescription
TRUEnever evaluated
FALSEnever evaluated
0
1299 stop_signal_count++;
never executed: stop_signal_count++;
0
1300}
never executed: end of block
0
1301-
1302/* Process any pending signals. If signals are caught, this function-
1303 should be called periodically. Ideally there should never be an-
1304 unbounded amount of time when signals are not being processed.-
1305 Signal handling can restore the default colors, so callers must-
1306 immediately change colors after invoking this function. */-
1307-
1308static void-
1309process_signals (void)-
1310{-
1311 while (interrupt_signal || stop_signal_count)
interrupt_signalDescription
TRUEnever evaluated
FALSEevaluated 1492 times by 3 tests
Evaluated by:
  • dir
  • ls
  • vdir
stop_signal_countDescription
TRUEnever evaluated
FALSEevaluated 1492 times by 3 tests
Evaluated by:
  • dir
  • ls
  • vdir
0-1492
1312 {-
1313 int sig;-
1314 int stops;-
1315 sigset_t oldset;-
1316-
1317 if (used_color)
used_colorDescription
TRUEnever evaluated
FALSEnever evaluated
0
1318 restore_default_color ();
never executed: restore_default_color ();
0
1319 fflush (stdout);-
1320-
1321 sigprocmask (SIG_BLOCK, &caught_signals, &oldset);-
1322-
1323 /* Reload interrupt_signal and stop_signal_count, in case a new-
1324 signal was handled before sigprocmask took effect. */-
1325 sig = interrupt_signal;-
1326 stops = stop_signal_count;-
1327-
1328 /* SIGTSTP is special, since the application can receive that signal-
1329 more than once. In this case, don't set the signal handler to the-
1330 default. Instead, just raise the uncatchable SIGSTOP. */-
1331 if (stops)
stopsDescription
TRUEnever evaluated
FALSEnever evaluated
0
1332 {-
1333 stop_signal_count = stops - 1;-
1334 sig = SIGSTOP;-
1335 }
never executed: end of block
0
1336 else-
1337 signal (sig, SIG_DFL);
never executed: signal (sig, ((__sighandler_t) 0) );
0
1338-
1339 /* Exit or suspend the program. */-
1340 raise (sig);-
1341 sigprocmask (SIG_SETMASK, &oldset, NULL);-
1342-
1343 /* If execution reaches here, then the program has been-
1344 continued (after being suspended). */-
1345 }
never executed: end of block
0
1346}
executed 1492 times by 3 tests: end of block
Executed by:
  • dir
  • ls
  • vdir
1492
1347-
1348/* Setup signal handlers if INIT is true,-
1349 otherwise restore to the default. */-
1350-
1351static void-
1352signal_setup (bool init)-
1353{-
1354 /* The signals that are trapped, and the number of such signals. */-
1355 static int const sig[] =-
1356 {-
1357 /* This one is handled specially. */-
1358 SIGTSTP,-
1359-
1360 /* The usual suspects. */-
1361 SIGALRM, SIGHUP, SIGINT, SIGPIPE, SIGQUIT, SIGTERM,-
1362#ifdef SIGPOLL-
1363 SIGPOLL,-
1364#endif-
1365#ifdef SIGPROF-
1366 SIGPROF,-
1367#endif-
1368#ifdef SIGVTALRM-
1369 SIGVTALRM,-
1370#endif-
1371#ifdef SIGXCPU-
1372 SIGXCPU,-
1373#endif-
1374#ifdef SIGXFSZ-
1375 SIGXFSZ,-
1376#endif-
1377 };-
1378 enum { nsigs = ARRAY_CARDINALITY (sig) };-
1379-
1380#if ! SA_NOCLDSTOP-
1381 static bool caught_sig[nsigs];-
1382#endif-
1383-
1384 int j;-
1385-
1386 if (init)
initDescription
TRUEnever evaluated
FALSEevaluated 24 times by 1 test
Evaluated by:
  • ls
0-24
1387 {-
1388#if SA_NOCLDSTOP-
1389 struct sigaction act;-
1390-
1391 sigemptyset (&caught_signals);-
1392 for (j = 0; j < nsigs; j++)
j < nsigsDescription
TRUEnever evaluated
FALSEnever evaluated
0
1393 {-
1394 sigaction (sig[j], NULL, &act);-
1395 if (act.sa_handler != SIG_IGN)
act. __sigacti...ghandler_t) 1)Description
TRUEnever evaluated
FALSEnever evaluated
0
1396 sigaddset (&caught_signals, sig[j]);
never executed: sigaddset (&caught_signals, sig[j]);
0
1397 }
never executed: end of block
0
1398-
1399 act.sa_mask = caught_signals;-
1400 act.sa_flags = SA_RESTART;-
1401-
1402 for (j = 0; j < nsigs; j++)
j < nsigsDescription
TRUEnever evaluated
FALSEnever evaluated
0
1403 if (sigismember (&caught_signals, sig[j]))
sigismember (&...gnals, sig[j])Description
TRUEnever evaluated
FALSEnever evaluated
0
1404 {-
1405 act.sa_handler = sig[j] == SIGTSTP ? stophandler : sighandler;
sig[j] == 20Description
TRUEnever evaluated
FALSEnever evaluated
0
1406 sigaction (sig[j], &act, NULL);-
1407 }
never executed: end of block
0
1408#else-
1409 for (j = 0; j < nsigs; j++)-
1410 {-
1411 caught_sig[j] = (signal (sig[j], SIG_IGN) != SIG_IGN);-
1412 if (caught_sig[j])-
1413 {-
1414 signal (sig[j], sig[j] == SIGTSTP ? stophandler : sighandler);-
1415 siginterrupt (sig[j], 0);-
1416 }-
1417 }-
1418#endif-
1419 }
never executed: end of block
0
1420 else /* restore. */-
1421 {-
1422#if SA_NOCLDSTOP-
1423 for (j = 0; j < nsigs; j++)
j < nsigsDescription
TRUEevaluated 288 times by 1 test
Evaluated by:
  • ls
FALSEevaluated 24 times by 1 test
Evaluated by:
  • ls
24-288
1424 if (sigismember (&caught_signals, sig[j]))
sigismember (&...gnals, sig[j])Description
TRUEnever evaluated
FALSEevaluated 288 times by 1 test
Evaluated by:
  • ls
0-288
1425 signal (sig[j], SIG_DFL);
never executed: signal (sig[j], ((__sighandler_t) 0) );
0
1426#else-
1427 for (j = 0; j < nsigs; j++)-
1428 if (caught_sig[j])-
1429 signal (sig[j], SIG_DFL);-
1430#endif-
1431 }
executed 24 times by 1 test: end of block
Executed by:
  • ls
24
1432}-
1433-
1434static inline void-
1435signal_init (void)-
1436{-
1437 signal_setup (true);-
1438}
never executed: end of block
0
1439-
1440static inline void-
1441signal_restore (void)-
1442{-
1443 signal_setup (false);-
1444}
executed 24 times by 1 test: end of block
Executed by:
  • ls
24
1445-
1446int-
1447main (int argc, char **argv)-
1448{-
1449 int i;-
1450 struct pending *thispend;-
1451 int n_files;-
1452-
1453 initialize_main (&argc, &argv);-
1454 set_program_name (argv[0]);-
1455 setlocale (LC_ALL, "");-
1456 bindtextdomain (PACKAGE, LOCALEDIR);-
1457 textdomain (PACKAGE);-
1458-
1459 initialize_exit_failure (LS_FAILURE);-
1460 atexit (close_stdout);-
1461-
1462 assert (ARRAY_CARDINALITY (color_indicator) + 1-
1463 == ARRAY_CARDINALITY (indicator_name));-
1464-
1465 exit_status = EXIT_SUCCESS;-
1466 print_dir_name = true;-
1467 pending_dirs = NULL;-
1468-
1469 current_time.tv_sec = TYPE_MINIMUM (time_t);-
1470 current_time.tv_nsec = -1;-
1471-
1472 i = decode_switches (argc, argv);-
1473-
1474 if (print_with_color)
print_with_colorDescription
TRUEevaluated 32 times by 1 test
Evaluated by:
  • ls
FALSEevaluated 1134 times by 3 tests
Evaluated by:
  • dir
  • ls
  • vdir
32-1134
1475 parse_ls_color ();
executed 32 times by 1 test: parse_ls_color ();
Executed by:
  • ls
32
1476-
1477 /* Test print_with_color again, because the call to parse_ls_color-
1478 may have just reset it -- e.g., if LS_COLORS is invalid. */-
1479 if (print_with_color)
print_with_colorDescription
TRUEevaluated 28 times by 1 test
Evaluated by:
  • ls
FALSEevaluated 1138 times by 3 tests
Evaluated by:
  • dir
  • ls
  • vdir
28-1138
1480 {-
1481 /* Avoid following symbolic links when possible. */-
1482 if (is_colored (C_ORPHAN)
is_colored (C_ORPHAN)Description
TRUEevaluated 10 times by 1 test
Evaluated by:
  • ls
FALSEevaluated 18 times by 1 test
Evaluated by:
  • ls
10-18
1483 || (is_colored (C_EXEC) && color_symlink_as_referent)
is_colored (C_EXEC)Description
TRUEevaluated 16 times by 1 test
Evaluated by:
  • ls
FALSEevaluated 2 times by 1 test
Evaluated by:
  • ls
color_symlink_as_referentDescription
TRUEevaluated 6 times by 1 test
Evaluated by:
  • ls
FALSEevaluated 10 times by 1 test
Evaluated by:
  • ls
2-16
1484 || (is_colored (C_MISSING) && format == long_format))
is_colored (C_MISSING)Description
TRUEevaluated 2 times by 1 test
Evaluated by:
  • ls
FALSEevaluated 10 times by 1 test
Evaluated by:
  • ls
format == long_formatDescription
TRUEevaluated 2 times by 1 test
Evaluated by:
  • ls
FALSEnever evaluated
0-10
1485 check_symlink_color = true;
executed 18 times by 1 test: check_symlink_color = 1 ;
Executed by:
  • ls
18
1486 }
executed 28 times by 1 test: end of block
Executed by:
  • ls
28
1487-
1488 if (dereference == DEREF_UNDEFINED)
dereference == DEREF_UNDEFINEDDescription
TRUEevaluated 1160 times by 3 tests
Evaluated by:
  • dir
  • ls
  • vdir
FALSEevaluated 6 times by 1 test
Evaluated by:
  • ls
6-1160
1489 dereference = ((immediate_dirs
executed 1160 times by 3 tests: dereference = ((immediate_dirs || indicator_style == classify || format == long_format) ? DEREF_NEVER : DEREF_COMMAND_LINE_SYMLINK_TO_DIR);
Executed by:
  • dir
  • ls
  • vdir
immediate_dirsDescription
TRUEevaluated 1038 times by 1 test
Evaluated by:
  • ls
FALSEevaluated 122 times by 3 tests
Evaluated by:
  • dir
  • ls
  • vdir
122-1160
1490 || indicator_style == classify
executed 1160 times by 3 tests: dereference = ((immediate_dirs || indicator_style == classify || format == long_format) ? DEREF_NEVER : DEREF_COMMAND_LINE_SYMLINK_TO_DIR);
Executed by:
  • dir
  • ls
  • vdir
indicator_style == classifyDescription
TRUEevaluated 4 times by 1 test
Evaluated by:
  • ls
FALSEevaluated 118 times by 3 tests
Evaluated by:
  • dir
  • ls
  • vdir
4-1160
1491 || format == long_format)
executed 1160 times by 3 tests: dereference = ((immediate_dirs || indicator_style == classify || format == long_format) ? DEREF_NEVER : DEREF_COMMAND_LINE_SYMLINK_TO_DIR);
Executed by:
  • dir
  • ls
  • vdir
format == long_formatDescription
TRUEevaluated 29 times by 2 tests
Evaluated by:
  • ls
  • vdir
FALSEevaluated 89 times by 2 tests
Evaluated by:
  • dir
  • ls
29-1160
1492 ? DEREF_NEVER
executed 1160 times by 3 tests: dereference = ((immediate_dirs || indicator_style == classify || format == long_format) ? DEREF_NEVER : DEREF_COMMAND_LINE_SYMLINK_TO_DIR);
Executed by:
  • dir
  • ls
  • vdir
1160
1493 : DEREF_COMMAND_LINE_SYMLINK_TO_DIR);
executed 1160 times by 3 tests: dereference = ((immediate_dirs || indicator_style == classify || format == long_format) ? DEREF_NEVER : DEREF_COMMAND_LINE_SYMLINK_TO_DIR);
Executed by:
  • dir
  • ls
  • vdir
1160
1494-
1495 /* When using -R, initialize a data structure we'll use to-
1496 detect any directory cycles. */-
1497 if (recursive)
recursiveDescription
TRUEevaluated 6 times by 1 test
Evaluated by:
  • ls
FALSEevaluated 1160 times by 3 tests
Evaluated by:
  • dir
  • ls
  • vdir
6-1160
1498 {-
1499 active_dir_set = hash_initialize (INITIAL_TABLE_SIZE, NULL,-
1500 dev_ino_hash,-
1501 dev_ino_compare,-
1502 dev_ino_free);-
1503 if (active_dir_set == NULL)
active_dir_set == ((void *)0)Description
TRUEnever evaluated
FALSEevaluated 6 times by 1 test
Evaluated by:
  • ls
0-6
1504 xalloc_die ();
never executed: xalloc_die ();
0
1505-
1506 obstack_init (&dev_ino_obstack);-
1507 }
executed 6 times by 1 test: end of block
Executed by:
  • ls
6
1508-
1509 localtz = tzalloc (getenv ("TZ"));-
1510-
1511 format_needs_stat = sort_type == sort_time || sort_type == sort_size
sort_type == sort_timeDescription
TRUEevaluated 8 times by 1 test
Evaluated by:
  • ls
FALSEevaluated 1158 times by 3 tests
Evaluated by:
  • dir
  • ls
  • vdir
sort_type == sort_sizeDescription
TRUEnever evaluated
FALSEevaluated 1158 times by 3 tests
Evaluated by:
  • dir
  • ls
  • vdir
0-1158
1512 || format == long_format
format == long_formatDescription
TRUEevaluated 149 times by 2 tests
Evaluated by:
  • ls
  • vdir
FALSEevaluated 1009 times by 2 tests
Evaluated by:
  • dir
  • ls
149-1009
1513 || print_scontext
print_scontextDescription
TRUEnever evaluated
FALSEevaluated 1009 times by 2 tests
Evaluated by:
  • dir
  • ls
0-1009
1514 || print_block_size;
print_block_sizeDescription
TRUEnever evaluated
FALSEevaluated 1009 times by 2 tests
Evaluated by:
  • dir
  • ls
0-1009
1515 format_needs_type = (! format_needs_stat
! format_needs_statDescription
TRUEevaluated 1009 times by 2 tests
Evaluated by:
  • dir
  • ls
FALSEevaluated 157 times by 2 tests
Evaluated by:
  • ls
  • vdir
157-1009
1516 && (recursive
recursiveDescription
TRUEevaluated 6 times by 1 test
Evaluated by:
  • ls
FALSEevaluated 1003 times by 2 tests
Evaluated by:
  • dir
  • ls
6-1003
1517 || print_with_color
print_with_colorDescription
TRUEevaluated 20 times by 1 test
Evaluated by:
  • ls
FALSEevaluated 983 times by 2 tests
Evaluated by:
  • dir
  • ls
20-983
1518 || indicator_style != none
indicator_style != noneDescription
TRUEevaluated 10 times by 1 test
Evaluated by:
  • ls
FALSEevaluated 973 times by 2 tests
Evaluated by:
  • dir
  • ls
10-973
1519 || directories_first));
directories_firstDescription
TRUEnever evaluated
FALSEevaluated 973 times by 2 tests
Evaluated by:
  • dir
  • ls
0-973
1520-
1521 if (dired)
diredDescription
TRUEnever evaluated
FALSEevaluated 1166 times by 3 tests
Evaluated by:
  • dir
  • ls
  • vdir
0-1166
1522 {-
1523 obstack_init (&dired_obstack);-
1524 obstack_init (&subdired_obstack);-
1525 }
never executed: end of block
0
1526-
1527 if (print_hyperlink)
print_hyperlinkDescription
TRUEnever evaluated
FALSEevaluated 1166 times by 3 tests
Evaluated by:
  • dir
  • ls
  • vdir
0-1166
1528 {-
1529 file_escape_init ();-
1530-
1531 hostname = xgethostname ();-
1532 /* The hostname is generally ignored,-
1533 so ignore failures obtaining it. */-
1534 if (! hostname)
! hostnameDescription
TRUEnever evaluated
FALSEnever evaluated
0
1535 hostname = "";
never executed: hostname = "";
0
1536 }
never executed: end of block
0
1537-
1538 cwd_n_alloc = 100;-
1539 cwd_file = xnmalloc (cwd_n_alloc, sizeof *cwd_file);-
1540 cwd_n_used = 0;-
1541-
1542 clear_files ();-
1543-
1544 n_files = argc - i;-
1545-
1546 if (n_files <= 0)
n_files <= 0Description
TRUEevaluated 3 times by 3 tests
Evaluated by:
  • dir
  • ls
  • vdir
FALSEevaluated 1163 times by 1 test
Evaluated by:
  • ls
3-1163
1547 {-
1548 if (immediate_dirs)
immediate_dirsDescription
TRUEnever evaluated
FALSEevaluated 3 times by 3 tests
Evaluated by:
  • dir
  • ls
  • vdir
0-3
1549 gobble_file (".", directory, NOT_AN_INODE_NUMBER, true, "");
never executed: gobble_file (".", directory, NOT_AN_INODE_NUMBER, 1 , "");
0
1550 else-
1551 queue_directory (".", NULL, true);
executed 3 times by 3 tests: queue_directory (".", ((void *)0) , 1 );
Executed by:
  • dir
  • ls
  • vdir
3
1552 }-
1553 else-
1554 do-
1555 gobble_file (argv[i++], unknown, NOT_AN_INODE_NUMBER, true, "");
executed 1225 times by 1 test: gobble_file (argv[i++], unknown, NOT_AN_INODE_NUMBER, 1 , "");
Executed by:
  • ls
1225
1556 while (i < argc);
i < argcDescription
TRUEevaluated 62 times by 1 test
Evaluated by:
  • ls
FALSEevaluated 1163 times by 1 test
Evaluated by:
  • ls
62-1163
1557-
1558 if (cwd_n_used)
cwd_n_usedDescription
TRUEevaluated 1047 times by 1 test
Evaluated by:
  • ls
FALSEevaluated 119 times by 3 tests
Evaluated by:
  • dir
  • ls
  • vdir
119-1047
1559 {-
1560 sort_files ();-
1561 if (!immediate_dirs)
!immediate_dirsDescription
TRUEevaluated 119 times by 1 test
Evaluated by:
  • ls
FALSEevaluated 928 times by 1 test
Evaluated by:
  • ls
119-928
1562 extract_dirs_from_files (NULL, true);
executed 119 times by 1 test: extract_dirs_from_files ( ((void *)0) , 1 );
Executed by:
  • ls
119
1563 /* 'cwd_n_used' might be zero now. */-
1564 }
executed 1047 times by 1 test: end of block
Executed by:
  • ls
1047
1565-
1566 /* In the following if/else blocks, it is sufficient to test 'pending_dirs'-
1567 (and not pending_dirs->name) because there may be no markers in the queue-
1568 at this point. A marker may be enqueued when extract_dirs_from_files is-
1569 called with a non-empty string or via print_dir. */-
1570 if (cwd_n_used)
cwd_n_usedDescription
TRUEevaluated 1015 times by 1 test
Evaluated by:
  • ls
FALSEevaluated 151 times by 3 tests
Evaluated by:
  • dir
  • ls
  • vdir
151-1015
1571 {-
1572 print_current_files ();-
1573 if (pending_dirs)
pending_dirsDescription
TRUEnever evaluated
FALSEevaluated 1015 times by 1 test
Evaluated by:
  • ls
0-1015
1574 DIRED_PUTCHAR ('\n');
never executed: end of block
0
1575 }
executed 1015 times by 1 test: end of block
Executed by:
  • ls
1015
1576 else if (n_files <= 1 && pending_dirs && pending_dirs->next == 0)
n_files <= 1Description
TRUEevaluated 145 times by 3 tests
Evaluated by:
  • dir
  • ls
  • vdir
FALSEevaluated 6 times by 1 test
Evaluated by:
  • ls
pending_dirsDescription
TRUEevaluated 29 times by 3 tests
Evaluated by:
  • dir
  • ls
  • vdir
FALSEevaluated 116 times by 1 test
Evaluated by:
  • ls
pending_dirs->next == 0Description
TRUEevaluated 29 times by 3 tests
Evaluated by:
  • dir
  • ls
  • vdir
FALSEnever evaluated
0-145
1577 print_dir_name = false;
executed 29 times by 3 tests: print_dir_name = 0 ;
Executed by:
  • dir
  • ls
  • vdir
29
1578-
1579 while (pending_dirs)
pending_dirsDescription
TRUEevaluated 51 times by 3 tests
Evaluated by:
  • dir
  • ls
  • vdir
FALSEevaluated 1166 times by 3 tests
Evaluated by:
  • dir
  • ls
  • vdir
51-1166
1580 {-
1581 thispend = pending_dirs;-
1582 pending_dirs = pending_dirs->next;-
1583-
1584 if (LOOP_DETECT)
(!!active_dir_set)Description
TRUEevaluated 20 times by 1 test
Evaluated by:
  • ls
FALSEevaluated 31 times by 3 tests
Evaluated by:
  • dir
  • ls
  • vdir
20-31
1585 {-
1586 if (thispend->name == NULL)
thispend->name == ((void *)0)Description
TRUEevaluated 10 times by 1 test
Evaluated by:
  • ls
FALSEevaluated 10 times by 1 test
Evaluated by:
  • ls
10
1587 {-
1588 /* thispend->name == NULL means this is a marker entry-
1589 indicating we've finished processing the directory.-
1590 Use its dev/ino numbers to remove the corresponding-
1591 entry from the active_dir_set hash table. */-
1592 struct dev_ino di = dev_ino_pop ();-
1593 struct dev_ino *found = hash_delete (active_dir_set, &di);-
1594 /* ASSERT_MATCHING_DEV_INO (thispend->realname, di); */-
1595 assert (found);-
1596 dev_ino_free (found);-
1597 free_pending_ent (thispend);-
1598 continue;
executed 10 times by 1 test: continue;
Executed by:
  • ls
10
1599 }-
1600 }
executed 10 times by 1 test: end of block
Executed by:
  • ls
10
1601-
1602 print_dir (thispend->name, thispend->realname,-
1603 thispend->command_line_arg);-
1604-
1605 free_pending_ent (thispend);-
1606 print_dir_name = true;-
1607 }
executed 41 times by 3 tests: end of block
Executed by:
  • dir
  • ls
  • vdir
41
1608-
1609 if (print_with_color && used_color)
print_with_colorDescription
TRUEevaluated 28 times by 1 test
Evaluated by:
  • ls
FALSEevaluated 1138 times by 3 tests
Evaluated by:
  • dir
  • ls
  • vdir
used_colorDescription
TRUEevaluated 24 times by 1 test
Evaluated by:
  • ls
FALSEevaluated 4 times by 1 test
Evaluated by:
  • ls
4-1138
1610 {-
1611 int j;-
1612-
1613 /* Skip the restore when it would be a no-op, i.e.,-
1614 when left is "\033[" and right is "m". */-
1615 if (!(color_indicator[C_LEFT].len == 2
color_indicato...LEFT].len == 2Description
TRUEevaluated 24 times by 1 test
Evaluated by:
  • ls
FALSEnever evaluated
0-24
1616 && memcmp (color_indicator[C_LEFT].string, "\033[", 2) == 0
memcmp (color_...033[", 2) == 0Description
TRUEevaluated 24 times by 1 test
Evaluated by:
  • ls
FALSEnever evaluated
0-24
1617 && color_indicator[C_RIGHT].len == 1
color_indicato...IGHT].len == 1Description
TRUEevaluated 24 times by 1 test
Evaluated by:
  • ls
FALSEnever evaluated
0-24
1618 && color_indicator[C_RIGHT].string[0] == 'm'))
color_indicato...ring[0] == 'm'Description
TRUEevaluated 24 times by 1 test
Evaluated by:
  • ls
FALSEnever evaluated
0-24
1619 restore_default_color ();
never executed: restore_default_color ();
0
1620-
1621 fflush (stdout);-
1622-
1623 signal_restore ();-
1624-
1625 /* Act on any signals that arrived before the default was restored.-
1626 This can process signals out of order, but there doesn't seem to-
1627 be an easy way to do them in order, and the order isn't that-
1628 important anyway. */-
1629 for (j = stop_signal_count; j; j--)
jDescription
TRUEnever evaluated
FALSEevaluated 24 times by 1 test
Evaluated by:
  • ls
0-24
1630 raise (SIGSTOP);
never executed: raise ( 19 );
0
1631 j = interrupt_signal;-
1632 if (j)
jDescription
TRUEnever evaluated
FALSEevaluated 24 times by 1 test
Evaluated by:
  • ls
0-24
1633 raise (j);
never executed: raise (j);
0
1634 }
executed 24 times by 1 test: end of block
Executed by:
  • ls
24
1635-
1636 if (dired)
diredDescription
TRUEnever evaluated
FALSEevaluated 1166 times by 3 tests
Evaluated by:
  • dir
  • ls
  • vdir
0-1166
1637 {-
1638 /* No need to free these since we're about to exit. */-
1639 dired_dump_obstack ("//DIRED//", &dired_obstack);-
1640 dired_dump_obstack ("//SUBDIRED//", &subdired_obstack);-
1641 printf ("//DIRED-OPTIONS// --quoting-style=%s\n",-
1642 quoting_style_args[get_quoting_style (filename_quoting_options)]);-
1643 }
never executed: end of block
0
1644-
1645 if (LOOP_DETECT)
(!!active_dir_set)Description
TRUEevaluated 6 times by 1 test
Evaluated by:
  • ls
FALSEevaluated 1160 times by 3 tests
Evaluated by:
  • dir
  • ls
  • vdir
6-1160
1646 {-
1647 assert (hash_get_n_entries (active_dir_set) == 0);-
1648 hash_free (active_dir_set);-
1649 }
executed 6 times by 1 test: end of block
Executed by:
  • ls
6
1650-
1651 return exit_status;
executed 1166 times by 3 tests: return exit_status;
Executed by:
  • dir
  • ls
  • vdir
1166
1652}-
1653-
1654/* Set the line length to the value given by SPEC. Return true if-
1655 successful. 0 means no limit on line length. */-
1656-
1657static bool-
1658set_line_length (char const *spec)-
1659{-
1660 uintmax_t val;-
1661-
1662 /* Treat too-large values as if they were SIZE_MAX, which is-
1663 effectively infinity. */-
1664 switch (xstrtoumax (spec, NULL, 0, &val, ""))-
1665 {-
1666 case LONGINT_OK:
never executed: case LONGINT_OK:
0
1667 line_length = MIN (val, SIZE_MAX);
(( val )<((184...709551615UL)))Description
TRUEnever evaluated
FALSEnever evaluated
0
1668 return true;
never executed: return 1 ;
0
1669-
1670 case LONGINT_OVERFLOW:
never executed: case LONGINT_OVERFLOW:
0
1671 line_length = SIZE_MAX;-
1672 return true;
never executed: return 1 ;
0
1673-
1674 default:
executed 4 times by 2 tests: default:
Executed by:
  • dir
  • vdir
4
1675 return false;
executed 4 times by 2 tests: return 0 ;
Executed by:
  • dir
  • vdir
4
1676 }-
1677}-
1678-
1679/* Set all the option flags according to the switches specified.-
1680 Return the index of the first non-option argument. */-
1681-
1682static int-
1683decode_switches (int argc, char **argv)-
1684{-
1685 char *time_style_option = NULL;-
1686-
1687 bool sort_type_specified = false;-
1688 bool kibibytes_specified = false;-
1689-
1690 qmark_funny_chars = false;-
1691-
1692 /* initialize all switches to default settings */-
1693-
1694 switch (ls_mode)-
1695 {-
1696 case LS_MULTI_COL:
executed 92 times by 1 test: case 2:
Executed by:
  • dir
92
1697 /* This is for the 'dir' program. */-
1698 format = many_per_line;-
1699 set_quoting_style (NULL, escape_quoting_style);-
1700 break;
executed 92 times by 1 test: break;
Executed by:
  • dir
92
1701-
1702 case LS_LONG_FORMAT:
executed 92 times by 1 test: case 3:
Executed by:
  • vdir
92
1703 /* This is for the 'vdir' program. */-
1704 format = long_format;-
1705 set_quoting_style (NULL, escape_quoting_style);-
1706 break;
executed 92 times by 1 test: break;
Executed by:
  • vdir
92
1707-
1708 case LS_LS:
executed 1175 times by 1 test: case 1:
Executed by:
  • ls
1175
1709 /* This is for the 'ls' program. */-
1710 if (isatty (STDOUT_FILENO))
isatty ( 1 )Description
TRUEnever evaluated
FALSEevaluated 1175 times by 1 test
Evaluated by:
  • ls
0-1175
1711 {-
1712 format = many_per_line;-
1713 set_quoting_style (NULL, shell_escape_quoting_style);-
1714 /* See description of qmark_funny_chars, above. */-
1715 qmark_funny_chars = true;-
1716 }
never executed: end of block
0
1717 else-
1718 {-
1719 format = one_per_line;-
1720 qmark_funny_chars = false;-
1721 }
executed 1175 times by 1 test: end of block
Executed by:
  • ls
1175
1722 break;
executed 1175 times by 1 test: break;
Executed by:
  • ls
1175
1723-
1724 default:
never executed: default:
0
1725 abort ();
never executed: abort ();
0
1726 }-
1727-
1728 time_type = time_mtime;-
1729 sort_type = sort_name;-
1730 sort_reverse = false;-
1731 numeric_ids = false;-
1732 print_block_size = false;-
1733 indicator_style = none;-
1734 print_inode = false;-
1735 dereference = DEREF_UNDEFINED;-
1736 recursive = false;-
1737 immediate_dirs = false;-
1738 ignore_mode = IGNORE_DEFAULT;-
1739 ignore_patterns = NULL;-
1740 hide_patterns = NULL;-
1741 print_scontext = false;-
1742-
1743 getenv_quoting_style ();-
1744-
1745 line_length = 80;-
1746 {-
1747 char const *p = getenv ("COLUMNS");-
1748 if (p && *p && ! set_line_length (p))
pDescription
TRUEnever evaluated
FALSEevaluated 1359 times by 3 tests
Evaluated by:
  • dir
  • ls
  • vdir
*pDescription
TRUEnever evaluated
FALSEnever evaluated
! set_line_length (p)Description
TRUEnever evaluated
FALSEnever evaluated
0-1359
1749 error (0, 0,
never executed: error (0, 0, dcgettext (((void *)0), "ignoring invalid width in environment variable COLUMNS: %s" , 5) , quote (p));
0
1750 _("ignoring invalid width in environment variable COLUMNS: %s"),
never executed: error (0, 0, dcgettext (((void *)0), "ignoring invalid width in environment variable COLUMNS: %s" , 5) , quote (p));
0
1751 quote (p));
never executed: error (0, 0, dcgettext (((void *)0), "ignoring invalid width in environment variable COLUMNS: %s" , 5) , quote (p));
0
1752 }-
1753-
1754#ifdef TIOCGWINSZ-
1755 {-
1756 struct winsize ws;-
1757-
1758 if (ioctl (STDOUT_FILENO, TIOCGWINSZ, &ws) != -1
ioctl ( 1 , 0x...3 , &ws) != -1Description
TRUEnever evaluated
FALSEevaluated 1359 times by 3 tests
Evaluated by:
  • dir
  • ls
  • vdir
0-1359
1759 && 0 < ws.ws_col && ws.ws_col == (size_t) ws.ws_col)
0 < ws.ws_colDescription
TRUEnever evaluated
FALSEnever evaluated
ws.ws_col == (...e_t) ws.ws_colDescription
TRUEnever evaluated
FALSEnever evaluated
0
1760 line_length = ws.ws_col;
never executed: line_length = ws.ws_col;
0
1761 }-
1762#endif-
1763-
1764 {-
1765 char const *p = getenv ("TABSIZE");-
1766 tabsize = 8;-
1767 if (p)
pDescription
TRUEnever evaluated
FALSEevaluated 1359 times by 3 tests
Evaluated by:
  • dir
  • ls
  • vdir
0-1359
1768 {-
1769 unsigned long int tmp_ulong;-
1770 if (xstrtoul (p, NULL, 0, &tmp_ulong, NULL) == LONGINT_OK
xstrtoul (p, (... == LONGINT_OKDescription
TRUEnever evaluated
FALSEnever evaluated
0
1771 && tmp_ulong <= SIZE_MAX)
tmp_ulong <= (...73709551615UL)Description
TRUEnever evaluated
FALSEnever evaluated
0
1772 {-
1773 tabsize = tmp_ulong;-
1774 }
never executed: end of block
0
1775 else-
1776 {-
1777 error (0, 0,-
1778 _("ignoring invalid tab size in environment variable TABSIZE: %s"),-
1779 quote (p));-
1780 }
never executed: end of block
0
1781 }-
1782 }-
1783-
1784 while (true)-
1785 {-
1786 int oi = -1;-
1787 int c = getopt_long (argc, argv,-
1788 "abcdfghiklmnopqrstuvw:xABCDFGHI:LNQRST:UXZ1",-
1789 long_options, &oi);-
1790 if (c == -1)
c == -1Description
TRUEevaluated 1166 times by 3 tests
Evaluated by:
  • dir
  • ls
  • vdir
FALSEevaluated 1809 times by 3 tests
Evaluated by:
  • dir
  • ls
  • vdir
1166-1809
1791 break;
executed 1166 times by 3 tests: break;
Executed by:
  • dir
  • ls
  • vdir
1166
1792-
1793 switch (c)-
1794 {-
1795 case 'a':
executed 4 times by 2 tests: case 'a':
Executed by:
  • dir
  • vdir
4
1796 ignore_mode = IGNORE_MINIMAL;-
1797 break;
executed 4 times by 2 tests: break;
Executed by:
  • dir
  • vdir
4
1798-
1799 case 'b':
executed 4 times by 2 tests: case 'b':
Executed by:
  • dir
  • vdir
4
1800 set_quoting_style (NULL, escape_quoting_style);-
1801 break;
executed 4 times by 2 tests: break;
Executed by:
  • dir
  • vdir
4
1802-
1803 case 'c':
executed 5 times by 3 tests: case 'c':
Executed by:
  • dir
  • ls
  • vdir
5
1804 time_type = time_ctime;-
1805 break;
executed 5 times by 3 tests: break;
Executed by:
  • dir
  • ls
  • vdir
5
1806-
1807 case 'd':
executed 1046 times by 3 tests: case 'd':
Executed by:
  • dir
  • ls
  • vdir
1046
1808 immediate_dirs = true;-
1809 break;
executed 1046 times by 3 tests: break;
Executed by:
  • dir
  • ls
  • vdir
1046
1810-
1811 case 'f':
executed 2 times by 2 tests: case 'f':
Executed by:
  • dir
  • vdir
2
1812 /* Same as enabling -a -U and disabling -l -s. */-
1813 ignore_mode = IGNORE_MINIMAL;-
1814 sort_type = sort_none;-
1815 sort_type_specified = true;-
1816 /* disable -l */-
1817 if (format == long_format)
format == long_formatDescription
TRUEevaluated 1 time by 1 test
Evaluated by:
  • vdir
FALSEevaluated 1 time by 1 test
Evaluated by:
  • dir
1
1818 format = (isatty (STDOUT_FILENO) ? many_per_line : one_per_line);
executed 1 time by 1 test: format = (isatty ( 1 ) ? many_per_line : one_per_line);
Executed by:
  • vdir
isatty ( 1 )Description
TRUEnever evaluated
FALSEevaluated 1 time by 1 test
Evaluated by:
  • vdir
0-1
1819 print_block_size = false; /* disable -s */-
1820 print_with_color = false; /* disable --color */-
1821 print_hyperlink = false; /* disable --hyperlink */-
1822 break;
executed 2 times by 2 tests: break;
Executed by:
  • dir
  • vdir
2
1823-
1824 case FILE_TYPE_INDICATOR_OPTION: /* --file-type */
executed 4 times by 3 tests: case FILE_TYPE_INDICATOR_OPTION:
Executed by:
  • dir
  • ls
  • vdir
4
1825 indicator_style = file_type;-
1826 break;
executed 4 times by 3 tests: break;
Executed by:
  • dir
  • ls
  • vdir
4
1827-
1828 case 'g':
executed 122 times by 3 tests: case 'g':
Executed by:
  • dir
  • ls
  • vdir
122
1829 format = long_format;-
1830 print_owner = false;-
1831 break;
executed 122 times by 3 tests: break;
Executed by:
  • dir
  • ls
  • vdir
122
1832-
1833 case 'h':
executed 4 times by 2 tests: case 'h':
Executed by:
  • dir
  • vdir
4
1834 file_human_output_opts = human_output_opts =-
1835 human_autoscale | human_SI | human_base_1024;-
1836 file_output_block_size = output_block_size = 1;-
1837 break;
executed 4 times by 2 tests: break;
Executed by:
  • dir
  • vdir
4
1838-
1839 case 'i':
executed 4 times by 2 tests: case 'i':
Executed by:
  • dir
  • vdir
4
1840 print_inode = true;-
1841 break;
executed 4 times by 2 tests: break;
Executed by:
  • dir
  • vdir
4
1842-
1843 case 'k':
executed 4 times by 2 tests: case 'k':
Executed by:
  • dir
  • vdir
4
1844 kibibytes_specified = true;-
1845 break;
executed 4 times by 2 tests: break;
Executed by:
  • dir
  • vdir
4
1846-
1847 case 'l':
executed 22 times by 3 tests: case 'l':
Executed by:
  • dir
  • ls
  • vdir
22
1848 format = long_format;-
1849 break;
executed 22 times by 3 tests: break;
Executed by:
  • dir
  • ls
  • vdir
22
1850-
1851 case 'm':
executed 2 times by 2 tests: case 'm':
Executed by:
  • dir
  • vdir
2
1852 format = with_commas;-
1853 break;
executed 2 times by 2 tests: break;
Executed by:
  • dir
  • vdir
2
1854-
1855 case 'n':
executed 24 times by 3 tests: case 'n':
Executed by:
  • dir
  • ls
  • vdir
24
1856 numeric_ids = true;-
1857 format = long_format;-
1858 break;
executed 24 times by 3 tests: break;
Executed by:
  • dir
  • ls
  • vdir
24
1859-
1860 case 'o': /* Just like -l, but don't display group info. */
executed 124 times by 3 tests: case 'o':
Executed by:
  • dir
  • ls
  • vdir
124
1861 format = long_format;-
1862 print_group = false;-
1863 break;
executed 124 times by 3 tests: break;
Executed by:
  • dir
  • ls
  • vdir
124
1864-
1865 case 'p':
executed 2 times by 2 tests: case 'p':
Executed by:
  • dir
  • vdir
2
1866 indicator_style = slash;-
1867 break;
executed 2 times by 2 tests: break;
Executed by:
  • dir
  • vdir
2
1868-
1869 case 'q':
executed 22 times by 3 tests: case 'q':
Executed by:
  • dir
  • ls
  • vdir
22
1870 qmark_funny_chars = true;-
1871 break;
executed 22 times by 3 tests: break;
Executed by:
  • dir
  • ls
  • vdir
22
1872-
1873 case 'r':
executed 4 times by 2 tests: case 'r':
Executed by:
  • dir
  • vdir
4
1874 sort_reverse = true;-
1875 break;
executed 4 times by 2 tests: break;
Executed by:
  • dir
  • vdir
4
1876-
1877 case 's':
executed 4 times by 2 tests: case 's':
Executed by:
  • dir
  • vdir
4
1878 print_block_size = true;-
1879 break;
executed 4 times by 2 tests: break;
Executed by:
  • dir
  • vdir
4
1880-
1881 case 't':
executed 9 times by 3 tests: case 't':
Executed by:
  • dir
  • ls
  • vdir
9
1882 sort_type = sort_time;-
1883 sort_type_specified = true;-
1884 break;
executed 9 times by 3 tests: break;
Executed by:
  • dir
  • ls
  • vdir
9
1885-
1886 case 'u':
executed 4 times by 3 tests: case 'u':
Executed by:
  • dir
  • ls
  • vdir
4
1887 time_type = time_atime;-
1888 break;
executed 4 times by 3 tests: break;
Executed by:
  • dir
  • ls
  • vdir
4
1889-
1890 case 'v':
executed 4 times by 3 tests: case 'v':
Executed by:
  • dir
  • ls
  • vdir
4
1891 sort_type = sort_version;-
1892 sort_type_specified = true;-
1893 break;
executed 4 times by 3 tests: break;
Executed by:
  • dir
  • ls
  • vdir
4
1894-
1895 case 'w':
executed 4 times by 2 tests: case 'w':
Executed by:
  • dir
  • vdir
4
1896 if (! set_line_length (optarg))
! set_line_length (optarg)Description
TRUEevaluated 4 times by 2 tests
Evaluated by:
  • dir
  • vdir
FALSEnever evaluated
0-4
1897 die (LS_FAILURE, 0, "%s: %s", _("invalid line width"),
executed 4 times by 2 tests: ((!!sizeof (struct { _Static_assert (LS_FAILURE, "verify_expr (" "LS_FAILURE" ", " "(error (LS_FAILURE, 0, \"%s: %s\", dcgettext (((void *)0), \"invalid line width\", 5), quote (optarg)), assume (false))" ")"); int _gl_dummy; })) ? ((error (LS_FAILURE, 0,... *)0), "invalid line width" , 5) , quote (optarg)), (( 0 ) ? (void) 0 : __builtin_unreachable ()))) : ((error (LS_FAILURE, 0, "%s: %s", dcgettext (((void *)0), "invalid line width" , 5) , quote (optarg)), (( 0 ) ? (void) 0 : __builtin_unreachable ())))) ;
Executed by:
  • dir
  • vdir
4
1898 quote (optarg));
executed 4 times by 2 tests: ((!!sizeof (struct { _Static_assert (LS_FAILURE, "verify_expr (" "LS_FAILURE" ", " "(error (LS_FAILURE, 0, \"%s: %s\", dcgettext (((void *)0), \"invalid line width\", 5), quote (optarg)), assume (false))" ")"); int _gl_dummy; })) ? ((error (LS_FAILURE, 0,... *)0), "invalid line width" , 5) , quote (optarg)), (( 0 ) ? (void) 0 : __builtin_unreachable ()))) : ((error (LS_FAILURE, 0, "%s: %s", dcgettext (((void *)0), "invalid line width" , 5) , quote (optarg)), (( 0 ) ? (void) 0 : __builtin_unreachable ())))) ;
Executed by:
  • dir
  • vdir
4
1899 break;
never executed: break;
0
1900-
1901 case 'x':
executed 2 times by 2 tests: case 'x':
Executed by:
  • dir
  • vdir
2
1902 format = horizontal;-
1903 break;
executed 2 times by 2 tests: break;
Executed by:
  • dir
  • vdir
2
1904-
1905 case 'A':
executed 6 times by 3 tests: case 'A':
Executed by:
  • dir
  • ls
  • vdir
6
1906 ignore_mode = IGNORE_DOT_AND_DOTDOT;-
1907 break;
executed 6 times by 3 tests: break;
Executed by:
  • dir
  • ls
  • vdir
6
1908-
1909 case 'B':
executed 4 times by 2 tests: case 'B':
Executed by:
  • dir
  • vdir
4
1910 add_ignore_pattern ("*~");-
1911 add_ignore_pattern (".*~");-
1912 break;
executed 4 times by 2 tests: break;
Executed by:
  • dir
  • vdir
4
1913-
1914 case 'C':
executed 3 times by 3 tests: case 'C':
Executed by:
  • dir
  • ls
  • vdir
3
1915 format = many_per_line;-
1916 break;
executed 3 times by 3 tests: break;
Executed by:
  • dir
  • ls
  • vdir
3
1917-
1918 case 'D':
executed 4 times by 2 tests: case 'D':
Executed by:
  • dir
  • vdir
4
1919 dired = true;-
1920 break;
executed 4 times by 2 tests: break;
Executed by:
  • dir
  • vdir
4
1921-
1922 case 'F':
executed 16 times by 3 tests: case 'F':
Executed by:
  • dir
  • ls
  • vdir
16
1923 indicator_style = classify;-
1924 break;
executed 16 times by 3 tests: break;
Executed by:
  • dir
  • ls
  • vdir
16
1925-
1926 case 'G': /* inhibit display of group info */
executed 4 times by 2 tests: case 'G':
Executed by:
  • dir
  • vdir
4
1927 print_group = false;-
1928 break;
executed 4 times by 2 tests: break;
Executed by:
  • dir
  • vdir
4
1929-
1930 case 'H':
executed 6 times by 3 tests: case 'H':
Executed by:
  • dir
  • ls
  • vdir
6
1931 dereference = DEREF_COMMAND_LINE_ARGUMENTS;-
1932 break;
executed 6 times by 3 tests: break;
Executed by:
  • dir
  • ls
  • vdir
6
1933-
1934 case DEREFERENCE_COMMAND_LINE_SYMLINK_TO_DIR_OPTION:
executed 2 times by 2 tests: case DEREFERENCE_COMMAND_LINE_SYMLINK_TO_DIR_OPTION:
Executed by:
  • dir
  • vdir
2
1935 dereference = DEREF_COMMAND_LINE_SYMLINK_TO_DIR;-
1936 break;
executed 2 times by 2 tests: break;
Executed by:
  • dir
  • vdir
2
1937-
1938 case 'I':
executed 6 times by 3 tests: case 'I':
Executed by:
  • dir
  • ls
  • vdir
6
1939 add_ignore_pattern (optarg);-
1940 break;
executed 6 times by 3 tests: break;
Executed by:
  • dir
  • ls
  • vdir
6
1941-
1942 case 'L':
executed 8 times by 3 tests: case 'L':
Executed by:
  • dir
  • ls
  • vdir
8
1943 dereference = DEREF_ALWAYS;-
1944 break;
executed 8 times by 3 tests: break;
Executed by:
  • dir
  • ls
  • vdir
8
1945-
1946 case 'N':
executed 6 times by 3 tests: case 'N':
Executed by:
  • dir
  • ls
  • vdir
6
1947 set_quoting_style (NULL, literal_quoting_style);-
1948 break;
executed 6 times by 3 tests: break;
Executed by:
  • dir
  • ls
  • vdir
6
1949-
1950 case 'Q':
executed 6 times by 3 tests: case 'Q':
Executed by:
  • dir
  • ls
  • vdir
6
1951 set_quoting_style (NULL, c_quoting_style);-
1952 break;
executed 6 times by 3 tests: break;
Executed by:
  • dir
  • ls
  • vdir
6
1953-
1954 case 'R':
executed 10 times by 3 tests: case 'R':
Executed by:
  • dir
  • ls
  • vdir
10
1955 recursive = true;-
1956 break;
executed 10 times by 3 tests: break;
Executed by:
  • dir
  • ls
  • vdir
10
1957-
1958 case 'S':
executed 2 times by 2 tests: case 'S':
Executed by:
  • dir
  • vdir
2
1959 sort_type = sort_size;-
1960 sort_type_specified = true;-
1961 break;
executed 2 times by 2 tests: break;
Executed by:
  • dir
  • vdir
2
1962-
1963 case 'T':
executed 4 times by 2 tests: case 'T':
Executed by:
  • dir
  • vdir
4
1964 tabsize = xnumtoumax (optarg, 0, 0, SIZE_MAX, "",-
1965 _("invalid tab size"), LS_FAILURE);-
1966 break;
never executed: break;
0
1967-
1968 case 'U':
executed 4 times by 3 tests: case 'U':
Executed by:
  • dir
  • ls
  • vdir
4
1969 sort_type = sort_none;-
1970 sort_type_specified = true;-
1971 break;
executed 4 times by 3 tests: break;
Executed by:
  • dir
  • ls
  • vdir
4
1972-
1973 case 'X':
executed 2 times by 2 tests: case 'X':
Executed by:
  • dir
  • vdir
2
1974 sort_type = sort_extension;-
1975 sort_type_specified = true;-
1976 break;
executed 2 times by 2 tests: break;
Executed by:
  • dir
  • vdir
2
1977-
1978 case '1':
executed 6 times by 3 tests: case '1':
Executed by:
  • dir
  • ls
  • vdir
6
1979 /* -1 has no effect after -l. */-
1980 if (format != long_format)
format != long_formatDescription
TRUEevaluated 5 times by 2 tests
Evaluated by:
  • dir
  • ls
FALSEevaluated 1 time by 1 test
Evaluated by:
  • vdir
1-5
1981 format = one_per_line;
executed 5 times by 2 tests: format = one_per_line;
Executed by:
  • dir
  • ls
5
1982 break;
executed 6 times by 3 tests: break;
Executed by:
  • dir
  • ls
  • vdir
6
1983-
1984 case AUTHOR_OPTION:
executed 2 times by 2 tests: case AUTHOR_OPTION:
Executed by:
  • dir
  • vdir
2
1985 print_author = true;-
1986 break;
executed 2 times by 2 tests: break;
Executed by:
  • dir
  • vdir
2
1987-
1988 case HIDE_OPTION:
executed 2 times by 2 tests: case HIDE_OPTION:
Executed by:
  • dir
  • vdir
2
1989 {-
1990 struct ignore_pattern *hide = xmalloc (sizeof *hide);-
1991 hide->pattern = optarg;-
1992 hide->next = hide_patterns;-
1993 hide_patterns = hide;-
1994 }-
1995 break;
executed 2 times by 2 tests: break;
Executed by:
  • dir
  • vdir
2
1996-
1997 case SORT_OPTION:
executed 2 times by 2 tests: case SORT_OPTION:
Executed by:
  • dir
  • vdir
2
1998 sort_type = XARGMATCH ("--sort", optarg, sort_args, sort_types);-
1999 sort_type_specified = true;-
2000 break;
never executed: break;
0
2001-
2002 case GROUP_DIRECTORIES_FIRST_OPTION:
executed 2 times by 2 tests: case GROUP_DIRECTORIES_FIRST_OPTION:
Executed by:
  • dir
  • vdir
2
2003 directories_first = true;-
2004 break;
executed 2 times by 2 tests: break;
Executed by:
  • dir
  • vdir
2
2005-
2006 case TIME_OPTION:
executed 2 times by 2 tests: case TIME_OPTION:
Executed by:
  • dir
  • vdir
2
2007 time_type = XARGMATCH ("--time", optarg, time_args, time_types);-
2008 break;
never executed: break;
0
2009-
2010 case FORMAT_OPTION:
executed 2 times by 2 tests: case FORMAT_OPTION:
Executed by:
  • dir
  • vdir
2
2011 format = XARGMATCH ("--format", optarg, format_args, format_types);-
2012 break;
never executed: break;
0
2013-
2014 case FULL_TIME_OPTION:
executed 4 times by 3 tests: case FULL_TIME_OPTION:
Executed by:
  • dir
  • ls
  • vdir
4
2015 format = long_format;-
2016 time_style_option = bad_cast ("full-iso");-
2017 break;
executed 4 times by 3 tests: break;
Executed by:
  • dir
  • ls
  • vdir
4
2018-
2019 case COLOR_OPTION:
executed 34 times by 3 tests: case COLOR_OPTION:
Executed by:
  • dir
  • ls
  • vdir
34
2020 {-
2021 int i;-
2022 if (optarg)
optargDescription
TRUEevaluated 32 times by 1 test
Evaluated by:
  • ls
FALSEevaluated 2 times by 2 tests
Evaluated by:
  • dir
  • vdir
2-32
2023 i = XARGMATCH ("--color", optarg, when_args, when_types);
executed 32 times by 1 test: i = ((when_types) [__xargmatch_internal ("--color", optarg, when_args, (char const *) (when_types), sizeof *(when_types), argmatch_die)]);
Executed by:
  • ls
32
2024 else-
2025 /* Using --color with no argument is equivalent to using-
2026 --color=always. */-
2027 i = when_always;
executed 2 times by 2 tests: i = when_always;
Executed by:
  • dir
  • vdir
2
2028-
2029 print_with_color = (i == when_always
i == when_alwaysDescription
TRUEevaluated 34 times by 3 tests
Evaluated by:
  • dir
  • ls
  • vdir
FALSEnever evaluated
0-34
2030 || (i == when_if_tty
i == when_if_ttyDescription
TRUEnever evaluated
FALSEnever evaluated
0
2031 && isatty (STDOUT_FILENO)));
isatty ( 1 )Description
TRUEnever evaluated
FALSEnever evaluated
0
2032-
2033 if (print_with_color)
print_with_colorDescription
TRUEevaluated 34 times by 3 tests
Evaluated by:
  • dir
  • ls
  • vdir
FALSEnever evaluated
0-34
2034 {-
2035 /* Don't use TAB characters in output. Some terminal-
2036 emulators can't handle the combination of tabs and-
2037 color codes on the same line. */-
2038 tabsize = 0;-
2039 }
executed 34 times by 3 tests: end of block
Executed by:
  • dir
  • ls
  • vdir
34
2040 break;
executed 34 times by 3 tests: break;
Executed by:
  • dir
  • ls
  • vdir
34
2041 }-
2042-
2043 case HYPERLINK_OPTION:
executed 2 times by 2 tests: case HYPERLINK_OPTION:
Executed by:
  • dir
  • vdir
2
2044 {-
2045 int i;-
2046 if (optarg)
optargDescription
TRUEnever evaluated
FALSEevaluated 2 times by 2 tests
Evaluated by:
  • dir
  • vdir
0-2
2047 i = XARGMATCH ("--hyperlink", optarg, when_args, when_types);
never executed: i = ((when_types) [__xargmatch_internal ("--hyperlink", optarg, when_args, (char const *) (when_types), sizeof *(when_types), argmatch_die)]);
0
2048 else-
2049 /* Using --hyperlink with no argument is equivalent to using-
2050 --hyperlink=always. */-
2051 i = when_always;
executed 2 times by 2 tests: i = when_always;
Executed by:
  • dir
  • vdir
2
2052-
2053 print_hyperlink = (i == when_always
i == when_alwaysDescription
TRUEevaluated 2 times by 2 tests
Evaluated by:
  • dir
  • vdir
FALSEnever evaluated
0-2
2054 || (i == when_if_tty
i == when_if_ttyDescription
TRUEnever evaluated
FALSEnever evaluated
0
2055 && isatty (STDOUT_FILENO)));
isatty ( 1 )Description
TRUEnever evaluated
FALSEnever evaluated
0
2056 break;
executed 2 times by 2 tests: break;
Executed by:
  • dir
  • vdir
2
2057 }-
2058-
2059 case INDICATOR_STYLE_OPTION:
executed 4 times by 2 tests: case INDICATOR_STYLE_OPTION:
Executed by:
  • dir
  • vdir
4
2060 indicator_style = XARGMATCH ("--indicator-style", optarg,-
2061 indicator_style_args,-
2062 indicator_style_types);-
2063 break;
never executed: break;
0
2064-
2065 case QUOTING_STYLE_OPTION:
executed 36 times by 3 tests: case QUOTING_STYLE_OPTION:
Executed by:
  • dir
  • ls
  • vdir
36
2066 set_quoting_style (NULL,-
2067 XARGMATCH ("--quoting-style", optarg,-
2068 quoting_style_args,-
2069 quoting_style_vals));-
2070 break;
executed 34 times by 1 test: break;
Executed by:
  • ls
34
2071-
2072 case TIME_STYLE_OPTION:
executed 11 times by 3 tests: case TIME_STYLE_OPTION:
Executed by:
  • dir
  • ls
  • vdir
11
2073 time_style_option = optarg;-
2074 break;
executed 11 times by 3 tests: break;
Executed by:
  • dir
  • ls
  • vdir
11
2075-
2076 case SHOW_CONTROL_CHARS_OPTION:
executed 2 times by 2 tests: case SHOW_CONTROL_CHARS_OPTION:
Executed by:
  • dir
  • vdir
2
2077 qmark_funny_chars = false;-
2078 break;
executed 2 times by 2 tests: break;
Executed by:
  • dir
  • vdir
2
2079-
2080 case BLOCK_SIZE_OPTION:
executed 2 times by 2 tests: case BLOCK_SIZE_OPTION:
Executed by:
  • dir
  • vdir
2
2081 {-
2082 enum strtol_error e = human_options (optarg, &human_output_opts,-
2083 &output_block_size);-
2084 if (e != LONGINT_OK)
e != LONGINT_OKDescription
TRUEevaluated 2 times by 2 tests
Evaluated by:
  • dir
  • vdir
FALSEnever evaluated
0-2
2085 xstrtol_fatal (e, oi, 0, long_options, optarg);
executed 2 times by 2 tests: xstrtol_fatal (e, oi, 0, long_options, optarg);
Executed by:
  • dir
  • vdir
2
2086 file_human_output_opts = human_output_opts;-
2087 file_output_block_size = output_block_size;-
2088 }-
2089 break;
never executed: break;
0
2090-
2091 case SI_OPTION:
executed 2 times by 2 tests: case SI_OPTION:
Executed by:
  • dir
  • vdir
2
2092 file_human_output_opts = human_output_opts =-
2093 human_autoscale | human_SI;-
2094 file_output_block_size = output_block_size = 1;-
2095 break;
executed 2 times by 2 tests: break;
Executed by:
  • dir
  • vdir
2
2096-
2097 case 'Z':
executed 4 times by 2 tests: case 'Z':
Executed by:
  • dir
  • vdir
4
2098 print_scontext = true;-
2099 break;
executed 4 times by 2 tests: break;
Executed by:
  • dir
  • vdir
4
2100-
2101 case_GETOPT_HELP_CHAR;
never executed: break;
executed 152 times by 3 tests: case GETOPT_HELP_CHAR:
Executed by:
  • dir
  • ls
  • vdir
0-152
2102-
2103 case_GETOPT_VERSION_CHAR (PROGRAM_NAME, AUTHORS);
executed 12 times by 3 tests: exit ( 0 );
Executed by:
  • dir
  • ls
  • vdir
never executed: break;
executed 12 times by 3 tests: case GETOPT_VERSION_CHAR:
Executed by:
  • dir
  • ls
  • vdir
0-12
2104-
2105 default:
executed 7 times by 3 tests: default:
Executed by:
  • dir
  • ls
  • vdir
7
2106 usage (LS_FAILURE);-
2107 }
never executed: end of block
0
2108 }-
2109-
2110 if (! output_block_size)
! output_block_sizeDescription
TRUEevaluated 1166 times by 3 tests
Evaluated by:
  • dir
  • ls
  • vdir
FALSEnever evaluated
0-1166
2111 {-
2112 char const *ls_block_size = getenv ("LS_BLOCK_SIZE");-
2113 human_options (ls_block_size,-
2114 &human_output_opts, &output_block_size);-
2115 if (ls_block_size || getenv ("BLOCK_SIZE"))
ls_block_sizeDescription
TRUEnever evaluated
FALSEevaluated 1166 times by 3 tests
Evaluated by:
  • dir
  • ls
  • vdir
getenv ("BLOCK_SIZE")Description
TRUEnever evaluated
FALSEevaluated 1166 times by 3 tests
Evaluated by:
  • dir
  • ls
  • vdir
0-1166
2116 {-
2117 file_human_output_opts = human_output_opts;-
2118 file_output_block_size = output_block_size;-
2119 }
never executed: end of block
0
2120 if (kibibytes_specified)
kibibytes_specifiedDescription
TRUEnever evaluated
FALSEevaluated 1166 times by 3 tests
Evaluated by:
  • dir
  • ls
  • vdir
0-1166
2121 {-
2122 human_output_opts = 0;-
2123 output_block_size = 1024;-
2124 }
never executed: end of block
0
2125 }
executed 1166 times by 3 tests: end of block
Executed by:
  • dir
  • ls
  • vdir
1166
2126-
2127 /* Determine the max possible number of display columns. */-
2128 max_idx = line_length / MIN_COLUMN_WIDTH;-
2129 /* Account for first display column not having a separator,-
2130 or line_lengths shorter than MIN_COLUMN_WIDTH. */-
2131 max_idx += line_length % MIN_COLUMN_WIDTH != 0;-
2132-
2133 enum quoting_style qs = get_quoting_style (NULL);-
2134 align_variable_outer_quotes = format != with_commas
format != with_commasDescription
TRUEevaluated 1166 times by 3 tests
Evaluated by:
  • dir
  • ls
  • vdir
FALSEnever evaluated
0-1166
2135 && format != one_per_line
format != one_per_lineDescription
TRUEevaluated 151 times by 3 tests
Evaluated by:
  • dir
  • ls
  • vdir
FALSEevaluated 1015 times by 1 test
Evaluated by:
  • ls
151-1015
2136 && (line_length || format == long_format)
line_lengthDescription
TRUEevaluated 151 times by 3 tests
Evaluated by:
  • dir
  • ls
  • vdir
FALSEnever evaluated
format == long_formatDescription
TRUEnever evaluated
FALSEnever evaluated
0-151
2137 && (qs == shell_quoting_style
qs == shell_quoting_styleDescription
TRUEnever evaluated
FALSEevaluated 151 times by 3 tests
Evaluated by:
  • dir
  • ls
  • vdir
0-151
2138 || qs == shell_escape_quoting_style
qs == shell_es..._quoting_styleDescription
TRUEnever evaluated
FALSEevaluated 151 times by 3 tests
Evaluated by:
  • dir
  • ls
  • vdir
0-151
2139 || qs == c_maybe_quoting_style);
qs == c_maybe_quoting_styleDescription
TRUEnever evaluated
FALSEevaluated 151 times by 3 tests
Evaluated by:
  • dir
  • ls
  • vdir
0-151
2140 filename_quoting_options = clone_quoting_options (NULL);-
2141 if (qs == escape_quoting_style)
qs == escape_quoting_styleDescription
TRUEevaluated 6 times by 3 tests
Evaluated by:
  • dir
  • ls
  • vdir
FALSEevaluated 1160 times by 1 test
Evaluated by:
  • ls
6-1160
2142 set_char_quoting (filename_quoting_options, ' ', 1);
executed 6 times by 3 tests: set_char_quoting (filename_quoting_options, ' ', 1);
Executed by:
  • dir
  • ls
  • vdir
6
2143 if (file_type <= indicator_style)
file_type <= indicator_styleDescription
TRUEevaluated 14 times by 1 test
Evaluated by:
  • ls
FALSEevaluated 1152 times by 3 tests
Evaluated by:
  • dir
  • ls
  • vdir
14-1152
2144 {-
2145 char const *p;-
2146 for (p = &"*=>@|"[indicator_style - file_type]; *p; p++)
*pDescription
TRUEevaluated 58 times by 1 test
Evaluated by:
  • ls
FALSEevaluated 14 times by 1 test
Evaluated by:
  • ls
14-58
2147 set_char_quoting (filename_quoting_options, *p, 1);
executed 58 times by 1 test: set_char_quoting (filename_quoting_options, *p, 1);
Executed by:
  • ls
58
2148 }
executed 14 times by 1 test: end of block
Executed by:
  • ls
14
2149-
2150 dirname_quoting_options = clone_quoting_options (NULL);-
2151 set_char_quoting (dirname_quoting_options, ':', 1);-
2152-
2153 /* --dired is meaningful only with --format=long (-l).-
2154 Otherwise, ignore it. FIXME: warn about this?-
2155 Alternatively, make --dired imply --format=long? */-
2156 if (dired && (format != long_format || print_hyperlink))
diredDescription
TRUEnever evaluated
FALSEevaluated 1166 times by 3 tests
Evaluated by:
  • dir
  • ls
  • vdir
format != long_formatDescription
TRUEnever evaluated
FALSEnever evaluated
print_hyperlinkDescription
TRUEnever evaluated
FALSEnever evaluated
0-1166
2157 dired = false;
never executed: dired = 0 ;
0
2158-
2159 /* If -c or -u is specified and not -l (or any other option that implies -l),-
2160 and no sort-type was specified, then sort by the ctime (-c) or atime (-u).-
2161 The behavior of ls when using either -c or -u but with neither -l nor -t-
2162 appears to be unspecified by POSIX. So, with GNU ls, '-u' alone means-
2163 sort by atime (this is the one that's not specified by the POSIX spec),-
2164 -lu means show atime and sort by name, -lut means show atime and sort-
2165 by atime. */-
2166-
2167 if ((time_type == time_ctime || time_type == time_atime)
time_type == time_ctimeDescription
TRUEevaluated 3 times by 1 test
Evaluated by:
  • ls
FALSEevaluated 1163 times by 3 tests
Evaluated by:
  • dir
  • ls
  • vdir
time_type == time_atimeDescription
TRUEevaluated 2 times by 1 test
Evaluated by:
  • ls
FALSEevaluated 1161 times by 3 tests
Evaluated by:
  • dir
  • ls
  • vdir
2-1163
2168 && !sort_type_specified && format != long_format)
!sort_type_specifiedDescription
TRUEevaluated 2 times by 1 test
Evaluated by:
  • ls
FALSEevaluated 3 times by 1 test
Evaluated by:
  • ls
format != long_formatDescription
TRUEevaluated 1 time by 1 test
Evaluated by:
  • ls
FALSEevaluated 1 time by 1 test
Evaluated by:
  • ls
1-3
2169 {-
2170 sort_type = sort_time;-
2171 }
executed 1 time by 1 test: end of block
Executed by:
  • ls
1
2172-
2173 if (format == long_format)
format == long_formatDescription
TRUEevaluated 149 times by 2 tests
Evaluated by:
  • ls
  • vdir
FALSEevaluated 1017 times by 2 tests
Evaluated by:
  • dir
  • ls
149-1017
2174 {-
2175 char *style = time_style_option;-
2176 static char const posix_prefix[] = "posix-";-
2177-
2178 if (! style)
! styleDescription
TRUEevaluated 138 times by 2 tests
Evaluated by:
  • ls
  • vdir
FALSEevaluated 11 times by 1 test
Evaluated by:
  • ls
11-138
2179 if (! (style = getenv ("TIME_STYLE")))
! (style = get..."TIME_STYLE"))Description
TRUEevaluated 138 times by 2 tests
Evaluated by:
  • ls
  • vdir
FALSEnever evaluated
0-138
2180 style = bad_cast ("locale");
executed 138 times by 2 tests: style = bad_cast ("locale");
Executed by:
  • ls
  • vdir
138
2181-
2182 while (STREQ_LEN (style, posix_prefix, sizeof posix_prefix - 1))
never executed: __result = (((const unsigned char *) (const char *) ( style ))[3] - __s2[3]);
never executed: end of block
never executed: end of block
never executed: __result = (((const unsigned char *) (const char *) ( posix_prefix ))[3] - __s2[3]);
never executed: end of block
never executed: end of block
( (__extension... - 1 ))) == 0)Description
TRUEnever evaluated
FALSEevaluated 149 times by 2 tests
Evaluated by:
  • ls
  • vdir
__builtin_cons...x_prefix - 1 )Description
TRUEevaluated 149 times by 2 tests
Evaluated by:
  • ls
  • vdir
FALSEnever evaluated
__builtin_constant_p ( style )Description
TRUEnever evaluated
FALSEevaluated 149 times by 2 tests
Evaluated by:
  • ls
  • vdir
strlen ( style..._prefix - 1 ))Description
TRUEnever evaluated
FALSEnever evaluated
__builtin_cons...posix_prefix )Description
TRUEnever evaluated
FALSEevaluated 149 times by 2 tests
Evaluated by:
  • ls
  • vdir
strlen ( posix..._prefix - 1 ))Description
TRUEnever evaluated
FALSEnever evaluated
__s1_len > 0Description
TRUEnever evaluated
FALSEnever evaluated
__result == 0Description
TRUEnever evaluated
FALSEnever evaluated
__s1_len > 1Description
TRUEnever evaluated
FALSEnever evaluated
__result == 0Description
TRUEnever evaluated
FALSEnever evaluated
__s1_len > 2Description
TRUEnever evaluated
FALSEnever evaluated
__result == 0Description
TRUEnever evaluated
FALSEnever evaluated
__s2_len > 0Description
TRUEnever evaluated
FALSEnever evaluated
__result == 0Description
TRUEnever evaluated
FALSEnever evaluated
__s2_len > 1Description
TRUEnever evaluated
FALSEnever evaluated
__result == 0Description
TRUEnever evaluated
FALSEnever evaluated
__s2_len > 2Description
TRUEnever evaluated
FALSEnever evaluated
__result == 0Description
TRUEnever evaluated
FALSEnever evaluated
0-149
2183 {-
2184 if (! hard_locale (LC_TIME))
! hard_locale ( 2 )Description
TRUEnever evaluated
FALSEnever evaluated
0
2185 return optind;
never executed: return optind;
0
2186 style += sizeof posix_prefix - 1;-
2187 }
never executed: end of block
0
2188-
2189 if (*style == '+')
*style == '+'Description
TRUEevaluated 8 times by 1 test
Evaluated by:
  • ls
FALSEevaluated 141 times by 2 tests
Evaluated by:
  • ls
  • vdir
8-141
2190 {-
2191 char *p0 = style + 1;-
2192 char *p1 = strchr (p0, '\n');
__builtin_constant_p ( '\n' )Description
TRUEevaluated 8 times by 1 test
Evaluated by:
  • ls
FALSEnever evaluated
!__builtin_constant_p ( p0 )Description
TRUEevaluated 8 times by 1 test
Evaluated by:
  • ls
FALSEnever evaluated
( '\n' ) == '\0'Description
TRUEnever evaluated
FALSEevaluated 8 times by 1 test
Evaluated by:
  • ls
0-8
2193 if (! p1)
! p1Description
TRUEevaluated 8 times by 1 test
Evaluated by:
  • ls
FALSEnever evaluated
0-8
2194 p1 = p0;
executed 8 times by 1 test: p1 = p0;
Executed by:
  • ls
8
2195 else-
2196 {-
2197 if (strchr (p1 + 1, '\n'))
(__extension__...+ 1 , '\n' )))Description
TRUEnever evaluated
FALSEnever evaluated
__builtin_constant_p ( '\n' )Description
TRUEnever evaluated
FALSEnever evaluated
!__builtin_con...t_p ( p1 + 1 )Description
TRUEnever evaluated
FALSEnever evaluated
( '\n' ) == '\0'Description
TRUEnever evaluated
FALSEnever evaluated
0
2198 die (LS_FAILURE, 0, _("invalid time style format %s"),
never executed: ((!!sizeof (struct { _Static_assert (LS_FAILURE, "verify_expr (" "LS_FAILURE" ", " "(error (LS_FAILURE, 0, dcgettext (((void *)0), \"invalid time style format %s\", 5), quote (p0)), assume (false))" ")"); int _gl_dummy; })) ? ((error (LS_FAILURE, 0, dcget...)0), "invalid time style format %s" , 5) , quote (p0)), (( 0 ) ? (void) 0 : __builtin_unreachable ()))) : ((error (LS_FAILURE, 0, dcgettext (((void *)0), "invalid time style format %s" , 5) , quote (p0)), (( 0 ) ? (void) 0 : __builtin_unreachable ())))) ;
0
2199 quote (p0));
never executed: ((!!sizeof (struct { _Static_assert (LS_FAILURE, "verify_expr (" "LS_FAILURE" ", " "(error (LS_FAILURE, 0, dcgettext (((void *)0), \"invalid time style format %s\", 5), quote (p0)), assume (false))" ")"); int _gl_dummy; })) ? ((error (LS_FAILURE, 0, dcget...)0), "invalid time style format %s" , 5) , quote (p0)), (( 0 ) ? (void) 0 : __builtin_unreachable ()))) : ((error (LS_FAILURE, 0, dcgettext (((void *)0), "invalid time style format %s" , 5) , quote (p0)), (( 0 ) ? (void) 0 : __builtin_unreachable ())))) ;
0
2200 *p1++ = '\0';-
2201 }
never executed: end of block
0
2202 long_time_format[0] = p0;-
2203 long_time_format[1] = p1;-
2204 }
executed 8 times by 1 test: end of block
Executed by:
  • ls
8
2205 else-
2206 {-
2207 ptrdiff_t res = argmatch (style, time_style_args,-
2208 (char const *) time_style_types,-
2209 sizeof (*time_style_types));-
2210 if (res < 0)
res < 0Description
TRUEnever evaluated
FALSEevaluated 141 times by 2 tests
Evaluated by:
  • ls
  • vdir
0-141
2211 {-
2212 /* This whole block used to be a simple use of XARGMATCH.-
2213 but that didn't print the "posix-"-prefixed variants or-
2214 the "+"-prefixed format string option upon failure. */-
2215 argmatch_invalid ("time style", style, res);-
2216-
2217 /* The following is a manual expansion of argmatch_valid,-
2218 but with the added "+ ..." description and the [posix-]-
2219 prefixes prepended. Note that this simplification works-
2220 only because all four existing time_style_types values-
2221 are distinct. */-
2222 fputs (_("Valid arguments are:\n"), stderr);-
2223 char const *const *p = time_style_args;-
2224 while (*p)
*pDescription
TRUEnever evaluated
FALSEnever evaluated
0
2225 fprintf (stderr, " - [posix-]%s\n", *p++);
never executed: fprintf ( stderr , " - [posix-]%s\n", *p++);
0
2226 fputs (_(" - +FORMAT (e.g., +%H:%M) for a 'date'-style"-
2227 " format\n"), stderr);-
2228 usage (LS_FAILURE);-
2229 }
never executed: end of block
0
2230 switch (res)-
2231 {-
2232 case full_iso_time_style:
executed 2 times by 1 test: case full_iso_time_style:
Executed by:
  • ls
2
2233 long_time_format[0] = long_time_format[1] =-
2234 "%Y-%m-%d %H:%M:%S.%N %z";-
2235 break;
executed 2 times by 1 test: break;
Executed by:
  • ls
2
2236-
2237 case long_iso_time_style:
executed 1 time by 1 test: case long_iso_time_style:
Executed by:
  • ls
1
2238 long_time_format[0] = long_time_format[1] = "%Y-%m-%d %H:%M";-
2239 break;
executed 1 time by 1 test: break;
Executed by:
  • ls
1
2240-
2241 case iso_time_style:
never executed: case iso_time_style:
0
2242 long_time_format[0] = "%Y-%m-%d ";-
2243 long_time_format[1] = "%m-%d %H:%M";-
2244 break;
never executed: break;
0
2245-
2246 case locale_time_style:
executed 138 times by 2 tests: case locale_time_style:
Executed by:
  • ls
  • vdir
138
2247 if (hard_locale (LC_TIME))
hard_locale ( 2 )Description
TRUEnever evaluated
FALSEevaluated 138 times by 2 tests
Evaluated by:
  • ls
  • vdir
0-138
2248 {-
2249 for (int i = 0; i < 2; i++)
i < 2Description
TRUEnever evaluated
FALSEnever evaluated
0
2250 long_time_format[i] =
never executed: long_time_format[i] = dcgettext ( ((void *)0) , long_time_format[i], 2 );
0
2251 dcgettext (NULL, long_time_format[i], LC_TIME);
never executed: long_time_format[i] = dcgettext ( ((void *)0) , long_time_format[i], 2 );
0
2252 }
never executed: end of block
0
2253 }
executed 138 times by 2 tests: end of block
Executed by:
  • ls
  • vdir
138
2254 }
executed 141 times by 2 tests: end of block
Executed by:
  • ls
  • vdir
141
2255-
2256 abformat_init ();-
2257 }
executed 149 times by 2 tests: end of block
Executed by:
  • ls
  • vdir
149
2258-
2259 return optind;
executed 1166 times by 3 tests: return optind;
Executed by:
  • dir
  • ls
  • vdir
1166
2260}-
2261-
2262/* Parse a string as part of the LS_COLORS variable; this may involve-
2263 decoding all kinds of escape characters. If equals_end is set an-
2264 unescaped equal sign ends the string, otherwise only a : or \0-
2265 does. Set *OUTPUT_COUNT to the number of bytes output. Return-
2266 true if successful.-
2267-
2268 The resulting string is *not* null-terminated, but may contain-
2269 embedded nulls.-
2270-
2271 Note that both dest and src are char **; on return they point to-
2272 the first free byte after the array and the character that ended-
2273 the input string, respectively. */-
2274-
2275static bool-
2276get_funky_string (char **dest, const char **src, bool equals_end,-
2277 size_t *output_count)-
2278{-
2279 char num; /* For numerical codes */-
2280 size_t count; /* Something to count with */-
2281 enum {-
2282 ST_GND, ST_BACKSLASH, ST_OCTAL, ST_HEX, ST_CARET, ST_END, ST_ERROR-
2283 } state;-
2284 const char *p;-
2285 char *q;-
2286-
2287 p = *src; /* We don't want to double-indirect */-
2288 q = *dest; /* the whole darn time. */-
2289-
2290 count = 0; /* No characters counted in yet. */-
2291 num = 0;-
2292-
2293 state = ST_GND; /* Start in ground state. */-
2294 while (state < ST_END)
state < ST_ENDDescription
TRUEevaluated 314 times by 1 test
Evaluated by:
  • ls
FALSEevaluated 62 times by 1 test
Evaluated by:
  • ls
62-314
2295 {-
2296 switch (state)-
2297 {-
2298 case ST_GND: /* Ground state (no escapes) */
executed 314 times by 1 test: case ST_GND:
Executed by:
  • ls
314
2299 switch (*p)-
2300 {-
2301 case ':':
executed 46 times by 1 test: case ':':
Executed by:
  • ls
46
2302 case '\0':
executed 16 times by 1 test: case '\0':
Executed by:
  • ls
16
2303 state = ST_END; /* End of string */-
2304 break;
executed 62 times by 1 test: break;
Executed by:
  • ls
62
2305 case '\\':
never executed: case '\\':
0
2306 state = ST_BACKSLASH; /* Backslash escape sequence */-
2307 ++p;-
2308 break;
never executed: break;
0
2309 case '^':
never executed: case '^':
0
2310 state = ST_CARET; /* Caret escape */-
2311 ++p;-
2312 break;
never executed: break;
0
2313 case '=':
never executed: case '=':
0
2314 if (equals_end)
equals_endDescription
TRUEnever evaluated
FALSEnever evaluated
0
2315 {-
2316 state = ST_END; /* End */-
2317 break;
never executed</