This is the mail archive of the cygwin@sourceware.cygnus.com mailing list for the Cygwin project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

bug report



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

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]