🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: gnu.gcc.bug
Article #1449

fseek() bug in djgpp?

#1449
From: Dr. David Curtis
Date: Wed, 23 Dec 1992 09:09
72 lines
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
Technical Details
Message-ID: <1992Dec23.090918.4842@crc.ac.uk>
Path: arc1-ca.pugleaf.net!sparky!uunet!cis.ohio-state.edu!mrc-crc.ac.UK!dcurtis

Show Full Headers
Complete Article Headers
Newsgroups: gnu.gcc.bug
Path: arc1-ca.pugleaf.net!sparky!uunet!cis.ohio-state.edu!mrc-crc.ac.UK!dcurtis
From: dcurtis@mrc-crc.ac.UK (Dr. David Curtis)
Subject: fseek() bug in djgpp?
Message-ID: <1992Dec23.090918.4842@crc.ac.uk>
Sender: gnulists@ai.mit.edu
Organization: MRC Human Genome Resource Centre
Distribution: gnu
Date: Wed, 23 Dec 1992 09:09:18 GMT
Approved: bug-gcc@prep.ai.mit.edu
Lines: 74