summaryrefslogtreecommitdiff
path: root/test/pipetest.c
diff options
context:
space:
mode:
authorMiguel <m.i@gmx.at>2018-09-13 14:32:28 +0200
committerMiguel <m.i@gmx.at>2018-09-13 14:32:28 +0200
commitf844fafd324fbf4c7a986df2f0814f2e2d93bcd8 (patch)
tree30253b4757630124b23b29e8f09c3c77da07b423 /test/pipetest.c
parentb9f10c8a65a24db1c6a52d9df67230b75fa38d1a (diff)
thinking about syscalls and pipes
Diffstat (limited to 'test/pipetest.c')
-rw-r--r--test/pipetest.c54
1 files changed, 54 insertions, 0 deletions
diff --git a/test/pipetest.c b/test/pipetest.c
new file mode 100644
index 0000000..e848049
--- /dev/null
+++ b/test/pipetest.c
@@ -0,0 +1,54 @@
+#include <stdio.h>
+#include <errno.h>
+#include <string.h>
+
+int main(int argc, char *argv[])
+{
+ printf("LINUX PIPE TEST\n");
+
+ if(argc<=1)
+ {
+ printf("one argument please [read|write]\n");
+ }
+
+ if(!strcmp(argv[1],"read"))
+ {
+ FILE *p=fopen("./testpipe","r");
+ printf("opened for reading\n");
+ printf("feof: %i\n",feof(p));
+
+ if(p==NULL)
+ {
+ int err=errno;
+ printf("Opening pipe failed with errno %d : %s\n",err,strerror(err));
+ }
+
+ while(1)
+ {
+ char buf[256];
+ int ret=fread(buf,1,10,p);
+ buf[10]=0;
+ printf("read: %i %s\n",ret,buf);
+ printf("feof: %i\n",feof(p));
+ if (feof(p)) break;
+ }
+ }
+
+ if(!strcmp(argv[1],"write"))
+ {
+ FILE *p=fopen("./testpipe","a");
+ printf("opened for writing\n");
+ if(p==NULL)
+ {
+ int err=errno;
+ printf("Opening pipe failed with errno %d : %s\n",err,strerror(err));
+ }
+ fwrite("DUPA123",1,7,p);
+ fwrite("DUPA123",1,7,p);
+ for(int i=0;i<10000;i++)
+ {
+ fwrite("DUPA123",1,7,p);
+ }
+ //fclose(p);
+ }
+}