From 3d212b0252fa9290c273ac306adc9d98bd1ed3db Mon Sep 17 00:00:00 2001 From: prnmxfqg4 Date: Thu, 7 Jul 2022 12:50:47 +0800 Subject: [PATCH] ADD file via upload --- mycat.c | 55 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 55 insertions(+) create mode 100644 mycat.c diff --git a/mycat.c b/mycat.c new file mode 100644 index 0000000..6a78e9d --- /dev/null +++ b/mycat.c @@ -0,0 +1,55 @@ +#define __LIBRARY__ +#include +#include +#include +#include +#include +#include +#include +FILE __stdout; +#define O_RDONLY 00 +#define MSG_LEN 256 +#define MAX_NUMBER_BYTES 1024 +_syscall3(int,open,const char *,filename,int, flag,int, mode) +_syscall3(int,write,int ,fd,const char *, buf, off_t ,count) +_syscall3(int,read,int ,fildes,char *, buf, off_t ,count) +_syscall0(int,sync) +_syscall1(int,close,int,fildes) +_syscall3(int ,vsprintf1,char *, buf, const char *, fmt, va_list ,args) + +static char printbuf[1024]; +int printf(const char *fmt,...) +{ + write(2,fmt,strlen(fmt)); +} +int main(int argc, char **argv) +{ + int num, fd; + char msg[MSG_LEN+1]; + + if (argc == 1) + return EXIT_FAILURE; + + /* open the file */ + if ((fd=open(argv[1], O_RDONLY, 0)) < 0) + return EXIT_FAILURE; + do{ + /* read the file */ + if ((num = read(fd, msg, MSG_LEN)) < 0) { + close(fd); + return EXIT_FAILURE; + } else if (num == 0) { + break; + } + /* display on screen */ + msg[num] = '\0'; + printf( msg); + }while(1); + printf("\n"); + + /* exit */ + close(fd); + sync(); + + return EXIT_SUCCESS; +}