1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-28 20:27:46 +00:00

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().
This commit is contained in:
Andreas Kling 2018-10-28 14:11:51 +01:00
parent 1d4af51250
commit 97726862dd
20 changed files with 140 additions and 46 deletions

View file

@ -9,7 +9,7 @@ int main(int argc, char** argv)
printf("usage: cat <file>\n");
return 1;
}
int fd = open(argv[1]);
int fd = open(argv[1], O_RDONLY);
if (fd == -1) {
printf("failed to open %s: %s\n", argv[1], strerror(errno));
return 1;

View file

@ -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;

View file

@ -3,7 +3,7 @@
int main(int c, char** v)
{
int fd = open("/proc/mm");
int fd = open("/proc/mm", O_RDONLY);
if (fd == -1) {
perror("failed to open /proc/mm");
return 1;

View file

@ -3,7 +3,7 @@
int main(int c, char** v)
{
int fd = open("/proc/summary");
int fd = open("/proc/summary", O_RDONLY);
if (fd == -1) {
perror("failed to open /proc/summary");
return 1;

View file

@ -147,7 +147,7 @@ int main(int, char**)
int linedx = 0;
linebuf[0] = '\0';
int fd = open("/dev/keyboard");
int fd = open("/dev/keyboard", O_RDONLY);
if (fd == -1) {
printf("failed to open /dev/keyboard :(\n");
return 1;