Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
att
GitHub Repository: att/ast
Path: blob/master/src/cmd/tests/sfio/tatexit.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
/* test to see if files created in atexit functions work ok */
23
24
void ae()
25
{
26
Sfio_t* f = sfopen(NIL(Sfio_t*), tstfile("sf", 0), "w");
27
28
if(!f)
29
terror("Can't create file");
30
31
if(sfwrite(f,"1234\n",5) != 5)
32
terror("Can't write to file");
33
34
tcleanup();
35
}
36
37
#if __STD_C
38
main(int argc, char** argv)
39
#else
40
main(argc, argv)
41
int argc;
42
char** argv;
43
#endif
44
{
45
Sfio_t* f;
46
47
if(argc <= 1) /* atexit function registered after some sfio access */
48
{ if(!(f = sfopen(NIL(Sfio_t*), tstfile("sf", 1), "w")) )
49
terror("Can't create file");
50
if(sfwrite(f,"1234\n",5) != 5)
51
terror("Can't write to file");
52
53
atexit(ae);
54
55
system(sfprints("%s 1",argv[0]));
56
}
57
else /* atexit function registered before some sfio access */
58
{ atexit(ae);
59
60
if(!(f = sfopen(NIL(Sfio_t*), tstfile("sf", 1), "w")) )
61
terror("Can't create file");
62
if(sfwrite(f,"1234\n",5) != 5)
63
terror("Can't write to file");
64
}
65
66
texit(0);
67
}
68
69