Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
att
GitHub Repository: att/ast
Path: blob/master/src/cmd/tests/sfio/tpkrd.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
static int Fd[2];
23
24
#if __STD_C
25
void alarmhandler(int sig)
26
#else
27
void alarmhandler(sig)
28
int sig;
29
#endif
30
{
31
if(write(Fd[1],"01234\n56789\n",12) != 12)
32
terror("Writing to pipe");
33
}
34
35
tmain()
36
{
37
char* s;
38
char buf[1024];
39
int n;
40
41
if(pipe(Fd) < 0)
42
terror("Can't make pipe");
43
44
if(sfnew(sfstdin,NIL(Void_t*),(size_t)SF_UNBOUND,Fd[0],SF_READ) != sfstdin)
45
terror("Can't renew stdin");
46
sfset(sfstdin,SF_SHARE,1);
47
48
if(sfpkrd(Fd[0],(Void_t*)buf,10,-1,1000,1) >= 0)
49
terror("There isn't any data yet");
50
51
if((n = sfpkrd(Fd[0],(Void_t*)buf,sizeof(buf),-1,0L,0)) >= 0)
52
terror("Wrong data size %d, expecting < 0", n);
53
54
if(write(Fd[1],"abcd",4) != 4)
55
terror("Couldn't write to pipe");
56
57
if((n = sfpkrd(Fd[0],(Void_t*)buf,sizeof(buf),-1,0L,0)) != 4)
58
terror("Wrong data size %d, expecting 4", n);
59
60
signal(SIGALRM,alarmhandler);
61
alarm(2);
62
if(!(s = sfgetr(sfstdin,'\n',1)) || strcmp(s,"01234") != 0)
63
terror("Expecting 01234");
64
65
if(sfstdin->_next < sfstdin->_endb)
66
terror("Sfgetr read too much");
67
68
if(!(s = sfgetr(sfstdin,'\n',1)) || strcmp(s,"56789") != 0)
69
terror("Expecting 56789");
70
71
texit(0);
72
}
73
74