9fans - fans of the OS Plan 9 from Bell Labs
 help / color / mirror / Atom feed
From: forsyth@plan9.cs.york.ac.uk forsyth@plan9.cs.york.ac.uk
Subject: Bseek and Brdline
Date: Fri, 25 Aug 1995 07:02:41 -0400	[thread overview]
Message-ID: <19950825110241.6FAtPWFncESFXaZ75Ox94ydjTW_-AZ8-OsaYjb3prH8@z> (raw)

the new release appeared to break one of my programs,
and at first i thought it was a bug in new code in Bseek, but it
turns out to be my fault.

the new release changed Bseek to reuse the contents of
the Biobuf when possible, avoiding i/o.
many applications of Brdline, however, have the following form

	while((line = Brdline(f, '\n')) != 0) {
		line[Blinelen(f)-1] = 0;	/* replace '\n' */
		...
	}

this is a bad idea in combination with the new Bseek,
since it removes a newline from buffer contents that
a subsequent Bseek might preserve.  a later Brdline
will appear to malfunction, although it is just following orders.
it will not find the original newline, since it is now 0, and
will either find an untouched newline further down the file
or return an indication that the line seems to be bigger
than the buffer size!

it suffices to restore the '\n' at the end of the loop body,
but there might be more attractive solutions depending on the
application.  it can be tricky to spot, though, if the Brdline
is hidden in a library separate from the program that calls Bseek.






                 reply	other threads:[~1995-08-25 11:02 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=19950825110241.6FAtPWFncESFXaZ75Ox94ydjTW_-AZ8-OsaYjb3prH8@z \
    --to=forsyth@plan9.cs.york.ac.uk \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).