diff options
author | Christopher Faylor <me@cgf.cx> | 2000-02-17 19:39:52 +0000 |
---|---|---|
committer | Christopher Faylor <me@cgf.cx> | 2000-02-17 19:39:52 +0000 |
commit | 8a0efa53e44919bcf5ccb1d3353618a82afdf8bc (patch) | |
tree | 68c3dbf3f2c6fd5d49777def9914d77b5cd4589d /newlib/libc/stdlib/exit.c | |
parent | 1fd5e000ace55b323124c7e556a7a864b972a5c4 (diff) | |
download | cygnal-8a0efa53e44919bcf5ccb1d3353618a82afdf8bc.tar.gz cygnal-8a0efa53e44919bcf5ccb1d3353618a82afdf8bc.tar.bz2 cygnal-8a0efa53e44919bcf5ccb1d3353618a82afdf8bc.zip |
import newlib-2000-02-17 snapshot
Diffstat (limited to 'newlib/libc/stdlib/exit.c')
-rw-r--r-- | newlib/libc/stdlib/exit.c | 73 |
1 files changed, 73 insertions, 0 deletions
diff --git a/newlib/libc/stdlib/exit.c b/newlib/libc/stdlib/exit.c new file mode 100644 index 000000000..543bd0e30 --- /dev/null +++ b/newlib/libc/stdlib/exit.c @@ -0,0 +1,73 @@ +/* + * Copyright (c) 1990 Regents of the University of California. + * All rights reserved. + * + * %sccs.include.redist.c% + */ + +/* +FUNCTION +<<exit>>---end program execution + +INDEX + exit + +ANSI_SYNOPSIS + #include <stdlib.h> + void exit(int <[code]>); + +TRAD_SYNOPSIS + #include <stdlib.h> + void exit(<[code]>) + int <[code]>; + +DESCRIPTION +Use <<exit>> to return control from a program to the host operating +environment. Use the argument <[code]> to pass an exit status to the +operating environment: two particular values, <<EXIT_SUCCESS>> and +<<EXIT_FAILURE>>, are defined in `<<stdlib.h>>' to indicate success or +failure in a portable fashion. + +<<exit>> does two kinds of cleanup before ending execution of your +program. First, it calls all application-defined cleanup functions +you have enrolled with <<atexit>>. Second, files and streams are +cleaned up: any pending output is delivered to the host system, each +open file or stream is closed, and files created by <<tmpfile>> are +deleted. + +RETURNS +<<exit>> does not return to its caller. + +PORTABILITY +ANSI C requires <<exit>>, and specifies that <<EXIT_SUCCESS>> and +<<EXIT_FAILURE>> must be defined. + +Supporting OS subroutines required: <<_exit>>. +*/ + +#include <stdlib.h> +#include <unistd.h> /* for _exit() declaration */ +#include <reent.h> + +#ifndef _REENT_ONLY + +/* + * Exit, flushing stdio buffers if necessary. + */ + +void +_DEFUN (exit, (code), + int code) +{ + register struct _atexit *p; + register int n; + + for (p = _REENT->_atexit; p; p = p->_next) + for (n = p->_ind; --n >= 0;) + (*p->_fns[n]) (); + if (_REENT->__cleanup) + (*_REENT->__cleanup) (_REENT); + _exit (code); +} + +#endif |