Path: utzoo!utgpu!water!watmath!clyde!att!osu-cis!tut.cis.ohio-state.edu!mailrus!uflorida!novavax!proxftl!bill From: bill@proxftl.UUCP (T. William Wells) Newsgroups: comp.lang.c Subject: Re: Any way to catch exit()? Keywords: _cleanup Message-ID: <657@proxftl.UUCP> Date: 29 Aug 88 07:05:11 GMT References: <8808261432.AA11635@ucbvax.Berkeley.EDU> <967@cbnews.ATT.COM> <771@philmds.UUCP> Reply-To: bill@proxftl.UUCP (T. William Wells) Organization: Proximity Technology, Ft. Lauderdale Lines: 32 Summary: Expires: Sender: Followup-To: Distribution: In article <771@philmds.UUCP> leo@philmds.UUCP (Leo de Wit) writes: : Probably has something to : do with keeping binary sizes small, Yes. Loading the stdio _cleanup means loading a substantial part of stdio as well. : but I can't figure out how you can : have several _cleanup() 's in one library. Anyone knows? : : Leo. This is easy on a UNIX system. You define __iob or whatever the FILE pointers point to in the file where you want the fancy _cleanup routine to go. You then place the exit and then the dummy _cleanup right after it. You have to give the two object files different names, but that is easy. The names I have seen are cleanup.o and fakcu.o. So, if the program references stdio anywhere, it will reference __iob. When the linker finds the first _cleanup, it will load it because of the __iob. Then exit comes along and uses the already loaded _cleanup so the second one is ignored. On the other hand, if stdio is not referenced, the first _cleanup is ignored because there is no reference to it; the exit is loaded because every program references exit, and that forces the loading of the second _cleanup. There are several variations on this theme, but as far as I know they all depend on library ordering tricks. --- Bill novavax!proxftl!bill