From c4b20a0ebbde1348e1e085e2ea3be35345d92b7c Mon Sep 17 00:00:00 2001 From: Miguel Date: Fri, 14 Sep 2018 23:10:16 +0200 Subject: tuining userspace and files --- userspace/cat.c | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) (limited to 'userspace/cat.c') 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 -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; } -- cgit v1.2.3