aboutsummaryrefslogtreecommitdiff
path: root/coreutils/ls.c
diff options
context:
space:
mode:
Diffstat (limited to 'coreutils/ls.c')
-rw-r--r--coreutils/ls.c246
1 files changed, 167 insertions, 79 deletions
diff --git a/coreutils/ls.c b/coreutils/ls.c
index cc809b797..c24561576 100644
--- a/coreutils/ls.c
+++ b/coreutils/ls.c
@@ -126,6 +126,8 @@
126//usage: "\n -F Append indicator (one of */=@|) to names" 126//usage: "\n -F Append indicator (one of */=@|) to names"
127//usage: ) 127//usage: )
128//usage: "\n -l Long format" 128//usage: "\n -l Long format"
129////usage: "\n -g Long format without group column"
130////TODO: support -G too ("suppress owner column", GNUism)
129//usage: "\n -i List inode numbers" 131//usage: "\n -i List inode numbers"
130//usage: "\n -n List numeric UIDs and GIDs instead of names" 132//usage: "\n -n List numeric UIDs and GIDs instead of names"
131//usage: "\n -s List allocated blocks" 133//usage: "\n -s List allocated blocks"
@@ -159,6 +161,8 @@
159//usage: IF_FEATURE_LS_WIDTH( 161//usage: IF_FEATURE_LS_WIDTH(
160//usage: "\n -w N Format N columns wide" 162//usage: "\n -w N Format N columns wide"
161//usage: ) 163//usage: )
164////usage: "\n -Q Double-quote names"
165////usage: "\n -q Replace unprintable chars with '?'"
162//usage: IF_FEATURE_LS_COLOR( 166//usage: IF_FEATURE_LS_COLOR(
163//usage: "\n --color[={always,never,auto}]" 167//usage: "\n --color[={always,never,auto}]"
164//usage: ) 168//usage: )
@@ -196,27 +200,47 @@ SPLIT_SUBDIR = 2,
196 200
197/* -Cadi1l Std options, busybox always supports */ 201/* -Cadi1l Std options, busybox always supports */
198/* -gnsxA Std options, busybox always supports */ 202/* -gnsxA Std options, busybox always supports */
199/* -Q GNU option, busybox always supports */ 203/* -Q GNU option, busybox always supports: */
200/* -k Std option, busybox always supports (by ignoring) */ 204/* -Q, --quote-name */
201/* It means "for -s, show sizes in kbytes" */ 205/* enclose entry names in double quotes */
202/* Seems to only affect "POSIXLY_CORRECT=1 ls -sk" */
203/* since otherwise -s shows kbytes anyway */
204/* -LHRctur Std options, busybox optionally supports */ 206/* -LHRctur Std options, busybox optionally supports */
205/* -Fp Std options, busybox optionally supports */ 207/* -Fp Std options, busybox optionally supports */
206/* -SXvhTw GNU options, busybox optionally supports */ 208/* -SXvhTw GNU options, busybox optionally supports */
207/* -T WIDTH Ignored (we don't use tabs on output) */ 209/* -T WIDTH Ignored (we don't use tabs on output) */
208/* -Z SELinux mandated option, busybox optionally supports */ 210/* -Z SELinux mandated option, busybox optionally supports */
211/* -q Std option, busybox always supports: */
212/* https://pubs.opengroup.org/onlinepubs/9699919799/utilities/ls.html: */
213/* Force each instance of non-printable filename characters and */
214/* <tab> characters to be written as the <question-mark> ('?') */
215/* character. Implementations may provide this option by default */
216/* if the output is to a terminal device. */
217/* -k Std option, busybox always supports (by ignoring) */
218/* It means "for -s, show sizes in kbytes" */
219/* Seems to only affect "POSIXLY_CORRECT=1 ls -sk" */
220/* since otherwise -s shows kbytes anyway */
209#define ls_options \ 221#define ls_options \
210 "Cadi1lgnsxAk" /* 12 opts, total 12 */ \ 222 "Cadi1lgnsxA" /* 11 opts, total 11 */ \
211 IF_FEATURE_LS_FILETYPES("Fp") /* 2, 14 */ \ 223 IF_FEATURE_LS_FILETYPES("Fp") /* 2, 13 */ \
212 IF_FEATURE_LS_RECURSIVE("R") /* 1, 15 */ \ 224 IF_FEATURE_LS_RECURSIVE("R") /* 1, 14 */ \
213 IF_SELINUX("Z") /* 1, 16 */ \ 225 IF_SELINUX("Z") /* 1, 15 */ \
214 "Q" /* 1, 17 */ \ 226 "Q" /* 1, 16 */ \
215 IF_FEATURE_LS_TIMESTAMPS("ctu") /* 3, 20 */ \ 227 IF_FEATURE_LS_TIMESTAMPS("ctu") /* 3, 19 */ \
216 IF_FEATURE_LS_SORTFILES("SXrv") /* 4, 24 */ \ 228 IF_FEATURE_LS_SORTFILES("SXrv") /* 4, 23 */ \
217 IF_FEATURE_LS_FOLLOWLINKS("LH") /* 2, 26 */ \ 229 IF_FEATURE_LS_FOLLOWLINKS("LH") /* 2, 25 */ \
218 IF_FEATURE_HUMAN_READABLE("h") /* 1, 27 */ \ 230 IF_FEATURE_HUMAN_READABLE("h") /* 1, 26 */ \
219 IF_FEATURE_LS_WIDTH("T:w:") /* 2, 29 */ 231 IF_FEATURE_LS_WIDTH("T:w:") /* 2, 28 */ \
232 IF_LONG_OPTS("\xff") /* 1, 29 */ \
233 IF_LONG_OPTS("\xfe") /* 1, 30 */ \
234 IF_LONG_OPTS("\xfd") /* 1, 31 */ \
235 "qk" /* 2, 33 */
236
237#if ENABLE_LONG_OPTS
238static const char ls_longopts[] ALIGN1 =
239 "full-time\0" No_argument "\xff"
240 "group-directories-first\0" No_argument "\xfe"
241 IF_FEATURE_LS_COLOR("color\0" Optional_argument "\xfd")
242;
243#endif
220 244
221enum { 245enum {
222 OPT_C = (1 << 0), 246 OPT_C = (1 << 0),
@@ -230,29 +254,31 @@ enum {
230 OPT_s = (1 << 8), 254 OPT_s = (1 << 8),
231 OPT_x = (1 << 9), 255 OPT_x = (1 << 9),
232 OPT_A = (1 << 10), 256 OPT_A = (1 << 10),
233 //OPT_k = (1 << 11),
234 257
235 OPTBIT_F = 12, 258 OPTBIT_F = 11,
236 OPTBIT_p, /* 13 */ 259 OPTBIT_p, /* 12 */
237 OPTBIT_R = OPTBIT_F + 2 * ENABLE_FEATURE_LS_FILETYPES, 260 OPTBIT_R = OPTBIT_F + 2 * ENABLE_FEATURE_LS_FILETYPES,
238 OPTBIT_Z = OPTBIT_R + 1 * ENABLE_FEATURE_LS_RECURSIVE, 261 OPTBIT_Z = OPTBIT_R + 1 * ENABLE_FEATURE_LS_RECURSIVE,
239 OPTBIT_Q = OPTBIT_Z + 1 * ENABLE_SELINUX, 262 OPTBIT_Q = OPTBIT_Z + 1 * ENABLE_SELINUX,
240 OPTBIT_c, /* 17 */ 263 OPTBIT_c, /* 16 */
241 OPTBIT_t, /* 18 */ 264 OPTBIT_t, /* 17 */
242 OPTBIT_u, /* 19 */ 265 OPTBIT_u, /* 18 */
243 OPTBIT_S = OPTBIT_c + 3 * ENABLE_FEATURE_LS_TIMESTAMPS, 266 OPTBIT_S = OPTBIT_c + 3 * ENABLE_FEATURE_LS_TIMESTAMPS,
244 OPTBIT_X, /* 21 */ 267 OPTBIT_X, /* 20 */
245 OPTBIT_r, /* 22 */ 268 OPTBIT_r, /* 21 */
246 OPTBIT_v, /* 23 */ 269 OPTBIT_v, /* 22 */
247 OPTBIT_L = OPTBIT_S + 4 * ENABLE_FEATURE_LS_SORTFILES, 270 OPTBIT_L = OPTBIT_S + 4 * ENABLE_FEATURE_LS_SORTFILES,
248 OPTBIT_H, /* 25 */ 271 OPTBIT_H, /* 24 */
249 OPTBIT_h = OPTBIT_L + 2 * ENABLE_FEATURE_LS_FOLLOWLINKS, 272 OPTBIT_h = OPTBIT_L + 2 * ENABLE_FEATURE_LS_FOLLOWLINKS,
250 OPTBIT_T = OPTBIT_h + 1 * ENABLE_FEATURE_HUMAN_READABLE, 273 OPTBIT_T = OPTBIT_h + 1 * ENABLE_FEATURE_HUMAN_READABLE,
251 OPTBIT_w, /* 28 */ 274 OPTBIT_w, /* 27 */
252 OPTBIT_full_time = OPTBIT_T + 2 * ENABLE_FEATURE_LS_WIDTH, 275 OPTBIT_full_time = OPTBIT_T + 2 * ENABLE_FEATURE_LS_WIDTH,
253 OPTBIT_dirs_first, 276 OPTBIT_dirs_first,
254 OPTBIT_color, /* 31 */ 277 OPTBIT_color, /* 30 */
255 /* with long opts, we use all 32 bits */ 278 OPTBIT_q = OPTBIT_color + 1, /* 31 */
279 OPTBIT_k = OPTBIT_q + 1, /* 32 */
280 /* with all options enabled, we use all 32 bits and even one extra bit! */
281 /* this works because -k is ignored, and getopt32 allows such "ignore" options past 31th bit */
256 282
257 OPT_F = (1 << OPTBIT_F) * ENABLE_FEATURE_LS_FILETYPES, 283 OPT_F = (1 << OPTBIT_F) * ENABLE_FEATURE_LS_FILETYPES,
258 OPT_p = (1 << OPTBIT_p) * ENABLE_FEATURE_LS_FILETYPES, 284 OPT_p = (1 << OPTBIT_p) * ENABLE_FEATURE_LS_FILETYPES,
@@ -274,6 +300,8 @@ enum {
274 OPT_full_time = (1 << OPTBIT_full_time ) * ENABLE_LONG_OPTS, 300 OPT_full_time = (1 << OPTBIT_full_time ) * ENABLE_LONG_OPTS,
275 OPT_dirs_first = (1 << OPTBIT_dirs_first) * ENABLE_LONG_OPTS, 301 OPT_dirs_first = (1 << OPTBIT_dirs_first) * ENABLE_LONG_OPTS,
276 OPT_color = (1 << OPTBIT_color ) * ENABLE_FEATURE_LS_COLOR, 302 OPT_color = (1 << OPTBIT_color ) * ENABLE_FEATURE_LS_COLOR,
303 OPT_q = (1 << OPTBIT_q),
304 //-k is ignored: OPT_k = (1 << OPTBIT_k),
277}; 305};
278 306
279/* 307/*
@@ -327,6 +355,7 @@ struct globals {
327#endif 355#endif
328 smallint exit_code; 356 smallint exit_code;
329 smallint show_dirname; 357 smallint show_dirname;
358 smallint tty_out;
330#if ENABLE_FEATURE_LS_WIDTH 359#if ENABLE_FEATURE_LS_WIDTH
331 unsigned terminal_width; 360 unsigned terminal_width;
332# define G_terminal_width (G.terminal_width) 361# define G_terminal_width (G.terminal_width)
@@ -343,16 +372,21 @@ struct globals {
343 setup_common_bufsiz(); \ 372 setup_common_bufsiz(); \
344 /* we have to zero it out because of NOEXEC */ \ 373 /* we have to zero it out because of NOEXEC */ \
345 memset(&G, 0, sizeof(G)); \ 374 memset(&G, 0, sizeof(G)); \
346 IF_FEATURE_LS_WIDTH(G_terminal_width = TERMINAL_WIDTH;) \ 375 IF_FEATURE_LS_WIDTH(G_terminal_width = ~0U;) \
347 IF_FEATURE_LS_TIMESTAMPS(time(&G.current_time_t);) \ 376 IF_FEATURE_LS_TIMESTAMPS(time(&G.current_time_t);) \
348} while (0) 377} while (0)
349 378
350#define ESC "\033" 379#define ESC "\033"
351 380
381static int G_isatty(void)
382{
383 if (!G.tty_out) /* not known yet? */
384 G.tty_out = isatty(STDOUT_FILENO) + 1;
385 return (G.tty_out == 2);
386}
352 387
353/*** Output code ***/ 388/*** Output code ***/
354 389
355
356/* FYI type values: 1:fifo 2:char 4:dir 6:blk 8:file 10:link 12:socket 390/* FYI type values: 1:fifo 2:char 4:dir 6:blk 8:file 10:link 12:socket
357 * (various wacky OSes: 13:Sun door 14:BSD whiteout 5:XENIX named file 391 * (various wacky OSes: 13:Sun door 14:BSD whiteout 5:XENIX named file
358 * 3/7:multiplexed char/block device) 392 * 3/7:multiplexed char/block device)
@@ -415,56 +449,93 @@ static char append_char(mode_t mode)
415} 449}
416#endif 450#endif
417 451
452/* Return the number of used columns.
453 * Note that only columnar output uses return value.
454 * -l and -1 modes don't care.
455 * coreutils 7.2 also supports:
456 * ls -b (--escape) = octal escapes (although it doesn't look like working)
457 * ls -N (--literal) = not escape at all
458 */
418static unsigned calc_name_len(const char *name) 459static unsigned calc_name_len(const char *name)
419{ 460{
420 unsigned len; 461 unsigned len;
421 uni_stat_t uni_stat; 462 uni_stat_t uni_stat;
422 463
423 // TODO: quote tab as \t, etc, if -Q 464 if (!(option_mask32 & (OPT_q|OPT_Q)))
424 name = printable_string2(&uni_stat, name); 465 return strlen(name);
425 466
426 if (!(option_mask32 & OPT_Q)) { 467 if (!(option_mask32 & OPT_Q)) {
468 /* the most likely branch: "ls" to tty (it auto-enables -q behavior) */
469 printable_string2(&uni_stat, name);
427 return uni_stat.unicode_width; 470 return uni_stat.unicode_width;
428 } 471 }
429 472
430 len = 2 + uni_stat.unicode_width; 473 len = 2 + strlen(name);
431 while (*name) { 474 while (*name) {
475 unsigned char ch = (unsigned char)*name;
476 if (ch < ' ' || ch > 0x7e) {
477 ch -= 7;
478 if (ch <= 6) {
479 /* quote chars 7..13 as \a,b,t,n,v,f,r */
480 goto two;
481 }
482 /* other chars <32 or >126 as \ooo octal */
483 len += 3;
484 goto next;
485 }
432 if (*name == '"' || *name == '\\') { 486 if (*name == '"' || *name == '\\') {
487 two:
433 len++; 488 len++;
434 } 489 }
490 next:
435 name++; 491 name++;
436 } 492 }
437 return len; 493 return len;
438} 494}
439
440/* Return the number of used columns.
441 * Note that only columnar output uses return value.
442 * -l and -1 modes don't care.
443 * coreutils 7.2 also supports:
444 * ls -b (--escape) = octal escapes (although it doesn't look like working)
445 * ls -N (--literal) = not escape at all
446 */
447static unsigned print_name(const char *name) 495static unsigned print_name(const char *name)
448{ 496{
449 unsigned len; 497 unsigned len;
450 uni_stat_t uni_stat; 498 uni_stat_t uni_stat;
451 499
452 // TODO: quote tab as \t, etc, if -Q 500 if (!(option_mask32 & (OPT_q|OPT_Q))) {
453 name = printable_string2(&uni_stat, name); 501 fputs_stdout(name);
502 return strlen(name);
503 }
454 504
455 if (!(option_mask32 & OPT_Q)) { 505 if (!(option_mask32 & OPT_Q)) {
506 /* the most likely branch: "ls" to tty (it auto-enables -q behavior) */
507 name = printable_string2(&uni_stat, name);
456 fputs_stdout(name); 508 fputs_stdout(name);
457 return uni_stat.unicode_width; 509 return uni_stat.unicode_width;
458 } 510 }
459 511
460 len = 2 + uni_stat.unicode_width; 512 len = 2 + strlen(name);
461 putchar('"'); 513 putchar('"');
462 while (*name) { 514 while (*name) {
463 if (*name == '"' || *name == '\\') { 515 unsigned char ch = (unsigned char)*name;
516 if (ch < ' ' || ch > 0x7e) {
464 putchar('\\'); 517 putchar('\\');
518 ch -= 7;
519 if (ch <= 6) {
520 /* quote chars 7..13 as \a,b,t,n,v,f,r */
521 ch = c_escape_conv_str07[1 + 3 * ch];
522 goto two;
523 }
524 /* other chars <32 or >126 as \ooo octal */
525 ch = (unsigned char)*name;
526 putchar('0' + (ch>>6));
527 putchar('0' + ((ch>>3) & 7));
528 ch = '0' + (ch & 7);
529 len += 3;
530 goto put_ch;
531 }
532 if (ch == '"' || ch == '\\') {
533 putchar('\\');
534 two:
465 len++; 535 len++;
466 } 536 }
467 putchar(*name); 537 put_ch:
538 putchar(ch);
468 name++; 539 name++;
469 } 540 }
470 putchar('"'); 541 putchar('"');
@@ -646,7 +717,7 @@ static void display_files(struct dnode **dn, unsigned nfiles)
646 unsigned i, ncols, nrows, row, nc; 717 unsigned i, ncols, nrows, row, nc;
647 unsigned column; 718 unsigned column;
648 unsigned nexttab; 719 unsigned nexttab;
649 unsigned column_width = 0; /* used only by coulmnal output */ 720 unsigned column_width = 0; /* used only by columnar output */
650 721
651 if (option_mask32 & (OPT_l|OPT_1)) { 722 if (option_mask32 & (OPT_l|OPT_1)) {
652 ncols = 1; 723 ncols = 1;
@@ -691,6 +762,11 @@ static void display_files(struct dnode **dn, unsigned nfiles)
691 } 762 }
692 nexttab = column + column_width; 763 nexttab = column + column_width;
693 column += display_single(dn[i]); 764 column += display_single(dn[i]);
765 } else {
766 /* if -w999999999, ncols can be very large */
767 //bb_error_msg(" col:%u ncol:%u i:%i", nc, ncols, i); sleep1();
768 /* without "break", we loop millions of times here */
769 break;
694 } 770 }
695 } 771 }
696 putchar('\n'); 772 putchar('\n');
@@ -1090,25 +1166,11 @@ int ls_main(int argc UNUSED_PARAM, char **argv)
1090 /* need to initialize since --color has _an optional_ argument */ 1166 /* need to initialize since --color has _an optional_ argument */
1091 const char *color_opt = color_str; /* "always" */ 1167 const char *color_opt = color_str; /* "always" */
1092#endif 1168#endif
1093#if ENABLE_LONG_OPTS
1094 static const char ls_longopts[] ALIGN1 =
1095 "full-time\0" No_argument "\xff"
1096 "group-directories-first\0" No_argument "\xfe"
1097 IF_FEATURE_LS_COLOR("color\0" Optional_argument "\xfd")
1098 ;
1099#endif
1100 1169
1101 INIT_G(); 1170 INIT_G();
1102 1171
1103 init_unicode(); 1172 init_unicode();
1104 1173
1105#if ENABLE_FEATURE_LS_WIDTH
1106 /* obtain the terminal width */
1107 G_terminal_width = get_terminal_width(STDIN_FILENO);
1108 /* go one less... */
1109 G_terminal_width--;
1110#endif
1111
1112 /* process options */ 1174 /* process options */
1113 opt = getopt32long(argv, "^" 1175 opt = getopt32long(argv, "^"
1114 ls_options 1176 ls_options
@@ -1144,6 +1206,29 @@ int ls_main(int argc UNUSED_PARAM, char **argv)
1144 exit(0); 1206 exit(0);
1145#endif 1207#endif
1146 1208
1209 /* ftpd secret backdoor? */
1210 if (ENABLE_FTPD && applet_name[0] == 'f') {
1211 /* dirs first are much nicer */
1212 opt = option_mask32 |= OPT_dirs_first;
1213 /* don't show SEcontext */
1214 IF_SELINUX(opt = option_mask32 &= ~OPT_Z;)
1215 /* do not query stdout about size and tty-ness */
1216 IF_FEATURE_LS_WIDTH(G_terminal_width = INT_MAX;)
1217 G.tty_out = 1; /* not a tty */
1218 goto skip_if_ftpd;
1219 }
1220
1221#if ENABLE_FEATURE_LS_WIDTH
1222 if ((int)G_terminal_width < 0) {
1223 /* obtain the terminal width */
1224 G_terminal_width = get_terminal_width(STDIN_FILENO);
1225 /* go one less... */
1226 G_terminal_width--;
1227 }
1228 if (G_terminal_width == 0) /* -w0 */
1229 G_terminal_width = INT_MAX; /* "infinite" */
1230#endif
1231
1147#if ENABLE_SELINUX 1232#if ENABLE_SELINUX
1148 if (opt & OPT_Z) { 1233 if (opt & OPT_Z) {
1149 if (!is_selinux_enabled()) 1234 if (!is_selinux_enabled())
@@ -1157,7 +1242,7 @@ int ls_main(int argc UNUSED_PARAM, char **argv)
1157 char *p = getenv("LS_COLORS"); 1242 char *p = getenv("LS_COLORS");
1158 /* LS_COLORS is unset, or (not empty && not "none") ? */ 1243 /* LS_COLORS is unset, or (not empty && not "none") ? */
1159 if (!p || (p[0] && strcmp(p, "none") != 0)) { 1244 if (!p || (p[0] && strcmp(p, "none") != 0)) {
1160 if (isatty(STDOUT_FILENO)) { 1245 if (G_isatty()) {
1161 /* check isatty() last because it's expensive (syscall) */ 1246 /* check isatty() last because it's expensive (syscall) */
1162 G_show_color = 1; 1247 G_show_color = 1;
1163 } 1248 }
@@ -1166,23 +1251,28 @@ int ls_main(int argc UNUSED_PARAM, char **argv)
1166 if (opt & OPT_color) { 1251 if (opt & OPT_color) {
1167 if (color_opt[0] == 'n') 1252 if (color_opt[0] == 'n')
1168 G_show_color = 0; 1253 G_show_color = 0;
1169 else switch (index_in_substrings(color_str, color_opt)) { 1254 else if (!G_show_color) {
1170 case 3: 1255 /* if() is not needed, but avoids extra isatty() if G_show_color is already set */
1171 case 4: 1256 /* Check --color=COLOR_OPT and maybe set show_color=1 */
1172 case 5: 1257 switch (index_in_substrings(color_str, color_opt)) {
1173 if (!is_TERM_dumb() && isatty(STDOUT_FILENO)) { 1258 case 3: // auto
1174 case 0: 1259 case 4: // tty
1175 case 1: 1260 case 5: // if-tty
1176 case 2: 1261 if (!is_TERM_dumb() && G_isatty()) {
1177 G_show_color = 1; 1262 case 0: // always
1263 case 1: // yes
1264 case 2: // force
1265 G_show_color = 1;
1266 }
1178 } 1267 }
1179 } 1268 }
1180 } 1269 }
1181#endif 1270#endif
1271 skip_if_ftpd:
1182 1272
1183 /* sort out which command line options take precedence */ 1273 /* sort out which command line options take precedence */
1184 if (ENABLE_FEATURE_LS_RECURSIVE && (opt & OPT_d)) 1274 if (ENABLE_FEATURE_LS_RECURSIVE && (opt & OPT_d))
1185 option_mask32 &= ~OPT_R; /* no recurse if listing only dir */ 1275 opt = option_mask32 &= ~OPT_R; /* no recurse if listing only dir */
1186 if (!(opt & OPT_l)) { /* not -l? */ 1276 if (!(opt & OPT_l)) { /* not -l? */
1187 if (ENABLE_FEATURE_LS_TIMESTAMPS && ENABLE_FEATURE_LS_SORTFILES) { 1277 if (ENABLE_FEATURE_LS_TIMESTAMPS && ENABLE_FEATURE_LS_SORTFILES) {
1188 /* when to sort by time? -t[cu] sorts by time even with -l */ 1278 /* when to sort by time? -t[cu] sorts by time even with -l */
@@ -1190,19 +1280,17 @@ int ls_main(int argc UNUSED_PARAM, char **argv)
1190 /* without -l, bare -c or -u enable sort too */ 1280 /* without -l, bare -c or -u enable sort too */
1191 /* (with -l, bare -c or -u just select which time to show) */ 1281 /* (with -l, bare -c or -u just select which time to show) */
1192 if (opt & (OPT_c|OPT_u)) { 1282 if (opt & (OPT_c|OPT_u)) {
1193 option_mask32 |= OPT_t; 1283 opt = option_mask32 |= OPT_t;
1194 } 1284 }
1195 } 1285 }
1196 } 1286 }
1197 1287
1198 /* choose a display format if one was not already specified by an option */ 1288 /* choose a display format if one was not already specified by an option */
1199 if (!(option_mask32 & (OPT_l|OPT_1|OPT_x|OPT_C))) 1289 if (!(opt & (OPT_l|OPT_1|OPT_x|OPT_C)))
1200 option_mask32 |= (isatty(STDOUT_FILENO) ? OPT_C : OPT_1); 1290 opt = option_mask32 |= (G_isatty() ? OPT_C : OPT_1);
1201 1291
1202 if (ENABLE_FTPD && applet_name[0] == 'f') { 1292 if (!(opt & OPT_q) && G_isatty())
1203 /* ftpd secret backdoor. dirs first are much nicer */ 1293 opt = option_mask32 |= OPT_q;
1204 option_mask32 |= OPT_dirs_first;
1205 }
1206 1294
1207 argv += optind; 1295 argv += optind;
1208 if (!argv[0]) 1296 if (!argv[0])