diff --git a/src/cat.c b/src/cat.c index 639bbb8..d9f1672 100644 --- a/src/cat.c +++ b/src/cat.c @@ -79,26 +79,32 @@ int main(int argc, char **argv) /* i < argc is obvious; steps through all provided args. */ - /* !argc-optind && !newbuf is a little less so - it allows this loop to run once if the user provides no paths */ - for(i = optind; (i < argc) || (((argc - optind) == 0) && !newbuf); i++, newbufsize = 0) + /* !argc-optind && !c is a little less so - it allows this loop to run once if the user provides no paths */ + do { if( !(fd = file_open(argv[i], "r"))) { throw(FOPEN_FAIL, mastrcat(argv[0], mastrcat(": could not open file ", argv[i]))); } - - newbuf = file_read(fd, &newbufsize); + if(pars[U]) { - fwrite(newbuf, sizeof(char), newbufsize, stdout); - free(newbuf); - continue; + for(; (c = fgetc(fd)) != EOF; c = 0) + { + fputc(c, stdout); + } } - buf = concat(buf, newbuf, bufsize, newbufsize); - bufsize += newbufsize; - free(newbuf); - + else + { + newbuf = file_read(fd, &newbufsize); + buf = concat(buf, newbuf, bufsize, newbufsize); + bufsize += newbufsize; + free(newbuf); + } + + i++, newbufsize = 0; } + while((i < argc) || (((argc - optind) == 0) && !c)); if(!pars[U]) {