提交 2e51e12f 创建 作者: rsc's avatar rsc

make ls work on directories

上级 3fd50978
...@@ -22,6 +22,3 @@ ide.c: synchronous disk write -> polling disk write. search for ...@@ -22,6 +22,3 @@ ide.c: synchronous disk write -> polling disk write. search for
fs.c: split all name operations off in name.c? (starting with namei but move fs.c: split all name operations off in name.c? (starting with namei but move
wdir keep in fs.c) wdir keep in fs.c)
ls.c: apply tim's patch
...@@ -25,6 +25,7 @@ main(int argc, char *argv[]) ...@@ -25,6 +25,7 @@ main(int argc, char *argv[])
int fd; int fd;
uint off; uint off;
uint sz; uint sz;
char *p;
if(argc > 2){ if(argc > 2){
puts("Usage: ls [dir]\n"); puts("Usage: ls [dir]\n");
...@@ -63,8 +64,15 @@ main(int argc, char *argv[]) ...@@ -63,8 +64,15 @@ main(int argc, char *argv[])
break; break;
} }
if(dirent.inum != 0) { if(dirent.inum != 0) {
// xxx prepend to name the pathname supplied to ls (e.g. .. in ls ..) p = buf;
if(stat (dirent.name, &st) < 0) { if(argc == 2) {
strcpy(p, argv[1]);
p += strlen(p);
if(*(p-1) != '/')
*p++ = '/';
}
strcpy(p, dirent.name);
if(stat(buf, &st) < 0) {
printf(1, "stat: failed %s\n", dirent.name); printf(1, "stat: failed %s\n", dirent.name);
continue; continue;
} }
......
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论