[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
file SEEK behavior changed
From: |
Daniel J Sebald |
Subject: |
file SEEK behavior changed |
Date: |
Tue, 27 Apr 2004 18:38:09 -0500 |
User-agent: |
Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.0.2) Gecko/20021120 Netscape/7.01 |
I came across a change in behavior for the file I/O between 2.1.46 and
2.1.57. It has to do with the "fread" reading past the end of the file.
The following code used to work fine in 2.1.46. It is part of an
application that will read in LENGTH samples of data and display the
data; it steps through the data upon the user hitting the proper key
stroke. When it gets to the end of the file and runs out of data, this
chunk of code is supposed to realign with the end of the file.
[x_c,N_x_c] = fread(ifid,LENGTH,'int16');
%# Position to last block in file if read past end.
if (N_x_c < LENGTH)
if ((ipos + N_x_c) < LENGTH)
LENGTH = ipos + N_x_c;
OVERLAP = floor(LENGTH/5);
f_res = min(floor(LENGTH/40)*2, MAX_FFT_SIZE);
end
* cstatus = fseek(ifid, -2*LENGTH, SEEK_END);
ipos = ftell(ifid)/2;
[x_c,N_x_c] = fread(ifid,LENGTH,'int16');
if (create_pdf_file)
%# Make this the last page if creating a PDF file.
finished = 1;
end
end
However, in 2.1.57 this code fails to realign to the end of the file.
In particular, the line I marked above with a star (*) keeps coming
back with a -1 instead of a 0. My fix has been to close the file and
reopen it right before the * line of code. This fixes the problem so
that it now behaves like it did in 2.1.46.
Dan
rand seed, Daniel J Sebald, 2004/04/27