X-Git-Url: https://git.librecmc.org/?a=blobdiff_plain;ds=inline;f=ls.c;h=94c73b377433ab8c1a8984069f7f75028f09b1dd;hb=f3b2b52b589bccae28b1740c155733028f2b8fd5;hp=004c2a7735178b6c32380702fed662e372d2702b;hpb=3e07541e5fec215e2d61deb48e3dc1bb460babd1;p=oweals%2Fbusybox.git diff --git a/ls.c b/ls.c index 004c2a773..94c73b377 100644 --- a/ls.c +++ b/ls.c @@ -127,6 +127,7 @@ #define SPLIT_DIR 0 #define SPLIT_FILE 1 +#define SPLIT_SUBDIR 2 #define TYPEINDEX(mode) (((mode) >> 12) & 0x0f) #define TYPECHAR(mode) ("0pcCd?bB-?l?s???" [TYPEINDEX(mode)]) @@ -180,7 +181,7 @@ static int my_stat(struct dnode *cur) #ifdef BB_FEATURE_LS_FOLLOWLINKS if (follow_links == TRUE) { if (stat(cur->fullname, &cur->dstat)) { - errorMsg("%s: %s\n", cur->fullname, strerror(errno)); + error_msg("%s: %s\n", cur->fullname, strerror(errno)); status = EXIT_FAILURE; free(cur->fullname); free(cur); @@ -189,7 +190,7 @@ static int my_stat(struct dnode *cur) } else #endif if (lstat(cur->fullname, &cur->dstat)) { - errorMsg("%s: %s\n", cur->fullname, strerror(errno)); + error_msg("%s: %s\n", cur->fullname, strerror(errno)); status = EXIT_FAILURE; free(cur->fullname); free(cur); @@ -236,11 +237,16 @@ static void nexttabstop( void ) } /*----------------------------------------------------------------------*/ +static int is_subdir(struct dnode *dn) +{ + return (S_ISDIR(dn->dstat.st_mode) && strcmp(dn->name, ".") != 0 && + strcmp(dn->name, "..") != 0); +} + int countdirs(struct dnode **dn, int nfiles) { int i, dirs; - /* count how many dirs and regular files there are */ if (dn==NULL || nfiles < 1) return(0); dirs= 0; for (i=0; idstat.st_mode)) { dnp[d++]= dn[i]; } /* else skip the file */ + } else if (which == SPLIT_SUBDIR) { + if (is_subdir(dn[i])) { + dnp[d++]= dn[i]; + } /* else skip the file or dir */ } else { if (!(S_ISDIR(dn[i]->dstat.st_mode))) { dnp[d++]= dn[i]; @@ -455,8 +481,8 @@ void showdirs(struct dnode **dn, int ndirs) #ifdef BB_FEATURE_LS_RECURSIVE if (disp_opts & DISP_RECURSIVE) { /* recursive- list the sub-dirs */ - dnd= splitdnarray(subdnp, nfiles, SPLIT_DIR); - dndirs= countdirs(subdnp, nfiles); + dnd= splitdnarray(subdnp, nfiles, SPLIT_SUBDIR); + dndirs= countsubdirs(subdnp, nfiles); if (dndirs > 0) { #ifdef BB_FEATURE_LS_SORTFILES shellsort(dnd, dndirs); @@ -485,7 +511,7 @@ struct dnode **list_dir(char *path) nfiles= 0; dir = opendir(path); if (dir == NULL) { - errorMsg("%s: %s\n", path, strerror(errno)); + error_msg("%s: %s\n", path, strerror(errno)); status = EXIT_FAILURE; return(NULL); /* could not open the dir */ } @@ -531,7 +557,7 @@ int list_single(struct dnode *dn) char *filetime; time_t ttime, age; #endif -#if defined (BB_FEATURE_LS_FILETYPES) || defined (BB_FEATURE_LS_USERNAME) +#if defined (BB_FEATURE_LS_FILETYPES) struct stat info; #endif #ifdef BB_FEATURE_LS_FILETYPES @@ -565,7 +591,7 @@ int list_single(struct dnode *dn) column += 5; break; case LIST_MODEBITS: - fprintf(stdout, "%10s", (char *)modeString(dn->dstat.st_mode)); + fprintf(stdout, "%10s", (char *)mode_string(dn->dstat.st_mode)); column += 10; break; case LIST_NLINKS: @@ -574,28 +600,19 @@ int list_single(struct dnode *dn) break; case LIST_ID_NAME: #ifdef BB_FEATURE_LS_USERNAME - { - memset(&info, 0, sizeof(struct stat)); - memset(scratch, 0, sizeof(scratch)); - if (!stat(dn->fullname, &info)) { - my_getpwuid(scratch, info.st_uid); - } - if (*scratch) { - fprintf(stdout, "%-8.8s ", scratch); - } else { - fprintf(stdout, "%-8d ", dn->dstat.st_uid); - } - memset(scratch, 0, sizeof(scratch)); - if (info.st_ctime != 0) { - my_getgrgid(scratch, info.st_gid); - } - if (*scratch) { - fprintf(stdout, "%-8.8s", scratch); - } else { - fprintf(stdout, "%-8d", dn->dstat.st_gid); - } + memset(scratch, 0, sizeof(scratch)); + my_getpwuid(scratch, dn->dstat.st_uid); + if (*scratch) + fprintf(stdout, "%-8.8s ", scratch); + else + fprintf(stdout, "%-8d ", dn->dstat.st_uid); + memset(scratch, 0, sizeof(scratch)); + my_getgrgid(scratch, dn->dstat.st_gid); + if (*scratch) + fprintf(stdout, "%-8.8s", scratch); + else + fprintf(stdout, "%-8d", dn->dstat.st_gid); column += 17; - } break; #endif case LIST_ID_NUMERIC: @@ -861,5 +878,4 @@ extern int ls_main(int argc, char **argv) print_usage_message: usage(ls_usage); - return(FALSE); }