delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1994/04/11/15:34:33

To: djgpp AT sun DOT soe DOT clarkson DOT edu
Cc: chris AT a DOT cs DOT okstate DOT edu
Subject: possible fseek bug
Date: Mon, 11 Apr 94 14:08:04 -0500
From: Chris Schuermann <chris AT a DOT cs DOT okstate DOT edu>

A co-worker asked that I forward this to 'some djgpp people'.  He believes
that this demonstrates a bug in the fseek function.  I don't work with
DOS much so I can't comment (although the code seems to function under
Linux/GCC).  Sorry if this is something already well-discussed or if it
is due to programmer stupidity.

Please respond to 
chris AT a DOT cs DOT okstate DOT edu

Thanks!
Chris

----------------------------------------------------------------------------
>/*
>DOS GCC fseek(....,SEEK_CUR) on a "text" file appears to be buggy.  Run the
>pgm below and note the results of an fseek(infile,0L,SEEK_CUR).
>
>*/
>
>#include <stdio.h>
>#include <unistd.h>
>
>main(int argc,char *argv[])
>   {
>   FILE
>      *outfile,
>      *infile;
>   char
>      buff[100];
>   int
>      rtn,
>      i;
>   long
>      where;
>
>   if(argc > 1)
>      {
>      if((infile=fopen(argv[1],"r")) != NULL)
>         {
>         if(argc > 2)
>            {
>            if((outfile=fopen(argv[2],"w")) != NULL)
>               {
>               fseek(infile,0L,SEEK_SET);
>               printf("fseek(infile,0L,SEEK_SET) at %ld\n",ftell(infile));
>               while(1)
>                  {
>                  printf("where ?: ");
>                  if(scanf("%ld",&where) == 0) break;
>                  fseek(infile,where,SEEK_CUR);
>                  printf("fseek(infile,%ld,SEEK_CUR) at %ld\n",where,ftell(infile));
>                  fread(buff,1,100,infile);
>                  printf("fread(buff,1,100,infile) at %ld\n",ftell(infile));
>                  fprintf(outfile,"%s",buff);
>                  }
>               fclose(outfile);
>               }
>            }
>         fclose(infile);
>         }
>      }
>   }

- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019