5 void lsdir(const char*, const char*);
6 void ls1(const char*, bool, off_t
, const char*);
9 ls(const char *path
, const char *prefix
)
14 if ((r
= stat(path
, &st
)) < 0)
15 panic("stat %s: %e", path
, r
);
16 if (st
.st_isdir
&& !flag
['d'])
19 ls1(0, st
.st_isdir
, st
.st_size
, path
);
23 lsdir(const char *path
, const char *prefix
)
28 if ((fd
= open(path
, O_RDONLY
)) < 0)
29 panic("open %s: %e", path
, fd
);
30 while ((n
= readn(fd
, &f
, sizeof f
)) == sizeof f
)
32 ls1(prefix
, f
.f_type
==FTYPE_DIR
, f
.f_size
, f
.f_name
);
34 panic("short read in directory %s", path
);
36 panic("error reading directory %s: %e", path
, n
);
40 ls1(const char *prefix
, bool isdir
, off_t size
, const char *name
)
45 fprintf(1, "%11d %c ", size
, isdir
? 'd' : '-');
47 if (prefix
[0] && prefix
[strlen(prefix
)-1] != '/')
51 fprintf(1, "%s%s", prefix
, sep
);
53 fprintf(1, "%s", name
);
54 if(flag
['F'] && isdir
)
62 fprintf(1, "usage: ls [-dFl] [file...]\n");
67 umain(int argc
, char **argv
)
77 flag
[(uint8_t)ARGC()]++;
84 for (i
=0; i
<argc
; i
++)