Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
att
GitHub Repository: att/ast
Path: blob/master/src/cmd/tests/sfio/trcrv.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
#if __STD_C
23
ssize_t myread(Sfio_t* f, Void_t* buf, size_t n, Sfdisc_t* disc)
24
#else
25
ssize_t myread(f, buf, n, disc)
26
Sfio_t* f;
27
Void_t* buf;
28
size_t n;
29
Sfdisc_t* disc;
30
#endif
31
{
32
return sfrd(f,buf,n,disc);
33
}
34
35
Sfdisc_t Disc = {myread, NIL(Sfwrite_f), NIL(Sfseek_f), NIL(Sfexcept_f)};
36
37
tmain()
38
{
39
int fd[2];
40
41
if(pipe(fd) < 0)
42
terror("Can't open pipe");
43
44
if(sfnew(sfstdin,NIL(Void_t*),(size_t)SF_UNBOUND,fd[0],SF_READ) != sfstdin)
45
terror("Can't initialize sfstdin");
46
sfset(sfstdin,SF_SHARE,1);
47
sfdisc(sfstdin,&Disc);
48
49
if(sfnew(sfstdout,NIL(Void_t*),0,fd[1],SF_WRITE) != sfstdout)
50
terror("Can't initialize sfstdout");
51
sfputr(sfstdout,"111\n222\n333\n",-1);
52
sfsync(sfstdout);
53
54
if(strcmp(sfgetr(sfstdin,'\n',1),"111") != 0)
55
terror("sfgetr failed1");
56
if(sfstdin->_endb > sfstdin->_next)
57
terror("sfgetr reads too much1");
58
59
if(strcmp(sfgetr(sfstdin,'\n',1),"222") != 0)
60
terror("sfgetr failed2");
61
if(sfstdin->_endb > sfstdin->_next)
62
terror("sfgetr reads too much2");
63
64
texit(0);
65
}
66
67