Message52509
I confirmed that fread can read data from fp in EOF state on Linux. On OS X, freading from fp in EOF state doesn't work,
just return 0.
I tested this behavior using the following code.
----------------------------
#include <stdio.h>
#include <stdlib.h>
main(void)
{
FILE *fp1, *fp2;
int n;
char buf[128];
fp1 = fopen("spam.txt", "w+");
fputs("foo", fp1);
fseek(fp1, 0L, SEEK_END);
if (fread(buf, 1, sizeof(buf), fp1) == 0)
fprintf(stderr, "first fread failed\n");
fp2 = fopen("spam.txt", "a+");
fputs("bar", fp2);
fclose(fp2);
if (feof(fp1))
fprintf(stderr, "after appending some text, fp1 is still eof\n");
if (fread(buf, 1, sizeof(buf), fp1) == 0)
fprintf(stderr, "second fread failed\n");
printf("buf: %s\n", buf);
fclose(fp1);
return 0;
}
----------------------------
=============
On Linux
=============
first fread failed
after appending some text, fp1 is still eof
buf: bar
=============
On OS X
=============
first fread failed
after appending some text, fp1 is still eof
second fread failed
buf:
Anyway, I think it's safe and preferable to clear EOF indicator in this case. |
|
Date |
User |
Action |
Args |
2007-08-23 15:58:12 | admin | link | issue1706039 messages |
2007-08-23 15:58:12 | admin | create | |
|