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_ftype
== FTYPE_DIR
&& !flag
[(int) 'd'])
19 ls1(0, st
.st_ftype
== FTYPE_DIR
, st
.st_size
, path
);
23 lsdir(const char *path
, const char *prefix
)
26 char name
[MAXNAMELEN
];
30 if ((fd
= open(path
, O_RDONLY
)) < 0)
31 panic("open %s: %e", path
, fd
);
32 while ((n
= readn(fd
, &de
, sizeof de
)) == sizeof de
)
34 memcpy(name
, de
.de_name
, MAXNAMELEN
);
35 name
[de
.de_namelen
] = 0;
36 istat(de
.de_inum
, &st
);
37 ls1(prefix
, st
.st_ftype
==FTYPE_DIR
, st
.st_size
, name
);
40 panic("short read in directory %s", path
);
42 panic("error reading directory %s: %e", path
, n
);
46 ls1(const char *prefix
, bool isdir
, off_t size
, const char *name
)
51 fprintf(1, "%11d %c ", size
, isdir
? 'd' : '-');
53 if (prefix
[0] && prefix
[strlen(prefix
)-1] != '/')
57 fprintf(1, "%s%s", prefix
, sep
);
59 fprintf(1, "%s", name
);
60 if (flag
[(int) 'F'] && isdir
)
68 fprintf(1, "usage: ls [-dFl] [file...]\n");
73 umain(int argc
, char **argv
)
78 argstart(&argc
, argv
, &args
);
79 while ((i
= argnext(&args
)) >= 0)
93 for (i
= 1; i
< argc
; i
++)