diff --git a/myls.c b/myls.c new file mode 100644 index 0000000..fa2ddd4 --- /dev/null +++ b/myls.c @@ -0,0 +1,46 @@ +#define __LIBRARY__ +#include +#include +#include +#include +#include +#include +#include +#define O_RDONLY 00 +struct linux_dirent { + long d_ino; + off_t d_off; + unsigned short d_reclen; + char d_name[1024]; +}; +char buf[512]; +_syscall3(int,getdents, int,fd,struct linux_dirent *,dirp,unsigned long,len) +_syscall3(int ,open,const char *,filename,int, flag,int, mode) +_syscall1(int,close,int,fildes) +_syscall3(int,write,int ,fd,const char *, buf, off_t ,count) +#define MAX_NUMBER_BYTES 1024 +#define MSG_LEN 256 + + +int printf(const char *fmt,...) +{ + write(2,fmt,strlen(fmt)); +} +void test_getdents(void){ + int fd, nread, bpos; + struct linux_dirent *dirp, *tmp; + dirp = (struct linux_dirent *)buf; + fd = open(".", O_RDONLY,0); + nread = getdents(fd, dirp, 512); + for(bpos = 0; bpos < nread;){ + tmp = (struct linux_dirent *)(buf + bpos); + printf( tmp->d_name); + bpos += tmp->d_reclen; + } + close(fd); +} + +int main(int argc, char *argv[]){ + test_getdents(); + return 0; +}