diff options
Diffstat (limited to 'userspace/cat.c')
| -rw-r--r-- | userspace/cat.c | 16 |
1 files changed, 11 insertions, 5 deletions
diff --git a/userspace/cat.c b/userspace/cat.c index 800a14b..39d994f 100644 --- a/userspace/cat.c +++ b/userspace/cat.c @@ -1,18 +1,24 @@ #include <stdio.h> -int main() +int main(int argc, char **argv) { + FILE *f; + if(argc>1)f=fopen(argv[1],"r"); + else f=stdin; + + setvbuf(stdin,NULL,_IONBF,0); + setvbuf(stdout,NULL,_IONBF,0); char c; - printf("-- read from stderr byte by byte --\n"); + printf("-- read from file byte by byte --\n"); - while(_poll(2)){ - fread(&c,1,1,stderr); + while(fread(&c,1,1,f)) + { printf("%c",c); } - printf("\n-- no more data on stderr --\n"); + printf("\n-- no more data on this file --\n"); return 0; } |
