Re: Need to block on file eof read
From: Andrei Voropaev (avorop_at_mail.ru)
Date: 12/28/04
- Previous message: James Johnson: "Re: Need to block on file eof read"
- In reply to: James Johnson: "Need to block on file eof read"
- Next in thread: Chuck Dillon: "Re: Need to block on file eof read"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: 28 Dec 2004 17:58:54 GMT
On 2004-12-28, James Johnson <jj@yaaho.com> wrote:
>
>
> I need to do something like this, but get the read (fgets in this case)
> to block until there is a new line of data. Sort of like tail -f.
>
> FILE *instream = fopen(fname, "rt");
> if (instream==NULL) {
> return 0;
> }
> fseek(instream, 0L, SEEK_END);
>
> while(1) {
> cptr = fgets(buf, sizeof(buf), instream);
> if (cptr==NULL) {
> printf("exiting because there is no data\n");
> break;
> }
> printf(cptr);
> }
>
> fclose(instream);
>
>
> How can this be done in unix?
On linux, normally one calls fgets, if NULL then sleeps for a while, and
after that tries again. Check the strace of tail -f, you'll see it.
I don't believe (though I don't know it ;) that there's any other way.
Andrei
- Previous message: James Johnson: "Re: Need to block on file eof read"
- In reply to: James Johnson: "Need to block on file eof read"
- Next in thread: Chuck Dillon: "Re: Need to block on file eof read"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|