[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

[OT] Help with glibc memory streams



Hi,

Could you please help me identify what's wrong with this
test program that I've written? It'd seem to be a bug
with glibc but of course no hurrying.

The problem is that EOF descriptor isn't updated correctly
in the case of memory streams. At the EOF, I simply get
an error for any operation that I do. Please compile and
run the program to verify this.

Thanks,

-- 
Eray (exa) Ozkural
Comp. Sci. Dept., Bilkent University, Ankara
e-mail: erayo@cs.bilkent.edu.tr
www: http://www.cs.bilkent.edu.tr/~erayo
#include <stdio.h>

void main()
{
   char *str = "test";
   char line[80];
   FILE *stream;
   
   stream = fmemopen(str, strlen(str), "r");
   while (!feof(stream)) {
      if (!fgets(line, 80, stream)) {
      	printf("read error!\n");
        exit(-1);
      }
      printf("Read: %s", line);
   }
   fclose(stream);
}

Reply to: