summaryrefslogtreecommitdiff
path: root/test/pipetest.c
blob: e848049a1afb763ab9c58de4f950e8fa22efbf94 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
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);
    }
}