#include <signal.h>
#include <termios.h>
#include <sys/ioctl.h>
+#include <sys/sysmacros.h> /* major() and minor() */
#include "busybox.h"
#ifdef CONFIG_SELINUX
#include <fs_secure.h>
#include <time.h>
#endif
-#ifndef MAJOR
-#define MAJOR(dev) (((dev)>>8)&0xff)
-#define MINOR(dev) ((dev)&0xff)
-#endif
-
/* what is the overall style of the listing */
#define STYLE_AUTO (0)
#define STYLE_COLUMNS (1U<<21) /* fill columns */
if (S_ISDIR(dn[i]->dstat.st_mode)
&& (notsubdirs
|| ((dn[i]->name[0] != '.')
- || (dn[i]->name[1]
+ || (dn[i]->name[1]
&& ((dn[i]->name[1] != '.')
|| dn[i]->name[2])))))
dirs++;
}
/*----------------------------------------------------------------------*/
-static void showdirs(struct dnode **dn, int ndirs)
+static void showdirs(struct dnode **dn, int ndirs, int first)
{
int i, nfiles;
struct dnode **subdnp;
for (i = 0; i < ndirs; i++) {
if (all_fmt & (DISP_DIRNAME | DISP_RECURSIVE)) {
- printf("\n%s:\n", dn[i]->fullname);
+ if (!first)
+ printf("\n");
+ first = 0;
+ printf("%s:\n", dn[i]->fullname);
}
subdnp = list_dir(dn[i]->fullname);
nfiles = countfiles(subdnp);
#ifdef CONFIG_FEATURE_LS_SORTFILES
shellsort(dnd, dndirs);
#endif
- showdirs(dnd, dndirs);
+ showdirs(dnd, dndirs, 0);
free(dnd); /* free the array of dnode pointers to the dirs */
}
}
break;
case LIST_ID_NAME:
#ifdef CONFIG_FEATURE_LS_USERNAME
- my_getpwuid(scratch, dn->dstat.st_uid);
+ my_getpwuid(scratch, dn->dstat.st_uid, sizeof(scratch));
printf("%-8.8s ", scratch);
- my_getgrgid(scratch, dn->dstat.st_gid);
+ my_getgrgid(scratch, dn->dstat.st_gid, sizeof(scratch));
printf("%-8.8s", scratch);
column += 17;
break;
case LIST_SIZE:
case LIST_DEV:
if (S_ISBLK(dn->dstat.st_mode) || S_ISCHR(dn->dstat.st_mode)) {
- column += printf("%4d, %3d ", (int) MAJOR(dn->dstat.st_rdev),
- (int) MINOR(dn->dstat.st_rdev));
+ column += printf("%4d, %3d ", (int) major(dn->dstat.st_rdev),
+ (int) minor(dn->dstat.st_rdev));
} else {
#ifdef CONFIG_FEATURE_HUMAN_READABLE
if (all_fmt & LS_DISP_HR) {
break;
#ifdef CONFIG_FEATURE_LS_TIMESTAMPS
case LIST_FULLTIME:
+ printf("%24.24s ", filetime);
+ column += 25;
+ break;
case LIST_DATE_TIME:
- if (all_fmt & LIST_FULLTIME) {
- printf("%24.24s ", filetime);
- column += 25;
- break;
- }
- age = time(NULL) - ttime;
- printf("%6.6s ", filetime + 4);
- if (age < 3600L * 24 * 365 / 2 && age > -15 * 60) {
- /* hh:mm if less than 6 months old */
- printf("%5.5s ", filetime + 11);
- } else {
- printf(" %4.4s ", filetime + 20);
+ if ((all_fmt & LIST_FULLTIME) == 0) {
+ age = time(NULL) - ttime;
+ printf("%6.6s ", filetime + 4);
+ if (age < 3600L * 24 * 365 / 2 && age > -15 * 60) {
+ /* hh:mm if less than 6 months old */
+ printf("%5.5s ", filetime + 11);
+ } else {
+ printf(" %4.4s ", filetime + 20);
+ }
+ column += 13;
}
- column += 13;
break;
#endif
#ifdef CONFIG_SELINUX
LS_STR_SELINUX \
LS_STR_AUTOWIDTH;
-#define LIST_MASK_TRIGGER LIST_SHORT
+#define LIST_MASK_TRIGGER 0
#define STYLE_MASK_TRIGGER STYLE_MASK
#define SORT_MASK_TRIGGER SORT_MASK
#define DISP_MASK_TRIGGER DISP_ROWS
# endif
#endif
#ifdef CONFIG_FEATURE_LS_SORTFILES
- SORT_ORDER_REVERSE, /* r */
SORT_SIZE, /* S */
+ SORT_EXT, /* X */
+ SORT_ORDER_REVERSE, /* r */
SORT_VERSION, /* v */
- SORT_EXT, /* v */
#endif
#ifdef CONFIG_FEATURE_LS_FILETYPES
LIST_FILETYPE | LIST_EXEC, /* F */
#ifdef CONFIG_SELINUX
LIST_MODEBITS|LIST_NLINKS|LIST_CONTEXT|LIST_SIZE|LIST_DATE_TIME, /* K */
#endif
+ (1U<<31)
};
#ifdef CONFIG_FEATURE_AUTOWIDTH
/* Obtain the terminal width. */
- get_terminal_width_height(0, &terminal_width, NULL);
+ get_terminal_width_height(STDOUT_FILENO, &terminal_width, NULL);
/* Go one less... */
terminal_width--;
#endif
#ifdef CONFIG_FEATURE_LS_COLOR
- if (isatty(fileno(stdout)))
+ if (isatty(STDOUT_FILENO))
show_color = 1;
#endif
#else
opt = bb_getopt_ulflags(argc, argv, ls_options);
#endif
- /* 16 = maximum options minus tabsize and screewn width */
- for (i = 0; i < 16; i++) {
+ for (i = 0; opt_flags[i] != (1U<<31); i++) {
if (opt & (1 << i)) {
unsigned int flags = opt_flags[i];
if (flags & LIST_MASK_TRIGGER) {
if ((all_fmt & STYLE_MASK) == STYLE_LONG && (all_fmt & LIST_ID_NUMERIC))
all_fmt &= ~LIST_ID_NAME; /* don't list names if numeric uid */
#endif
-
+
/* choose a display format */
if ((all_fmt & STYLE_MASK) == STYLE_AUTO)
#if STYLE_AUTO != 0
all_fmt = (all_fmt & ~STYLE_MASK)
- | (isatty(fileno(stdout)) ? STYLE_COLUMNS : STYLE_SINGLE);
+ | (isatty(STDOUT_FILENO) ? STYLE_COLUMNS : STYLE_SINGLE);
#else
- all_fmt |= (isatty(fileno(stdout)) ? STYLE_COLUMNS : STYLE_SINGLE);
+ all_fmt |= (isatty(STDOUT_FILENO) ? STYLE_COLUMNS : STYLE_SINGLE);
#endif
/*
cur = cur->next;
}
-
if (all_fmt & DISP_NOLIST) {
#ifdef CONFIG_FEATURE_LS_SORTFILES
shellsort(dnp, nfiles);
#ifdef CONFIG_FEATURE_LS_SORTFILES
shellsort(dnd, dndirs);
#endif
- showdirs(dnd, dndirs);
+ showdirs(dnd, dndirs, dnfiles == 0);
}
}
return (status);