Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
att
GitHub Repository: att/ast
Path: blob/master/src/cmd/tests/sfio/tpopen.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
Sfio_t *f;
25
char *s, *endos, *os = "one\ntwo\nthree\n";
26
int n;
27
void(* handler)_ARG_((int));
28
29
if(argc > 1)
30
{ sfmove(sfstdin,sfstdout,(Sfoff_t)(-1),-1);
31
return 0;
32
}
33
34
if(!(f = sfpopen((Sfio_t*)0, sfprints("%s -p > %s", argv[0], tstfile("sf", 0)), "w")))
35
terror("Opening for write");
36
if(sfwrite(f,os,strlen(os)) != (ssize_t)strlen(os))
37
terror("Writing");
38
39
#ifdef SIGPIPE
40
if((handler = signal(SIGPIPE,SIG_DFL)) == SIG_DFL)
41
terror("Wrong signal handler");
42
if((handler = signal(SIGPIPE,handler)) != SIG_DFL)
43
terror("Weird signal handling");
44
#endif
45
46
sfclose(f);
47
48
if(!(f = sfpopen((Sfio_t*)0, sfprints("%s -p < %s", argv[0], tstfile("sf", 0)), "r")))
49
terror("Opening for read");
50
sleep(1);
51
52
endos = os + strlen(os);
53
while(s = sfgetr(f,'\n',0))
54
{ n = sfvalue(f);
55
if(strncmp(s,os,n) != 0)
56
{ s[n-1] = os[n-1] = 0;
57
terror("Input=%s, Expect=%s",s,os);
58
}
59
os += n;
60
}
61
62
if(os != endos)
63
terror("Does not match all data, left=%s",os);
64
65
texit(0);
66
}
67
68