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 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 >#include > >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); > } > } > }