Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
att
GitHub Repository: att/ast
Path: blob/master/src/cmd/tests/sfio/topen.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
Sfio_t sf;
26
27
if(sfopen(sfstdout,"abc","s") != sfstdout)
28
terror("Bad reopening of sfstdout");
29
if(sfopen(sfstdin,"123","s") != sfstdin)
30
terror("Bad reopening of sfstdin");
31
sfclose(sfstdin);
32
33
if(!(f = sfopen(NIL(Sfio_t*),"123","s")) )
34
terror("Opening a stream");
35
sfclose(f);
36
if(sfopen(f,"123","s") != NIL(Sfio_t*))
37
terror("can't reopen a closed stream!");
38
39
if(sfnew(&sf,NIL(char*),(size_t)SF_UNBOUND,0,SF_EOF|SF_READ) != &sf)
40
terror("Did not open sf");
41
sfset(&sf,SF_STATIC,1);
42
if(!sfclose(&sf) || errno != EBADF)
43
terror("sfclose(sf) should fail with EBADF");
44
if(!(sfset(&sf,0,0)&SF_STATIC))
45
terror("Did not close sf");
46
47
/* test for exclusive opens */
48
unlink(tstfile("sf", 0));
49
if(!(f = sfopen(NIL(Sfio_t*),tstfile("sf", 0),"wx") ) )
50
terror("sfopen failed");
51
if((f = sfopen(f,tstfile("sf", 0),"wx") ) )
52
terror("sfopen should not succeed here");
53
54
texit(0);
55
}
56
57