Path: utzoo!utgpu!news-server.csri.toronto.edu!mailrus!cs.utexas.edu!uunet!aplcen!haven!adm!smoke!gwyn From: gwyn@smoke.BRL.MIL (Doug Gwyn) Newsgroups: comp.unix.questions Subject: Re: Stdio buffer flushing Message-ID: <13315@smoke.BRL.MIL> Date: 8 Jul 90 05:14:17 GMT References: <1990Jul5.220009.3724@chinet.chi.il.us> Organization: U.S. Army Ballistic Research Laboratory, APG, MD. Lines: 18 In article <1990Jul5.220009.3724@chinet.chi.il.us> les@chinet.chi.il.us (Leslie Mikesell) writes: >(void)vfprintf(logfile, fmt, ap); >putc('\n', logfile); /* log messages don't come with \n */ >(void)fflush(logfile); >Apparently the putc is performing a flush *before* adding the \n, so >that a concurrent process can write it's entry first. Is this a >bug or are you not supposed to mix different forms of buffered output? All stdio I/O operations are defined in terms of getc() and putc(), so clearly "mixing forms" of output is not an issue. However, there is no particular guarantee that an output operation will not cause an actual write() at some point, even if you have setbuf()ed and have not yet invoked fflush(). Certainly when the buffer is full it will be automatically flushed. While I'm not sure why your implementation of vfprintf() (or less likely, putc()) would flush the buffer where you say it did, there is no rule that prohibits it from doing so. The C standard does not require that no extra buffer flushing occur, although it does suggest that it is not intended.