diff options
-rw-r--r-- | usr.bin/cat/cat.c | 19 |
1 files changed, 9 insertions, 10 deletions
diff --git a/usr.bin/cat/cat.c b/usr.bin/cat/cat.c index d40986b..b51e6a0 100644 --- a/usr.bin/cat/cat.c +++ b/usr.bin/cat/cat.c @@ -34,24 +34,23 @@ #include <stdio.h> #include <stdlib.h> -/* - * TODO FIXME (BUG): Print line by line (fix line clobbering issue) - */ static void cat(const char *pathname) { - char buf[4096]; + FILE *file; + char buf[64]; int fd; - fd = open(pathname, O_RDONLY); - if (fd < 0) { - printf("cat: could not open %s\n", pathname); + file = fopen(pathname, "r"); + if (file == NULL) { return; } - read(fd, buf, sizeof(buf)); - printf("%s", buf); - close(fd); + while (fgets(buf, sizeof(buf), file) != NULL) { + printf("%s", buf); + } + + fclose(file); } int |