diff options
| author | Miguel <m.i@gmx.at> | 2018-09-15 00:30:36 +0200 |
|---|---|---|
| committer | Miguel <m.i@gmx.at> | 2018-09-15 00:30:36 +0200 |
| commit | fe7d0332267ef1e62153b685d2b5574ce624a4bc (patch) | |
| tree | 0c5bb5af4275b55b141ff598d9daedd99eb12603 /userspace | |
| parent | c4b20a0ebbde1348e1e085e2ea3be35345d92b7c (diff) | |
reading ext2 files and using our abstractions
Diffstat (limited to 'userspace')
| -rw-r--r-- | userspace/cat.c | 8 | ||||
| -rw-r--r-- | userspace/piper.c | 21 | ||||
| -rw-r--r-- | userspace/test.txt | 2 |
3 files changed, 29 insertions, 2 deletions
diff --git a/userspace/cat.c b/userspace/cat.c index 39d994f..5b419ca 100644 --- a/userspace/cat.c +++ b/userspace/cat.c @@ -3,7 +3,11 @@ int main(int argc, char **argv) { FILE *f; - if(argc>1)f=fopen(argv[1],"r"); + if(argc>1){ + char buf[256]; + sprintf(buf,"%s/%s",getenv("PWD"),argv[1]); + f=fopen(buf,"r"); + } else f=stdin; setvbuf(stdin,NULL,_IONBF,0); @@ -11,7 +15,7 @@ int main(int argc, char **argv) char c; - printf("-- read from file byte by byte --\n"); + printf("-- reading from file byte by byte --\n\n"); while(fread(&c,1,1,f)) { diff --git a/userspace/piper.c b/userspace/piper.c new file mode 100644 index 0000000..2272f96 --- /dev/null +++ b/userspace/piper.c @@ -0,0 +1,21 @@ +#include <stdio.h> +int main() +{ + int pid=_fork(); + FILE *f=fopen("~testpipe","rw"); + + setvbuf(f,NULL,_IONBF,0); + + if(pid==0) + { + char buf[2]; + fread(f,buf,1,1); + printf("[%c]\n",buf[0]); + } + else + { + char buf="666"; + fwrite(f,buf,1,1); + printf("written\n"); + } +} diff --git a/userspace/test.txt b/userspace/test.txt index d44e39c..7a22897 100644 --- a/userspace/test.txt +++ b/userspace/test.txt @@ -2,4 +2,6 @@ HELLO THIS IS A TEXTFILE USED FOR TESTING THE FOOL OS EXT2 RAM IMAGE TRY TO READ ME! + [41;37m [COLOR CODES ARE SUPPORTED TOO FROM FILES] [37;40m + BYE |
