50,6 → 50,24 |
|
static char *cmdname = "ls"; |
|
static inline off_t flen(const char *f) |
{ |
int fd; |
off_t size; |
|
fd = open(f, O_RDONLY); |
if (fd == -1) |
return 0; |
|
size = lseek(fd, 0, SEEK_END); |
close(fd); |
|
if (size < 0) |
size = 0; |
|
return size; |
} |
|
static unsigned int ls_scope(const char *path) |
{ |
int fd; |
96,7 → 114,7 |
ls_print_dir(dp->d_name); |
break; |
case LS_FILE: |
ls_print_file(dp->d_name); |
ls_print_file(dp->d_name, buff); |
break; |
case LS_BOGUS: |
/* Odd chance it was deleted from the time readdir() found |
120,19 → 138,19 |
|
static void ls_print_dir(const char *d) |
{ |
printf("%-40s\t<DIR>\n", d); |
printf("%-40s\t<dir>\n", d); |
|
return; |
} |
|
static void ls_print_file(const char *f) |
static void ls_print_file(const char *name, const char *pathname) |
{ |
printf("%-40s\n", f); |
printf("%-40s\t%llu\n", name, (long long) flen(pathname)); |
|
return; |
} |
|
void * help_cmd_ls(unsigned int level) |
void help_cmd_ls(unsigned int level) |
{ |
if (level == HELP_SHORT) { |
printf("`%s' lists files and directories.\n", cmdname); |
142,10 → 160,10 |
"working directory is used.\n", cmdname); |
} |
|
return CMD_VOID; |
return; |
} |
|
int * cmd_ls(char **argv) |
int cmd_ls(char **argv) |
{ |
unsigned int argc; |
unsigned int scope; |
174,7 → 192,7 |
free(buff); |
return CMD_FAILURE; |
case LS_FILE: |
ls_print_file(buff); |
ls_print_file(buff, buff); |
break; |
case LS_DIR: |
dirp = opendir(buff); |