2000-02-18 03:39:52 +08:00
|
|
|
/*
|
|
|
|
* Copyright (c) 1990 Regents of the University of California.
|
|
|
|
* All rights reserved.
|
|
|
|
*
|
|
|
|
* %sccs.include.redist.c%
|
|
|
|
*/
|
|
|
|
|
|
|
|
/*
|
|
|
|
FUNCTION
|
|
|
|
<<exit>>---end program execution
|
|
|
|
|
|
|
|
INDEX
|
|
|
|
exit
|
|
|
|
|
2017-11-30 16:17:18 +08:00
|
|
|
SYNOPSIS
|
2000-02-18 03:39:52 +08:00
|
|
|
#include <stdlib.h>
|
|
|
|
void exit(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>
|
2004-09-10 03:46:54 +08:00
|
|
|
#include "atexit.h"
|
2000-02-18 03:39:52 +08:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Exit, flushing stdio buffers if necessary.
|
|
|
|
*/
|
|
|
|
|
2013-07-03 05:30:57 +08:00
|
|
|
void
|
2000-02-18 03:39:52 +08:00
|
|
|
_DEFUN (exit, (code),
|
|
|
|
int code)
|
|
|
|
{
|
2013-07-03 05:30:57 +08:00
|
|
|
#ifdef _LITE_EXIT
|
|
|
|
/* Refer to comments in __atexit.c for more details of lite exit. */
|
|
|
|
void __call_exitprocs _PARAMS ((int, _PTR)) __attribute__((weak));
|
|
|
|
if (__call_exitprocs)
|
|
|
|
#endif
|
|
|
|
__call_exitprocs (code, NULL);
|
2002-05-16 06:58:10 +08:00
|
|
|
|
2003-09-03 06:42:05 +08:00
|
|
|
if (_GLOBAL_REENT->__cleanup)
|
|
|
|
(*_GLOBAL_REENT->__cleanup) (_GLOBAL_REENT);
|
2000-02-18 03:39:52 +08:00
|
|
|
_exit (code);
|
|
|
|
}
|