V1_read_line() woes; possible bug?
McCauley Technical Services
darrellmy at ids.net
Thu Jan 14 04:22:45 EST 1993
Summary: Am I doing something very wrong, or is there something wrong
with V1_read_line()? Is V1_read_line() buggy w.r.t. detecting EOF?
While writing a function to remove duplicate items from a vector file,
I became puzzled by V1_read_line. The error that I was getting was:
SYSTEM_ERROR: NEW_T_OLD Got a bad type code fffffffe
I believe that it was trying to read past the end of the file.
There were only 7 area-edges in my test file. V1_read_line() read
these seven, then, while attempting to read an 8th, the error
message was generated and V1_read_line() returned -2. It should
have returned 0 on EOF. The only thing that I can think of
is that maybe when I reset the offset:
new_offset = ftell (Closet->dig_fp);
(after reading the 7th and final area-edge), something went
wrong.
I watched *Closet->dig_fp (my file pointer) with xdbx. When I got
the error, this is what I saw:
*Closet->dig_fp = {
_cnt = 0
_ptr = 0x24313
_base = 0x24108
_bufsiz = 8192
_flag = 9
_file = '^D'
(See /usr/include/stdio.h for the definition of FILE.)
The struct member _cnt decreased by 40 after each read until it
got to zero. What does this member of FILE signify? It seems like its
trying to tell me how far I have left until I reach the end of the
file. If so, perhaps V1_read_line() is not handling the EOF
very well.
I managed to avoid this error by first testing my file pointer:
if (Closet->dig_fp->_cnt == 0)
don't read anymore
Can anyone offer any comments/suggestions? Has this ever happened to
you? If anyone is *really* interested, I can supply full source and a
test dig_ascii file by anon ftp. The basic structure of what I was
trying to do is appended. My solution was to test Closet->dig_fp->_cur
in the second loop and put the second read statement in a
conditional if inside the second loop.
Thanks!
--Darrell
James Darrell McCauley phone: 317.497.4757
McCauley Technical Services internet: darrellmy at ids.net
P.O. Box 2485 West Lafayette, Indiana 47906-0485, USA
;;;;;;;;;;;;;;
Vect_rewind (Closet);
old_offset = ftell (Closet->dig_fp);
while (0 < (type = V1_read_line (Closet, Points_a, old_offset)))
{
new_offset = ftell (Closet->dig_fp);
while (0 < (type = V1_read_line (Closet, Points_b, new_offset)))
{
/* check remaining part of file for a match */
new_offset = ftell (Closet->dig_fp);
}
if (!match)
Vect_write_line (Suitcase, type, Points_a);
old_offset = ftell (Closet->dig_fp);
}
More information about the grass-dev
mailing list