Article View: comp.std.c
Article #3954Re: EXIT_FAILURE problem
From: Chris Torek
Date: Thu, 07 Sep 1995 22:50
Date: Thu, 07 Sep 1995 22:50
58 lines
2443 bytes
2443 bytes
In article <42mta4$2ku@solutions.solon.com> Peter Seebach
<seebs@solutions.solon.com> writes:
>Consider:
>
>_lib_startup() {
> exit(main(magic, magic));
>}
>
>exit(int x) {
>if (x == 0) exits("okay");
>else exits("not-so-ok");
>}
>
>Boom. We have adapted to a system where we exit with strings.
Well, more or less. Exit actually has to run all the atexit()-
registered functions, and close down stdio and free malloc'ed memory
and so on (much of which is implementation-dependent).
I would probably write this as:
void
exit(int status) {
__libc_shutdown();
__sys_exits(status ? "failure" : "success");
}
There is perhaps one interesting point here. If the actual `shutdown'
code (calling atexit() functions, closing down stdio, etc.) represented
above by __libc_shutdown() is coded in-line within exit(), it becomes
difficult to shut down the library *and* call the system exit function
(__sys_exits() above).
This is, of course, a `quality of implementation' issue; a system that
uses exit strings might want to provide a convenience function such as:
void exits(const char *status) {
__libc_shutdown();
__sys_exits(status);
}
but clearly the Standard cannot require this.
[and to halasz@caip.rutgers.edu]
>And please use modern English spelling ... you're gratuitously making
>your posts difficult to read.
Rather than using a kill file entry (though I have been tempted),
I let these articles come up in my window, and if I find them
difficult to read, I ignore them. I recommend this technique: I
find it saves lots of time and loses little. :-) (There are other
posters I sometimes find difficult to read, but their articles tend
to have more value to me.)
--
In-Real-Life: Chris Torek, Berkeley Software Design Inc
Berkeley, CA Domain: torek@bsdi.com +1 510 549 1145
`... if we wish to count lines of code, we should not regard them as
``lines produced'' but as ``lines spent.'' ' --Edsger Dijkstra
Technical Details
Message-ID:
<42nsuq$bon@elf.bsdi.com>Path:
arc1-ca.pugleaf.net!cs.umd.edu!not-for-mailReferences:
<jbundyDCw7uo.9sz@netcom.com> <42k9vn$5co@newshost.lanl.gov> <42lkqd$ngg@caip.rutgers.edu> <42mta4$2ku@solutions.solon.com>Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!cs.umd.edu!not-for-mail From: torek@elf.bsdi.com (Chris Torek) Newsgroups: comp.std.c Subject: Re: EXIT_FAILURE problem Date: 7 Sep 1995 15:50:02 -0700 Organization: Berkeley Software Design, Inc. Message-ID: <42nsuq$bon@elf.bsdi.com> References: <jbundyDCw7uo.9sz@netcom.com> <42k9vn$5co@newshost.lanl.gov> <42lkqd$ngg@caip.rutgers.edu> <42mta4$2ku@solutions.solon.com> Reply-To: torek@bsdi.com NNTP-Posting-Host: elf.bsdi.com