Prog#238: ls command


#1
/*
ls command
Program#238
*/
#include<stdio.h>
main(int argc,char *argv[])
{
int i,p;
union xyz{
struct lsc{
int mode;
char fn [14];
}a;
char b[sizeof(struct lsc)];
};
union xyz m;
if(argc!=2)
{
printf("error: no.of arg");
return 0;
}
p=open(argv[1], 0);
if(p==-1)
{
printf("file open error");
return 0;
}
i=read(p,m.b,sizeof(struct lsc));
while(i>0)
{
printf("%d %s", m.a.mode, m.a.fn);
i=read(p,m.b,sizeof(struct lsc));
}
close(p);
}