Path: utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!samsung!uakari.primate.wisc.edu!sdd.hp.com!ucsd!rutgers!mcdchg!chinet!les From: les@chinet.chi.il.us (Leslie Mikesell) Newsgroups: comp.unix.questions Subject: Stdio buffer flushing Message-ID: <1990Jul5.220009.3724@chinet.chi.il.us> Date: 5 Jul 90 22:00:09 GMT Organization: Chinet - Public Access UNIX Lines: 24 Does the putc macro have any strange side effects (such as flushing an unfilled buffer) under SysV when setbuf is used? I'm seeing occasional lines in a logfile that should be: line1 line2 become: line1line2 blank_line The relevant code is: (from smail 3.1, incidentally...) static char logbuf[BUFSIZ]; /* stdio buffer to avoid mallocs */ fd = open(log_fn, O_CREAT|O_APPEND|O_WRONLY, log_mode); logfile = fdopen(fd, "a"); (void) setbuf(logfile, logbuf); /* associate stream and buffer */ ... (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? Les Mikesell les@chinet.chi.il.us