From mboxrd@z Thu Jan 1 00:00:00 1970 Date: Fri, 25 Aug 1995 07:02:41 -0400 From: forsyth@plan9.cs.york.ac.uk forsyth@plan9.cs.york.ac.uk Subject: Bseek and Brdline Topicbox-Message-UUID: 1bf7b912-eac8-11e9-9e20-41e7f4b1d025 Message-ID: <19950825110241.6FAtPWFncESFXaZ75Ox94ydjTW_-AZ8-OsaYjb3prH8@z> 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.