Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
att
GitHub Repository: att/ast
Path: blob/master/src/cmd/tests/sfio/tpipemove.c
1810 views
1
/***********************************************************************
2
* *
3
* This software is part of the ast package *
4
* Copyright (c) 1999-2011 AT&T Intellectual Property *
5
* and is licensed under the *
6
* Eclipse Public License, Version 1.0 *
7
* by AT&T Intellectual Property *
8
* *
9
* A copy of the License is available at *
10
* http://www.eclipse.org/org/documents/epl-v10.html *
11
* (with md5 checksum b35adb5213ca9657e911e9befb180842) *
12
* *
13
* Information and Software Systems Research *
14
* AT&T Research *
15
* Florham Park NJ *
16
* *
17
* Glenn Fowler <[email protected]> *
18
* *
19
***********************************************************************/
20
#include "sftest.h"
21
22
tmain()
23
{
24
int fd[2];
25
Sfio_t *fr, *fw;
26
char *s;
27
int n, w;
28
29
if(pipe(fd) < 0)
30
terror("Can't open pipe");
31
32
if(!(fr = sfnew(NIL(Sfio_t*),NIL(Void_t*),(size_t)SF_UNBOUND,fd[0],SF_READ)) ||
33
!(fw = sfnew(NIL(Sfio_t*),NIL(Void_t*),(size_t)SF_UNBOUND,fd[1],SF_WRITE)) )
34
terror("Can't open pipe streams");
35
sfset(fr,SF_SHARE,1);
36
37
if(sfopen(sfstdout,tstfile("sf", 0),"w") != sfstdout)
38
terror("Can't open for write");
39
if(sfopen(sfstdin,tstfile("sf", 0),"r") != sfstdin)
40
terror("Can't open for read");
41
42
for(n = 0; n < 100; ++n)
43
if((w = sfwrite(fw,"123456789\n",10)) != 10)
44
terror("Writing to pipe w=%d",w);
45
46
if((n = (int)sfmove(fr,sfstdout,(Sfoff_t)100,'\n')) != 100)
47
terror("sfmove failed n=%d", n);
48
sfclose(sfstdout);
49
50
for(n = 0; n < 100; ++n)
51
{ if(!(s = sfgetr(sfstdin,'\n',1)) )
52
terror("Can't read data");
53
if(strcmp(s,"123456789") != 0)
54
terror("Wrong data");
55
}
56
57
texit(0);
58
}
59
60