/***********************************************************************1* *2* This software is part of the ast package *3* Copyright (c) 1999-2011 AT&T Intellectual Property *4* and is licensed under the *5* Eclipse Public License, Version 1.0 *6* by AT&T Intellectual Property *7* *8* A copy of the License is available at *9* http://www.eclipse.org/org/documents/epl-v10.html *10* (with md5 checksum b35adb5213ca9657e911e9befb180842) *11* *12* Information and Software Systems Research *13* AT&T Research *14* Florham Park NJ *15* *16* Glenn Fowler <[email protected]> *17* *18***********************************************************************/19#include "sftest.h"2021/* test to see if files created in atexit functions work ok */2223void ae()24{25Sfio_t* f = sfopen(NIL(Sfio_t*), tstfile("sf", 0), "w");2627if(!f)28terror("Can't create file");2930if(sfwrite(f,"1234\n",5) != 5)31terror("Can't write to file");3233tcleanup();34}3536#if __STD_C37main(int argc, char** argv)38#else39main(argc, argv)40int argc;41char** argv;42#endif43{44Sfio_t* f;4546if(argc <= 1) /* atexit function registered after some sfio access */47{ if(!(f = sfopen(NIL(Sfio_t*), tstfile("sf", 1), "w")) )48terror("Can't create file");49if(sfwrite(f,"1234\n",5) != 5)50terror("Can't write to file");5152atexit(ae);5354system(sfprints("%s 1",argv[0]));55}56else /* atexit function registered before some sfio access */57{ atexit(ae);5859if(!(f = sfopen(NIL(Sfio_t*), tstfile("sf", 1), "w")) )60terror("Can't create file");61if(sfwrite(f,"1234\n",5) != 5)62terror("Can't write to file");63}6465texit(0);66}676869