This is the mail archive of the
libc-help@sourceware.org
mailing list for the glibc project.
Re: Stream buffering and flushing behaviour
- From: Marc-Andrà Lureau <marcandre dot lureau at gmail dot com>
- To: "Carlos O'Donell" <carlos at redhat dot com>
- Cc: libc-help at sourceware dot org
- Date: Tue, 7 Jul 2015 20:43:11 +0200
- Subject: Re: Stream buffering and flushing behaviour
- Authentication-results: sourceware.org; auth=none
- References: <CAJ+F1CKnViodfEb=q8dspEkQnyyJ_+q-P1e+7X4w=-ATG081Dw at mail dot gmail dot com> <559C192B dot 7060501 at redhat dot com>
Hi Carlos
On Tue, Jul 7, 2015 at 8:23 PM, Carlos O'Donell <carlos@redhat.com> wrote:
>> with READ_SIZE >= 4096, there is no implicit flush taking place, while
>> with READ_SIZE < 4096 (13 for ex), it does flush to disk and
>> subsequent read after seek will return the expected buffer.
>
> Do you mean `fread after fseek`?
yes
> I don't see anything. Do you have a test case that shows the problem?
> Expected and observed results?
Sorry, the example code is a bit borked, here is a simpler version:
#include <stdio.h>
#include <assert.h>
int main()
{
FILE *f;
char foo[4096];
int n;
f = fopen("/tmp/test", "w+");
assert(f);
fwrite("Hello World!\n", 1, 13, f);
n = fread(foo, 1, FIRST_READ_SIZE, f);
assert(n == 0);
fseek(f, 0, SEEK_SET);
n = fread(foo, 1, sizeof(foo), f);
assert(n == 13);
return 0;
}
Compiled with -DFIRST_READ_SIZE=4096 = fail, -DFIRST_READ_SIZE=13 = pass.
Is this expected?
thanks