X-Git-Url: https://git.ucc.asn.au/?a=blobdiff_plain;f=Usermode%2FApplications%2Fcat_src%2Fmain.c;h=45a8d1b340936e6f74fe2d7d4613199db2bc9b9c;hb=733b37c90c20a76ec81c04431e8bc5224f053e28;hp=8fc8463fc1a2c1aeb7df003c5f2a0f79e59b7766;hpb=1a96e0dd77d6922078edd703fc7c2e809b9499b8;p=tpg%2Facess2.git diff --git a/Usermode/Applications/cat_src/main.c b/Usermode/Applications/cat_src/main.c index 8fc8463f..45a8d1b3 100644 --- a/Usermode/Applications/cat_src/main.c +++ b/Usermode/Applications/cat_src/main.c @@ -1,7 +1,6 @@ /* * Acess2 CAT command */ -#include #include #include @@ -13,28 +12,27 @@ */ int main(int argc, char *argv[]) { - int fd; - int num; - char buf[BUF_SIZE+1]; + size_t num; + char buf[BUF_SIZE]; if(argc < 2) { printf("Usage: cat \n"); return -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); - buf[num] = '\0'; - printf("%s", buf); + num = fread(buf, 1, BUF_SIZE, fp); + if(num <= 0) break; + fwrite(buf, 1, num, stdout); } while(num == BUF_SIZE); - close(fd); + fclose(fp); printf("\n"); return 0;