Date: Thu, 28 Nov 2002 11:37:13 +0000 From: "Richard Dawe" Sender: rich AT phekda DOT freeserve DOT co DOT uk To: djgpp-workers AT delorie DOT com X-Mailer: Emacs 21.3.50 (via feedmail 8.3.emacs20_6 I) and Blat ver 1.8.6 Subject: _Exit function [PATCH] Message-Id: Reply-To: djgpp-workers AT delorie DOT com Hello. Below is a patch to add the _Exit function, as required by C99. Here's its description from 7.20.4.4 (page 329 in the PDF): "The _Exit function causes normal program termination to occur and control to be returned to the host environment. No functions registered by the atexit function or signal handlers registered by the signal function are called. The status returned to the host environment is determined in the same way as for the exit function (7.20.4.3). Whether open streams with unwritten buffered data are flushed, open streams are closed, or temporary files are removed is implementation-defined." If we don't flush open streams, etc., then this function is equivalent to _exit. In fact, it seems like they chose the name not to clash with _exit, which some C libraries seem to have (DJGPP's & Microsoft's spring to mind). If we want to flush open streams, etc., then it's a little unclear what to do with C++ destructors. The C++ standard describes that exit() should call the destructors, but there's no mention of _exit() or _Exit(). That's not surprising, since C99 came out after the C++ standard. OK to commit? Thanks, bye, Rich =] Index: include/stdlib.h =================================================================== RCS file: /cvs/djgpp/djgpp/include/stdlib.h,v retrieving revision 1.12 diff -p -u -3 -r1.12 stdlib.h --- include/stdlib.h 17 Oct 2002 23:00:24 -0000 1.12 +++ include/stdlib.h 28 Nov 2002 11:27:35 -0000 @@ -46,6 +46,7 @@ __DJ_wchar_t #define _WCHAR_T #endif +void _Exit(int _status) __attribute__((noreturn)); void abort(void) __attribute__((noreturn)); int abs(int _i); int atexit(void (*_func)(void)); Index: src/libc/ansi/stdlib/makefile =================================================================== RCS file: /cvs/djgpp/djgpp/src/libc/ansi/stdlib/makefile,v retrieving revision 1.5 diff -p -u -3 -r1.5 makefile --- src/libc/ansi/stdlib/makefile 17 Oct 2002 23:00:24 -0000 1.5 +++ src/libc/ansi/stdlib/makefile 28 Nov 2002 11:27:35 -0000 @@ -1,9 +1,11 @@ +# Copyright (C) 2002 DJ Delorie, see COPYING.DJ for details # Copyright (C) 2001 DJ Delorie, see COPYING.DJ for details # Copyright (C) 1998 DJ Delorie, see COPYING.DJ for details # Copyright (C) 1996 DJ Delorie, see COPYING.DJ for details # Copyright (C) 1994 DJ Delorie, see COPYING.DJ for details TOP=../.. +SRC += _exit.c SRC += abort.c SRC += abs.c SRC += atexit.c Index: src/libc/ansi/stdlib/_exit.c =================================================================== RCS file: src/libc/ansi/stdlib/_exit.c diff -N src/libc/ansi/stdlib/_exit.c --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ src/libc/ansi/stdlib/_exit.c 28 Nov 2002 11:27:40 -0000 @@ -0,0 +1,10 @@ +/* Copyright (C) 2002 DJ Delorie, see COPYING.DJ for details */ +#include +#include +#include + +void +_Exit (int status) +{ + _exit(status); +} Index: src/libc/ansi/stdlib/_exit.txh =================================================================== RCS file: src/libc/ansi/stdlib/_exit.txh diff -N src/libc/ansi/stdlib/_exit.txh --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ src/libc/ansi/stdlib/_exit.txh 28 Nov 2002 11:27:40 -0000 @@ -0,0 +1,36 @@ +@node _Exit, process +@subheading Syntax + +@example +#include + +void _Exit(int exit_code); +@end example + +@subheading Description + +This function exits the program, returning @var{exit_code} to the +calling process. No additional processing (such as closing file +descriptors or calls to the static destructor functions) is done, and +any @code{atexit} functions are not called; only the hardware interrupt +handlers are unhooked, to prevent system crashes. + +@subheading Return Value + +This function does not return. + +@subheading Portability + +@portability !ansi-c89, ansi-c99, !posix-1003.2-1992, posix-1003.1-2001 + +@port-note ansi-c99 Depending on the implementation, @code{_Exit} may do the additional processing described above. + +@subheading Example + +@example +if (argc < 4) +@{ + print_usage(); + _Exit(1); +@} +@end example Index: src/docs/kb/wc204.txi =================================================================== RCS file: /cvs/djgpp/djgpp/src/docs/kb/wc204.txi,v retrieving revision 1.121 diff -p -u -3 -r1.121 wc204.txi --- src/docs/kb/wc204.txi 28 Nov 2002 09:06:29 -0000 1.121 +++ src/docs/kb/wc204.txi 28 Nov 2002 11:27:52 -0000 @@ -782,3 +782,6 @@ The @code{int_n_cs_precedes}, @code{int_ @code{int_n_sign_posn}, @code{int_p_cs_precedes}, @code{int_p_sep_by_space} and @code{int_p_sign_posn} members were added to @code{struct lconv}, to comply with the C99 standard. + +@findex _Exit +The function @code{_Exit} was added.