Skip to content
Snippets Groups Projects
Commit 3dcf889c authored by rsc's avatar rsc
Browse files

cleanup

parent 6bf2e5c8
No related branches found
No related tags found
No related merge requests found
......@@ -3,10 +3,6 @@
#include "user.h"
#include "fs.h"
char buf[512];
struct stat st;
struct dirent dirent;
void
pname(char *n)
{
......@@ -22,10 +18,11 @@ pname(char *n)
int
main(int argc, char *argv[])
{
char buf[512], *p;
int fd;
uint off;
uint sz;
char *p;
uint off, sz;
struct dirent de;
struct stat st;
if(argc > 2){
puts("Usage: ls [dir]\n");
......@@ -58,12 +55,12 @@ main(int argc, char *argv[])
break;
case T_DIR:
sz = st.size;
for(off = 0; off < sz; off += sizeof(struct dirent)) {
if(read(fd, &dirent, sizeof dirent) != sizeof dirent) {
for(off = 0; off < sz; off += sizeof(de)) {
if(read(fd, &de, sizeof(de)) != sizeof(de)) {
printf(1, "ls: read error\n");
break;
}
if(dirent.inum != 0) {
if(de.inum != 0) {
p = buf;
if(argc == 2) {
strcpy(p, argv[1]);
......@@ -71,13 +68,14 @@ main(int argc, char *argv[])
if(*(p-1) != '/')
*p++ = '/';
}
strcpy(p, dirent.name);
memmove(p, de.name, DIRSIZ);
p[DIRSIZ] = 0;
if(stat(buf, &st) < 0) {
printf(1, "stat: failed %s\n", dirent.name);
printf(1, "stat: failed %s\n", de.name);
continue;
}
pname(dirent.name);
printf(1, "%d %d %d\n", st.type, dirent.inum, st.size);
pname(de.name);
printf(1, "%d %d %d\n", st.type, de.inum, st.size);
}
}
break;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment