Re: seek() bug?
- Posted by Derek Parnell <ddparnell at bigpond.com> Feb 15, 2002
- 515 views
Kat and Robert, I can confirm that there is a bug somewhere in Euphoria's handling of puts(), gets(), seek(), and where() when using a file opened for either "u" or "ub". Here is the sample code I used to confirm it. It converts a text file into all 'A' so its not practical except to demonstrate this bug. If you run it with anthing on the command line, it works. The trick to making it work is that I reset the file position using seek() AFTER I do a puts(). I don't understand why this works, because I used seek() and where() often in the past without problems. -------------- include file.e include get.e without warning with trace trace(1) sequence index_noun integer indexfile object readline object newreadline object env atom junk_i, seek_i, junk_j, junk_k env = command_line() index_noun = "sample.f" indexfile = open(index_noun,"ub") readline = gets(indexfile) while not atom(readline) do -- generate a line the same length as the current one. newreadline = repeat('A', length(readline)-2) & 13 & 10 -- Find out where I am junk_k = where(indexfile) -- Calc the posn of the START of the line just read in junk_i = junk_k - length(readline) -- Move to the start of the line seek_i = seek(indexfile,junk_i) -- confirm that it worked junk_i = where(indexfile) -- Replace the line with generated one puts(indexfile,newreadline) if length(env) > 2 then -- Works if this line is executed. seek_i = seek(indexfile, junk_i + length(newreadline)) end if -- See if I now where I should be junk_j = where(indexfile) -- read next line readline = gets(indexfile) end while close(indexfile) -------------- Derek ----- Original Message ----- From: "Kat" <gertie at PELL.NET> To: "EUforum" <EUforum at topica.com> Sent: Friday, February 15, 2002 9:33 AM Subject: Re: seek() bug? > > On 15 Feb 2002, at 15:58, Robert Craig wrote: > > > > > Kat writes: > > > So is there a buglist for seek? > > > > There aren't any known bugs in seek(). > > EDS uses seek() extensively, and there aren't > > any known bugs in EDS either. > > > > > Is seek() maybe allergic to long filenames, or > > > filenames with sp aces in them? > > > > The file name is irrelevant to seek(), but > > there are some potential "gotchas". > > > > 1. It's strongly recommended that you open the file in binary mode, > > "rb", "wb" or "ub". (otherwise \r\n is secretly converted to \n by the o/s, > > and you'll go crazy trying to set the file position correctly) > > > > 2. Opening in append mode, "a" is possibly a bit dicey. > > A bug was fixed in 2.3 official in that case because of > > a Watcom bug. > > > > 3. The Euphoria manual states: > > "After seeking and reading (writing) a series of bytes, you may > > need to call seek() explicitly before you switch to writing > > (reading) bytes, even though the file position should already be > > what you want." > > > > If you can reduce the problem to something small, but runnable, > > and post it here, maybe we can see the problem. > > I did, but you missed the ',' remember? > > Kat > > > >