exit.c revision 1573
1240116Smarcel/*- 2240116Smarcel * Copyright (c) 1990, 1993 3240116Smarcel * The Regents of the University of California. All rights reserved. 4240116Smarcel * 5240116Smarcel * Redistribution and use in source and binary forms, with or without 6240116Smarcel * modification, are permitted provided that the following conditions 7240116Smarcel * are met: 8240116Smarcel * 1. Redistributions of source code must retain the above copyright 9240116Smarcel * notice, this list of conditions and the following disclaimer. 10240116Smarcel * 2. Redistributions in binary form must reproduce the above copyright 11240116Smarcel * notice, this list of conditions and the following disclaimer in the 12240116Smarcel * documentation and/or other materials provided with the distribution. 13240116Smarcel * 3. All advertising materials mentioning features or use of this software 14240116Smarcel * must display the following acknowledgement: 15240116Smarcel * This product includes software developed by the University of 16240116Smarcel * California, Berkeley and its contributors. 17240116Smarcel * 4. Neither the name of the University nor the names of its contributors 18240116Smarcel * may be used to endorse or promote products derived from this software 19240116Smarcel * without specific prior written permission. 20240116Smarcel * 21240116Smarcel * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 22240116Smarcel * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 23240116Smarcel * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 24240116Smarcel * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 25240116Smarcel * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 26240116Smarcel * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 27240116Smarcel * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 28240116Smarcel * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 29240116Smarcel * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 30240116Smarcel * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 31240116Smarcel * SUCH DAMAGE. 32240116Smarcel */ 33240116Smarcel 34240116Smarcel#if defined(LIBC_SCCS) && !defined(lint) 35240116Smarcelstatic char sccsid[] = "@(#)exit.c 8.1 (Berkeley) 6/4/93"; 36240116Smarcel#endif /* LIBC_SCCS and not lint */ 37240116Smarcel 38240116Smarcel#include <stdlib.h> 39240116Smarcel#include <unistd.h> 40240116Smarcel#include "atexit.h" 41240116Smarcel 42240116Smarcelvoid (*__cleanup)(); 43240116Smarcel 44240116Smarcel/* 45240116Smarcel * Exit, flushing stdio buffers if necessary. 46240116Smarcel */ 47240116Smarcelvoid 48240116Smarcelexit(status) 49240116Smarcel int status; 50240116Smarcel{ 51240116Smarcel register struct atexit *p; 52240116Smarcel register int n; 53240116Smarcel 54240116Smarcel for (p = __atexit; p; p = p->next) 55240116Smarcel for (n = p->ind; --n >= 0;) 56240116Smarcel (*p->fns[n])(); 57240116Smarcel if (__cleanup) 58240116Smarcel (*__cleanup)(); 59240116Smarcel _exit(status); 60240116Smarcel} 61240116Smarcel