ls: print link targets when listing files

This commit is contained in:
Bananymous 2023-11-11 23:17:18 +02:00
parent 447da99f0b
commit 6e3f176457
1 changed files with 11 additions and 0 deletions

View File

@ -74,7 +74,18 @@ void list_directory(const char* path)
} }
if (list) if (list)
{
printf("%s %4d %4d %6d %s%s\e[m", mode_string(st.st_mode), st.st_uid, st.st_gid, st.st_size, color_string(st.st_mode), dirent->d_name); printf("%s %4d %4d %6d %s%s\e[m", mode_string(st.st_mode), st.st_uid, st.st_gid, st.st_size, color_string(st.st_mode), dirent->d_name);
if (S_ISLNK(st.st_mode))
{
char link_buffer[128];
ssize_t ret = readlinkat(dirfd(dirp), dirent->d_name, link_buffer, sizeof(link_buffer));
if (ret >= 0)
printf(" -> %.*s", ret, link_buffer);
else
perror("readlink");
}
}
else else
printf("%s%s\e[m", color_string(st.st_mode), dirent->d_name); printf("%s%s\e[m", color_string(st.st_mode), dirent->d_name);