Path: utzoo!attcan!utgpu!news-server.csri.toronto.edu!mailrus!purdue!haven!mimsy!chris From: chris@mimsy.umd.edu (Chris Torek) Newsgroups: comp.unix.questions Subject: Re: _cleanup() before fork()? (was Re: How to terminate a child ...) Message-ID: <24822@mimsy.umd.edu> Date: 10 Jun 90 15:08:09 GMT References: <24504.26542926@kuhub.cc.ukans.edu> <12932@smoke.BRL.MIL> <775@mwtech.UUCP> Organization: U of Maryland, Dept. of Computer Science, Coll. Pk., MD 20742 Lines: 40 In article <775@mwtech.UUCP> martin@mwtech.UUCP (Martin Weitzel) writes: >It would be quite helpful if stdio had officially defined some >"fflush_all()" operation ... As of ANSI C, it does: fflush((FILE *)NULL) does the trick. >- which is necessary anyway, because its implicitly called by exit(). >For as much as I know the usual name of this routine is "_cleanup()", >but using it - of course - is not recommendable for portable programs. Indeed. In particular, in many implementations _cleanup() *closes* every stdio stream. The result is that stdin, stdout, and stderr are gone. fflush((FILE *)NULL) is the only semi-portable solution. If you need something like this, you are probably best off including a separate C file with a function `flushall' that reads: #include flushall() { #ifdef FFLUSH_NULL /* use ANSI standard method */ (void) fflush((FILE *)NULL); #else #ifdef _NFILE /* probably a SysV or V7 or 4.1BSD system */ register FILE *fp; for (fp = &_iob[0]; fp < &_iob[_NFILE]; fp++) if (fp->_flag) (void) fflush(fp); #else /* probably a 4.2BSD system or derivative */ extern int fflush(); /* might not be in */ extern int _fwalk(); /* undocumented but present */ (void) _fwalk(fflush); #endif #endif } -- In-Real-Life: Chris Torek, Univ of MD Comp Sci Dept (+1 301 454 7163) Domain: chris@cs.umd.edu Path: uunet!mimsy!chris