bug report

Andres Takach takach@ece.iit.edu
Wed Feb 12 16:36:00 GMT 1997


There seems to be a problem in the read() (getc etc.) when
reading binary files. A character 1A can confuse the read
to think that it has found the end of file.

This problem also happens when using the gnu-win92 "od" program.
In fact it also happens on the perl implementation for win 95/NT.
The perl problem happens on even NT machines. 

I have included below a simple c program that exposes the problem.

Andres Takach


#include <stdio.h>
#include <stdlib.h>

/* this program illustrates the fact that if the character 1A is
  present in a binary file, getc() will return an EOF at that point
  (same can be said about read() etc.)  The output of this program
  should be 13 (13 chars in file "temp") but instead it is 2.
  Program "od" will also quit early and same can be said about
  perl for windows 95/NT.
*/

main(){
  FILE *fp;
  int ch;
  int count = 0;
  int i;
  fp = fopen("temp","w");

/* Write two random chars to "temp"*/
  putc(255,fp); 
  putc('a',fp);
  
/* Write offending char 26 (Hex 1A) to "temp" */
  putc(26,fp);    

/* Write 10 more 'a's to file "temp"  and close file */
  for(i=0; i < 10; i++) putc('a',fp);  /* 10 more bytes */
  fclose(fp);

/* Attempt to count # of bytes in "temp" */
  fp = fopen("temp","r");
  while( getc(fp)!= EOF) count++;
  /* should be 13 bytes */
  printf("Number of bytes: %d\n",count);
}


More information about the Cygwin mailing list