diff options
author | Andreas Kling <awesomekling@gmail.com> | 2018-10-28 14:11:51 +0100 |
---|---|---|
committer | Andreas Kling <awesomekling@gmail.com> | 2018-10-28 14:11:51 +0100 |
commit | 97726862dd699cb0843b9d700789e30cf6625dc9 (patch) | |
tree | 07fd74e8e0e3b462ac5ab32994340c5090711348 /Userland/ls.cpp | |
parent | 1d4af5125078b097b9ab843d53ba50a0d9b1de5e (diff) | |
download | serenity-97726862dd699cb0843b9d700789e30cf6625dc9.zip |
Add basic symlink support.
- sys$readlink + readlink()
- Add a /proc/PID/exe symlink to the process's executable.
- Print symlink contents in ls output.
- Some work on plumbing options into VFS::open().
Diffstat (limited to 'Userland/ls.cpp')
-rw-r--r-- | Userland/ls.cpp | 17 |
1 files changed, 14 insertions, 3 deletions
diff --git a/Userland/ls.cpp b/Userland/ls.cpp index 30983147d9..ad26e020ad 100644 --- a/Userland/ls.cpp +++ b/Userland/ls.cpp @@ -65,7 +65,9 @@ int main(int c, char** v) const char* endColor = ""; if (colorize) { - if (S_ISDIR(st.st_mode)) + if (S_ISLNK(st.st_mode)) + beginColor = "\033[36;1m"; + else if (S_ISDIR(st.st_mode)) beginColor = "\033[34;1m"; else if (st.st_mode & 0111) beginColor = "\033[32;1m"; @@ -76,10 +78,19 @@ int main(int c, char** v) printf("%s%s%s", beginColor, de->d_name, endColor); - if (S_ISDIR(st.st_mode)) + if (S_ISLNK(st.st_mode)) { + char linkbuf[256]; + ssize_t nread = readlink(pathbuf, linkbuf, sizeof(linkbuf)); + if (nread < 0) { + perror("readlink failed"); + } else { + printf(" -> %s", linkbuf); + } + } else if (S_ISDIR(st.st_mode)) { printf("/"); - else if (st.st_mode & 0111) + } else if (st.st_mode & 0111) { printf("*"); + } printf("\n"); } return 0; |