Thread View: gnu.gcc.bug
1 messages
1 total messages
Started by Dr. David Curtis
Wed, 23 Dec 1992 09:09
fseek() bug in djgpp?
Author: Dr. David Curtis
Date: Wed, 23 Dec 1992 09:09
Date: Wed, 23 Dec 1992 09:09
72 lines
2669 bytes
2669 bytes
Am I being completely stupid, or does the djgpp version of fseek() just
not work _at_all_? Seeks to offsets relative to SEEK_CUR just go
completely wrong. I have a file called funcs.doc which suggests that it
should be possible to do seeks backwards or forwards from SEEK_END, but
only forwards from SEEK_CUR. If this is correct it sounds pretty
non-standard to me. Anyway, when I tried this out I found that no seeks
relative to SEEK_CUR worked correctly. See code to prove it below. I am
using DOS 5 and SMARTDRV.SYS, though I doubt this is anything to do with
it, and djgpp version 2.22. I am surprised that bugs as obvious as this
are present in library. What other bugs are known? - I still can't get
my f2c-translated code to run correctly....
Dave Curtis
Academic Department of Psychiatry, Janet: d.curtis@UK.AC.IC.SM
St. Mary's Hospital, Elsewhere: d.curtis@SM.IC.AC.UK
Praed Street, London W2. EARN/Bitnet: dcurtis%CRC@UKACRL
Tel 071-725 1993 Usenet:...!mcsun!ukc!mrccrc!D.Curtis
Test code:
(TEST.PED is any old text file, though opened in binary mode)
seeking backwards or forwards 5 from SEEK_CUR seems to move forwards by 17!!!
#include <stdio.h>
#define test(c) (printf("Trying %s ...\n",#c),printf("Result was %d\n",c))
#define tell() (printf("Now at %ld, ",ftell(fp)),\
printf("next character is 0x%x\n",fgetc(fp)))
main()
{
FILE *fp;
fp=fopen("TEST.PED","r+");
test(fseek(fp,0,0));
tell();
test(fseek(fp,0,0));
tell();
test(fseek(fp,0,2)); /* end */
tell();
test(fseek(fp,-10,2));
tell();
test(fseek(fp,10,0));
tell();
test(fseek(fp,5,1)); /* relative */
tell();
test(fseek(fp,-5,1));
tell();
}
Trying fseek(fp,0,0) ...
Result was 0
Now at 0, next character is 0x28
Trying fseek(fp,0,0) ...
Result was 0
Now at 0, next character is 0x28
Trying fseek(fp,0,2) ...
Result was 0
Now at 2212, next character is 0xffffffff
Trying fseek(fp,-10,2) ...
Result was 0
Now at 2202, next character is 0x2e
Trying fseek(fp,10,0) ...
Result was 0
Now at 10, next character is 0xa
Trying fseek(fp,5,1) ...
Result was 0
Now at 37, next character is 0x33
Trying fseek(fp,-5,1) ...
Result was 0
Now at 54, next character is 0x20
Thread Navigation
This is a paginated view of messages in the thread with full content displayed inline.
Messages are displayed in chronological order, with the original post highlighted in green.
Use pagination controls to navigate through all messages in large threads.
Back to All Threads