Browse Source

ls: lstat args and make sure to check symlinks

K. Lange 4 years ago
parent
commit
96d661f8c8
1 changed files with 6 additions and 1 deletions
  1. 6 1
      apps/ls.c

+ 6 - 1
apps/ls.c

@@ -424,13 +424,18 @@ int main (int argc, char * argv[]) {
 			struct tfile * f = malloc(sizeof(struct tfile));
 
 			f->name = p;
-			int t = stat(p, &f->statbuf);
+			int t = lstat(p, &f->statbuf);
 
 			if (t < 0) {
 				printf("ls: cannot access %s: No such file or directory\n", p);
 				free(f);
 				out = 2;
 			} else {
+				if (S_ISLNK(f->statbuf.st_mode)) {
+					stat(p, &f->statbufl);
+					f->link = malloc(4096);
+					readlink(p, f->link, 4096);
+				}
 				list_insert(files, f);
 			}