exit.c revision 1573
1226496Sjchandra/*- 2226496Sjchandra * Copyright (c) 1990, 1993 3226496Sjchandra * The Regents of the University of California. All rights reserved. 4226496Sjchandra * 5226496Sjchandra * Redistribution and use in source and binary forms, with or without 6226496Sjchandra * modification, are permitted provided that the following conditions 7226496Sjchandra * are met: 8226496Sjchandra * 1. Redistributions of source code must retain the above copyright 9226496Sjchandra * notice, this list of conditions and the following disclaimer. 10226496Sjchandra * 2. Redistributions in binary form must reproduce the above copyright 11226496Sjchandra * notice, this list of conditions and the following disclaimer in the 12226496Sjchandra * documentation and/or other materials provided with the distribution. 13226496Sjchandra * 3. All advertising materials mentioning features or use of this software 14226496Sjchandra * must display the following acknowledgement: 15226496Sjchandra * This product includes software developed by the University of 16226496Sjchandra * California, Berkeley and its contributors. 17226496Sjchandra * 4. Neither the name of the University nor the names of its contributors 18226496Sjchandra * may be used to endorse or promote products derived from this software 19226496Sjchandra * without specific prior written permission. 20226496Sjchandra * 21226496Sjchandra * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 22226496Sjchandra * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 23226496Sjchandra * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 24226496Sjchandra * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 25226496Sjchandra * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 26226496Sjchandra * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 27226496Sjchandra * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 28226496Sjchandra * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 29226496Sjchandra * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 30226496Sjchandra * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 31226496Sjchandra * SUCH DAMAGE. 32226496Sjchandra */ 33226496Sjchandra 34226496Sjchandra#if defined(LIBC_SCCS) && !defined(lint) 35226496Sjchandrastatic char sccsid[] = "@(#)exit.c 8.1 (Berkeley) 6/4/93"; 36226496Sjchandra#endif /* LIBC_SCCS and not lint */ 37226496Sjchandra 38226496Sjchandra#include <stdlib.h> 39226496Sjchandra#include <unistd.h> 40226496Sjchandra#include "atexit.h" 41226496Sjchandra 42226496Sjchandravoid (*__cleanup)(); 43226496Sjchandra 44226496Sjchandra/* 45226496Sjchandra * Exit, flushing stdio buffers if necessary. 46226496Sjchandra */ 47226496Sjchandravoid 48226496Sjchandraexit(status) 49226496Sjchandra int status; 50226496Sjchandra{ 51226496Sjchandra register struct atexit *p; 52 register int n; 53 54 for (p = __atexit; p; p = p->next) 55 for (n = p->ind; --n >= 0;) 56 (*p->fns[n])(); 57 if (__cleanup) 58 (*__cleanup)(); 59 _exit(status); 60} 61