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,14 → 138,14 |
|
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; |
} |
164,7 → 182,7 |
if (argc == 1) |
getcwd(buff, PATH_MAX); |
else |
strncpy(buff, argv[1], PATH_MAX); |
str_cpy(buff, PATH_MAX, argv[1]); |
|
scope = ls_scope(buff); |
|
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); |