mirror of
https://github.com/RGBCube/serenity
synced 2025-07-27 05:47:35 +00:00
Ls: Add single file support in short mode
This commit is contained in:
parent
b311257098
commit
07c356ce64
1 changed files with 26 additions and 9 deletions
|
@ -185,6 +185,19 @@ int do_dir(const char* path)
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
int print_filesystem_object_short(const char *path, const char *name, int *nprinted) {
|
||||||
|
struct stat st;
|
||||||
|
int rc = lstat(path, &st);
|
||||||
|
if (rc == -1) {
|
||||||
|
printf("lstat(%s) failed: %s\n", path, strerror(errno));
|
||||||
|
return 2;
|
||||||
|
}
|
||||||
|
|
||||||
|
*nprinted = print_name(st, name);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
int do_dir_short(const char* path)
|
int do_dir_short(const char* path)
|
||||||
{
|
{
|
||||||
int rows;
|
int rows;
|
||||||
|
@ -193,8 +206,15 @@ int do_dir_short(const char* path)
|
||||||
|
|
||||||
DIR* dirp = opendir(path);
|
DIR* dirp = opendir(path);
|
||||||
if (!dirp) {
|
if (!dirp) {
|
||||||
perror("opendir");
|
if (errno == ENOTDIR) {
|
||||||
return 1;
|
int nprinted;
|
||||||
|
print_filesystem_object_short(path, path, &nprinted);
|
||||||
|
printf("\n");
|
||||||
|
return 0;
|
||||||
|
} else {
|
||||||
|
perror("opendir");
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Vector<String, 1024> names;
|
Vector<String, 1024> names;
|
||||||
|
@ -209,19 +229,16 @@ int do_dir_short(const char* path)
|
||||||
closedir(dirp);
|
closedir(dirp);
|
||||||
|
|
||||||
int printed_on_row = 0;
|
int printed_on_row = 0;
|
||||||
|
int nprinted;
|
||||||
|
|
||||||
for (int i = 0; i < names.size(); ++i) {
|
for (int i = 0; i < names.size(); ++i) {
|
||||||
auto& name = names[i];
|
auto& name = names[i];
|
||||||
struct stat st;
|
|
||||||
char pathbuf[256];
|
char pathbuf[256];
|
||||||
sprintf(pathbuf, "%s/%s", path, name.characters());
|
sprintf(pathbuf, "%s/%s", path, name.characters());
|
||||||
int rc = lstat(pathbuf, &st);
|
|
||||||
if (rc == -1) {
|
|
||||||
printf("lstat(%s) failed: %s\n", pathbuf, strerror(errno));
|
|
||||||
return 2;
|
|
||||||
}
|
|
||||||
|
|
||||||
int nprinted = print_name(st, name.characters());
|
if (print_filesystem_object_short(pathbuf, name.characters(), &nprinted) == 2) {
|
||||||
|
return 2;
|
||||||
|
}
|
||||||
int column_width = 14;
|
int column_width = 14;
|
||||||
printed_on_row += column_width;
|
printed_on_row += column_width;
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue