diff options
Diffstat (limited to 'userspace')
| -rw-r--r-- | userspace/fd.c | 3 | ||||
| -rw-r--r-- | userspace/newcalls.h (renamed from userspace/snake2.h) | 5 | ||||
| -rw-r--r-- | userspace/piper.c | 48 | ||||
| -rw-r--r-- | userspace/snake2.c | 2 |
4 files changed, 27 insertions, 31 deletions
diff --git a/userspace/fd.c b/userspace/fd.c index 09cb28e..80ffd20 100644 --- a/userspace/fd.c +++ b/userspace/fd.c @@ -3,7 +3,6 @@ int main() { - dup(stdout); +// dup(stdout); printf("dup\n"); - } diff --git a/userspace/snake2.h b/userspace/newcalls.h index d4c47a8..9bc55a5 100644 --- a/userspace/snake2.h +++ b/userspace/newcalls.h @@ -2,9 +2,14 @@ // this syscall will be moved to newlib later! #define SYSCALL_CLONE 83 +#define SYSCALL_PIPE 84 int _clone(void) { return syscall(SYSCALL_CLONE,0,0,0); } +int _pipe(uint32_t fds[2]) +{ + return syscall(SYSCALL_PIPE,fds,0,0); +} // 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); } - } diff --git a/userspace/snake2.c b/userspace/snake2.c index 3b179ac..6fbd092 100644 --- a/userspace/snake2.c +++ b/userspace/snake2.c @@ -1,5 +1,5 @@ #include <stdio.h> -#include "snake2.h" +#include "newcalls.h" static char lastc='d'; |
