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

Re: [OT] Help with glibc memory streams



On 2000-10-29, Ben Collins <bcollins@debian.org> wrote:
> This is, IMO, a legitimate bug. Note, I also tested this same problem with
> fgetc() and it worked perfectly, so this is a problem in fgets.

I beg to differ.

#include <stdio.h>

int main()
{
   char *str = "test\nbar\n";
   char c;
   FILE *stream;

   stream = fmemopen(str, strlen(str), "r");
   while (EOF != (c = fgetc(stream)) && !ferror (stream)) {
      putchar (c);
   }
   if (ferror (stream))
           fprintf (stderr, "ferror!\n");
   if (feof (stream))
           fprintf (stderr, "feof!\n");
   fclose(stream);
   return 0;
}

results in:
test
bar
ferror!

Hm. When the \n after bar is omitted, the ferror gets thrown right after
reading and writing the line "test". Now, I also believe that this is a
bug.

Eray, I owe you an apology.

regards,
-- 
Andreas Fuchs, <asf@acm.org>, <d96001@htlwrn.ac.at>, antifuchs



Reply to: