When a program calls fread on a file immediately after writing a small amount of data, it may fail to flush the written data if the read size is greater than or equal to the FILE buffer size. The following test demonstrates this: #include <stdio.h> #include <assert.h> void main() { FILE *f; char foo[4096]; int n; f = fopen("/tmp/test", "a+"); /* qemu does fdopen */ assert(f); fwrite("Hello World!\n", 1, 13, f); n = fread(foo, 1, READ_SIZE, f); fprintf(stderr, "eof?%d %d", feof(f), n); fseek(f, 0, SEEK_SET); n = fread(foo, 1, sizeof(foo), f); fprintf(stderr, "eof?%d %d", feof(f), n); } 1) gcc test.c -DREAD_SIZE=4096 -o test (qemu-ga tries to read QGA_READ_COUNT_DEFAULT=4096 by default) ./test first read: 0 read after seek 0: 0 2) gcc test.c -DREAD_SIZE=13 -o test ./test first read: 0 read after seek 0: 13 Patch coming up.
However, the application shall ensure that output is not directly followed by input without an intervening call to fflush() or to a file positioning function (fseek(), fsetpos(), or rewind()),
. *** This bug has been marked as a duplicate of bug 17063 ***