[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [leafnode-list] Fetchnews suggestion - flushing verbose output



On Sat, 14 Aug 1999, Colin Brough <Colin.Brough@xxxxxxxxxxxxxx> wrote:
> However, 'stdout' is only rarely 'fflush'ed by 'fetchnews'.  If I
> ever want to watch how is is getting on "in real time" ('tail -f'),
> it is very difficult to know whether progress is being made with
> news downloading, or whether it has just hung....
>
> I've hacked my own copy of 'fetchnews' to flush stdout after every
> 'printf' (only if verbose output is selected), which does the trick
> nicely, but wondered whether it was something that might be useful
> for others....

OHHH, yes, please!  I connect by hand, and I tried to do as I've done
before -- tee stdout to a file.  I can then watch it but also look at
the log later if something odd happened.  I found it frustrating that
I can't.

You really don't want to fflush after every printf:
- that's a hell of a lot of editing, causing a lot of changes in the
  source control
- you're bound to miss a few
- you may overlook puts(), putc(), and output calls made in other
  files
- there's a much easier way

The Linux man page for setbuf(3) says

       #include <stdio.h>
       int setbuf(FILE *stream, char *buf);
       int setvbuf(FILE *stream, char *buf, int mode, size_t size);

are in ANSI C, so

    setbuf(stdout, (char *) NULL);

should do.  This call will cause any stdio output to stdout to be
flushed immediately.  setbuf is not in my Kernighan and Ritchie first
edition, but some things that existed then aren't, and I think setbuf
has existed for years (the Linux man page implies that it existed in
BSD before 4.2), so it should be nicely portable.  (Since there is
almost certainly a full function prototype in <stdio.h>, the cast
probably isn't needed, but it doesn't hurt and can help in odd
or archaic situations.)

I would not suggest setbuf only in verbose mode: I'd say do it all the
time.
- I can't think of a case where you don't want it; it's only a slight
  inefficiency
- If you're not in verbose mode, there's little output to be
  inefficient, so it really doesn't matter

-- 
                   *** NEW HOME E-MAIL ADDRESS ***
Tim McDaniel (home); Reply-To: tmcd@xxxxxxxx; 
if that fail, my work addresses are  tmcd@xxxxxxxxxxxxxx and tmcd@xxxxxxxxxxx
tmcd@xxxxxxxxxxxxxxxxx is a lie; tmcd@xxxxxxx is old and will go away.

-- 
leafnode-list@xxxxxxxxxxxxxxxxxxxxxxxxxxxx -- mailing list for leafnode
To unsubscribe, send mail with "unsubscribe" in the subject to the list