Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
att
GitHub Repository: att/ast
Path: blob/master/src/cmd/tests/sfio/tmode.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(argc > 1)
27
{ if(sfopen(sfstdin,argv[1],"r") != sfstdin)
28
terror("Can't reopen stdin");
29
sfmove(sfstdin,sfstdout,(Sfoff_t)(-1),-1);
30
return 0;
31
}
32
33
if(!(f = sfopen((Sfio_t*)0,tstfile("sf", 0),"w")))
34
terror("Opening to write");
35
if(sfputc(f,'a') != 'a')
36
terror("sfputc");
37
if(sfgetc(f) >= 0)
38
terror("sfgetc");
39
40
if(!(f = sfopen(f,tstfile("sf", 0),"r")))
41
terror("Opening to read");
42
if(sfgetc(f) != 'a')
43
terror("sfgetc2");
44
if(sfputc(f,'b') >= 0)
45
terror("sfputc2");
46
47
if(!(f = sfopen(f,tstfile("sf", 0),"r+")))
48
terror("Opening to read/write");
49
50
if(sfgetc(f) != 'a')
51
terror("sfgetc3");
52
if(sfputc(f,'b') != 'b')
53
terror("sfputc3");
54
if(sfclose(f) < 0)
55
terror("sfclose");
56
57
if(!(f = sfpopen(NIL(Sfio_t*),sfprints("%s %s", argv[0], tstfile("sf", 0)),"r")))
58
terror("sfpopen");
59
if(sfgetc(f) != 'a')
60
terror("sfgetc4");
61
if(sfgetc(f) != 'b')
62
terror("sfgetc5");
63
if(sfgetc(f) >= 0)
64
terror("sfgetc6");
65
66
if(!(f = sfopen(f,tstfile("sf", 0),"w")) )
67
terror("sfopen");
68
if(sfputc(f,'a') != 'a')
69
terror("sfputc1");
70
sfsetfd(f,-1);
71
if(sfputc(f,'b') >= 0)
72
terror("sfputc2");
73
if(sfclose(f) < 0)
74
terror("sfclose");
75
76
if(!(f = sfopen(NIL(Sfio_t*),tstfile("sf", 0),"a+")) )
77
terror("sfopen2");
78
sfset(f,SF_READ,0);
79
if(!sfreserve(f,0,-1) )
80
terror("Failed on buffer getting");
81
if(sfvalue(f) <= 0)
82
terror("There is no buffer?");
83
84
texit(0);
85
}
86
87