9fans - fans of the OS Plan 9 from Bell Labs
 help / color / mirror / Atom feed
* [9fans] bungetc error
@ 2008-01-02 11:00 smahapatra_ct
  2008-01-02 21:51 ` Martin Neubauer
  0 siblings, 1 reply; 3+ messages in thread
From: smahapatra_ct @ 2008-01-02 11:00 UTC (permalink / raw)
  To: 9fans

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


^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [9fans] bungetc error
  2008-01-02 11:00 [9fans] bungetc error smahapatra_ct
@ 2008-01-02 21:51 ` Martin Neubauer
  2008-01-03  0:24   ` Charles Forsyth
  0 siblings, 1 reply; 3+ messages in thread
From: Martin Neubauer @ 2008-01-02 21:51 UTC (permalink / raw)
  To: Fans of the OS Plan 9 from Bell Labs

* 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.


^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [9fans] bungetc error
  2008-01-02 21:51 ` Martin Neubauer
@ 2008-01-03  0:24   ` Charles Forsyth
  0 siblings, 0 replies; 3+ messages in thread
From: Charles Forsyth @ 2008-01-03  0:24 UTC (permalink / raw)
  To: 9fans

[-- Attachment #1: Type: text/plain, Size: 208 bytes --]

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.

[-- Attachment #2: Type: message/rfc822, Size: 3824 bytes --]

From: Martin Neubauer <m.ne@gmx.net>
To: Fans of the OS Plan 9 from Bell Labs <9fans@cse.psu.edu>
Subject: Re: [9fans] bungetc error
Date: Wed, 2 Jan 2008 22:51:28 +0100
Message-ID: <20080102215128.GB810@shodan.homeunix.net>

* 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.

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2008-01-03  0:24 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2008-01-02 11:00 [9fans] bungetc error smahapatra_ct
2008-01-02 21:51 ` Martin Neubauer
2008-01-03  0:24   ` Charles Forsyth

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).