ls: lstat args and make sure to check symlinks

This commit is contained in:
K. Lange 2018-10-11 19:45:19 +09:00
parent 00fd9c5e08
commit 96d661f8c8

View File

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