From a215862bb9f770201e94773e4071fe2c53a8a9ba Mon Sep 17 00:00:00 2001 From: prnmxfqg4 Date: Thu, 7 Jul 2022 12:51:14 +0800 Subject: [PATCH] ADD file via upload --- myls.c~ | 47 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 47 insertions(+) create mode 100644 myls.c~ diff --git a/myls.c~ b/myls.c~ new file mode 100644 index 0000000..1946ddc --- /dev/null +++ b/myls.c~ @@ -0,0 +1,47 @@ +#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;){ + printf("gasdg"); + 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; +}