Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
att
GitHub Repository: att/ast
Path: blob/master/src/cmd/tests/sfio/tflags.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
26
if(!(f = sfopen(NIL(Sfio_t*),"ab","sr")) )
27
terror("Can't open stream");
28
if(sfeof(f) || sferror(f))
29
terror("Can't be eof or error yet");
30
if(sfgetc(f) != 'a')
31
terror("Got wrong data");
32
if(sfeof(f) || sferror(f))
33
terror("Can't be eof or error yet2");
34
if(sfgetc(f) != 'b')
35
terror("Got wrong data2");
36
if(sfeof(f) || sferror(f))
37
terror("Can't be eof or error yet3");
38
if(sfgetc(f) >= 0)
39
terror("Got wrong data2");
40
if(!sfeof(f))
41
terror("Should be eof now");
42
if(sfseek(f,(Sfoff_t)(-1),2) != 1)
43
terror("Seek error");
44
if(sfeof(f))
45
terror("Shouldn't be eof any more");
46
47
if(!(f = sfopen(NIL(Sfio_t*), tstfile("sf", 0), "w+")) )
48
terror("Can't open stream2");
49
if(sfeof(f) || sferror(f))
50
terror("Can't be eof or error yet2");
51
if(sfwrite(f,"ab",2) != 2)
52
terror("Can't write data");
53
if(sfseek(f,(Sfoff_t)0,0) != 0)
54
terror("Can't seek back");
55
if(sfgetc(f) != 'a')
56
terror("Got wrong data3");
57
if(sfeof(f) || sferror(f))
58
terror("Can't be eof or error yet4");
59
if(sfgetc(f) != 'b')
60
terror("Got wrong data4");
61
if(sfeof(f) || sferror(f))
62
terror("Can't be eof or error yet5");
63
if(sfgetc(f) >= 0)
64
terror("Got wrong data5");
65
if(!sfeof(f))
66
terror("Should be eof now2");
67
if(sfseek(f,(Sfoff_t)(-1),2) != 1)
68
terror("Seek error2");
69
if(sfeof(f))
70
terror("Shouldn't be eof any more2");
71
72
if(!(f = sfopen(NIL(Sfio_t*), tstfile("sf", 0),"w+")) )
73
terror("Reopening %s", tstfile("sf", 0));
74
sfwrite(f,"1234567890",10);
75
sfseek(f,(Sfoff_t)0,0);
76
77
if(sfopen(sfstdout, tstfile("sf", 1), "w") != sfstdout)
78
terror("Opening %s", tstfile("sf", 1));
79
80
if(sfmove(f,sfstdout,(Sfoff_t)(-1),-1) != 10)
81
terror("sfmove failed");
82
if(!sfeof(f))
83
terror("f should be eof");
84
if(sferror(sfstdout))
85
terror("sfstdout should not be in error");
86
87
texit(0);
88
}
89
90