bungetc error - Plan9

This is a discussion on bungetc error - Plan9 ; I think after bgetc returns Beof, bungetc should change the state, but not decrement bp->icount. The correct code should be: int Bungetc(Biobufhdr *bp) { if(bp->state != Bractive) { if (bp->state == Bracteof) bp->state = Bractive; return Beof; } bp->icount--; return ...

+ Reply to Thread
Results 1 to 3 of 3

Thread: bungetc error

  1. bungetc error

    I think after bgetc returns Beof, bungetc should change the state, but
    not decrement bp->icount.

    The correct code should be:

    int
    Bungetc(Biobufhdr *bp)
    {
    if(bp->state != Bractive) {
    if (bp->state == Bracteof)
    bp->state = Bractive;
    return Beof;
    }
    bp->icount--;
    return 1;
    }

    instead of the current code:

    int
    Bungetc(Biobufhdr *bp)
    {

    if(bp->state == Bracteof)
    bp->state = Bractive;
    if(bp->state != Bractive)
    return Beof;
    bp->icount--;
    return 1;
    }

    Regards,
    Saroj Mahapatra

  2. Re: [9fans] bungetc error

    * smahapatra_ct@yahoo.com (smahapatra_ct@yahoo.com) wrote:
    > I think after bgetc returns Beof, bungetc should change the state, but
    > not decrement bp->icount.


    I don't think so. Bungetc ungets the last character read, not Beof.


  3. Re: [9fans] bungetc error

    i assumed the intention was:
    in practice it's sometimes a nuisance to have to keep a flag in the
    application to say whether eof has been reached or not,
    when it could be done by allowing an unget at eof.


+ Reply to Thread