/***********************************************************************1* *2* This software is part of the ast package *3* Copyright (c) 1985-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* David Korn <[email protected]> *18* Phong Vo <[email protected]> *19* *20***********************************************************************/21#pragma prototyped2223/*24* ANSI C atexit()25* arrange for func to be called LIFO on exit()26*/2728#include <ast.h>2930#if _lib_atexit3132NoN(atexit)3334#else3536#if _lib_onexit || _lib_on_exit3738#if !_lib_onexit39#define onexit on_exit40#endif4142extern int onexit(void(*)(void));4344int45atexit(void (*func)(void))46{47return(onexit(func));48}4950#else5152struct list53{54struct list* next;55void (*func)(void);56};5758static struct list* funclist;5960extern void _exit(int);6162int63atexit(void (*func)(void))64{65register struct list* p;6667if (!(p = newof(0, struct list, 1, 0))) return(-1);68p->func = func;69p->next = funclist;70funclist = p;71return(0);72}7374void75_ast_atexit(void)76{77register struct list* p;7879while (p = funclist)80{81funclist = p->next;82(*p->func)();83}84}8586#if _std_cleanup8788#if _lib__cleanup89extern void _cleanup(void);90#endif9192void93exit(int code)94{95_ast_atexit();96#if _lib__cleanup97_cleanup();98#endif99_exit(code);100}101102#else103104void105_cleanup(void)106{107_ast_atexit();108}109110#endif111112#endif113114#endif115116117