X-Git-Url: https://git.ucc.asn.au/?a=blobdiff_plain;f=Usermode%2FApplications%2Fcat_src%2Fmain.c;h=3fae4c6c1f149fd716b1b0aa804ae70db11b0b34;hb=7f05e2b2f029c1e9709a9be14dbeae159bb2f1cc;hp=a7f3ab323e1a24334c92120883156739058112cc;hpb=72783d96c2d86024b92b55a718f06f33b3dc8ade;p=tpg%2Facess2.git diff --git a/Usermode/Applications/cat_src/main.c b/Usermode/Applications/cat_src/main.c index a7f3ab32..3fae4c6c 100644 --- a/Usermode/Applications/cat_src/main.c +++ b/Usermode/Applications/cat_src/main.c @@ -1,38 +1,38 @@ /* * Acess2 CAT command */ -#include #include #include #define BUF_SIZE 1024 +/** + * \fn int main(int argc, char *argv[]) + * \brief Entrypoint + */ int main(int argc, char *argv[]) { - int fd; int num; - char buf[BUF_SIZE+1]; + char buf[BUF_SIZE]; if(argc < 2) { printf("Usage: cat \n"); return -1; } - //printf("Contents of `%s'\n", argv[1]); - fd = open(argv[1], OPENFLAG_READ); - if(fd == -1) { + FILE *fp = fopen(argv[1], "r"); + if(!fp) { printf("Unable to open '%s' for reading\n", argv[1]); return -1; } do { - num = read(fd, BUF_SIZE, buf); - //printf("num = %i\n", num); - buf[num] = '\0'; - printf("%s", buf); + num = fread(buf, BUF_SIZE, 1, fp); + if(num < 0) break; + fwrite(buf, num, 1, stdout); } while(num == BUF_SIZE); - close(fd); + fclose(fp); printf("\n"); return 0;