Path: utzoo!utgpu!watmath!att!tut.cis.ohio-state.edu!purdue!bu-cs!dartvax!eleazar.dartmouth.edu!kender
From: kender@eleazar.dartmouth.edu (Too hot to handle)
Newsgroups: comp.unix.questions
Subject: can files be treated as streams in SYSV??
Message-ID: <15034@dartvax.Dartmouth.EDU>
Date: 15 Aug 89 19:36:24 GMT
References: <113700014@uxa.cso.uiuc.edu>
Sender: news@dartvax.Dartmouth.EDU
Reply-To: kender@eleazar.dartmouth.edu
Organization: Dartmouth College, Hanover, NH
Lines: 58

I have a application that needs to follow the progress of a couple of files,
I'd like to use poll for this (shaddup you tail -f ers....I've my own reasons)
the code follows that has given me a bitch...the problem is that poll says that
there is always data to read even at eof...so I have this nagging feeling that
I cannot do this with a file...blah...I have R the FM and no mention that I 
could find about not being able to treat a file like a stream...

---------------------------- code follows -----------------------------
#include 
#include 
#include 
#define WAIT_FOR_EVENT -1

main(){
    FILE *wf0 = fopen("watch0", "a+");
    FILE *wf1 = fopen("watch1", "a+");

    struct pollfd fds[2];
    int timeout = WAIT_FOR_EVENT;
    unsigned long nfds = 2;           /* two files to watch */
    char buf[80];
    unsigned int nbyte = 80;
    int i;
    int cnt;
    int ccnt;

    fds[0].fd = fileno(wf0);
    fds[0].events = POLLIN; 

    fds[1].fd = fileno(wf1);
    fds[1].events = POLLIN;

    printf("%d %d\n", fds[0].fd, fds[1].fd);

    for(;;){
        if ((cnt = poll(fds, nfds, timeout)) > 0) {
	        printf("Event detected on %d fd(s)\n", cnt);
		fflush(stdout);
		for(i=0;i