9 static char buf
[DIRSIZ
+1];
12 // Find first character after last slash.
13 for(p
=path
+strlen(path
); p
>= path
&& *p
!= '/'; p
--)
17 // Return blank-padded name.
18 if(strlen(p
) >= DIRSIZ
)
20 memmove(buf
, p
, strlen(p
));
21 memset(buf
+strlen(p
), ' ', DIRSIZ
-strlen(p
));
33 if((fd
= open(path
, 0)) < 0){
34 printf(2, "ls: cannot open %s\n", path
);
38 if(fstat(fd
, &st
) < 0){
39 printf(2, "ls: cannot stat %s\n", path
);
46 printf(1, "%s %d %d %d\n", fmtname(path
), st
.type
, st
.ino
, st
.size
);
50 if(strlen(path
) + 1 + DIRSIZ
+ 1 > sizeof buf
){
51 printf(1, "ls: path too long\n");
57 while(read(fd
, &de
, sizeof(de
)) == sizeof(de
)){
60 memmove(p
, de
.name
, DIRSIZ
);
62 if(stat(buf
, &st
) < 0){
63 printf(1, "ls: cannot stat %s\n", buf
);
66 printf(1, "%s %d %d %d\n", fmtname(buf
), st
.type
, st
.ino
, st
.size
);
74 main(int argc
, char *argv
[])