OrionUserland
Barry Removing binaries f8ba6df (2 years, 4 months ago)diff --git a/cat/main.c b/cat/main.c index f1570bc..17b7761 100644 --- a/cat/main.c +++ b/cat/main.c @@ -6,13 +6,14 @@ #include <sys/stat.h> #include <dirent.h> +#define BUF_SIZE (4096 * 4) + /* Main function */ int main(int argc, char *argv[]) { int fd, sz, i; - char *buf; - struct stat statbuf; + char buf[BUF_SIZE]; if (argc < 2) { printf("Usage: %s <file> [<file>...]\n"); @@ -27,14 +28,15 @@ main(int argc, char *argv[]) continue; } - stat(argv[i], &statbuf); - if (S_ISREG(statbuf.mode)) { - sz = lseek(fd, 0, SEEK_END); - buf = malloc(sz + 1); - lseek(fd, 0, SEEK_SET); - read(fd, buf, sz); - printf("%s", buf); - free(buf); + while ((sz = read(fd, buf, sizeof(buf))) > 0) { + if (write(STDOUT_FILENO, buf, sz) < 0) { + printf("%s: write: ", argv[0]); + perror(NULL); + } + } + if (sz < 0) { + printf("%s: read: ", argv[0]); + perror(NULL); } close(fd);