summaryrefslogtreecommitdiff
path: root/userspace/piper.c
diff options
context:
space:
mode:
authorMiguel <m.i@gmx.at>2018-09-20 10:46:00 +0200
committerMiguel <m.i@gmx.at>2018-09-20 10:46:00 +0200
commit763f85c55fdb5a2c4f5bf98e4989a69d27da6e4f (patch)
treeb9be12d5c20ee1c5cc006b09a6a1584880c15928 /userspace/piper.c
parent631fdbefc89a6202c5b8e2bf0e15a6ca7df809ef (diff)
pipes do not work :(
Diffstat (limited to 'userspace/piper.c')
-rw-r--r--userspace/piper.c48
1 files changed, 20 insertions, 28 deletions
diff --git a/userspace/piper.c b/userspace/piper.c
index 73b9516..e433a5c 100644
--- a/userspace/piper.c
+++ b/userspace/piper.c
@@ -1,42 +1,34 @@
#include <stdio.h>
+#include "newcalls.h"
int main()
{
- setvbuf(stdout,NULL,_IONBF,0);
- /*
- FILE *f=fopen("~testpipe","rw");
+ int fds[2];
+ _pipe(fds);
+
+ printf("opened pipe / in fd=%d,out fd=%d\n",fds[0],fds[1]);
int pid=_fork();
- if(pid==0)
+ if(pid)
{
- char buf[2];
- fread(buf,1,1,f);
- printf("[%c]\n",buf[0]);
- while(1);
- }
+ while(1) // read forever from our pipe and echo to stdout
+ {
+ char buf[256];
+ int len=fread(buf,1,255,fds[0]);
+ printf("%s",buf);
+ }
- else
- {
- char buf[]="666";
- fwrite(buf,1,1,f);
- printf("written\n");
- while(1);
}
- */
- int f=_open("~testpipe","RW");
- int pid=_fork();
- if(pid==0)
- {
- char buf[2];
- while(_read(f,buf,1))printf("%c",buf[0]);
- }
-
else
{
- char buf[]="666 the number of the beast";
- _write(f,buf,27);
- printf("written\n");
+
+ // write to our pipe
+ fwrite("Hello\n",1,6,fds[1]);
+ fwrite("Bello\n",1,6,fds[1]);
+ fwrite("Gello\n",1,6,fds[1]);
+
+ // hang forever
+ while(1);
}
-
}