Re: fseek and open_memstream



Dmitry Belous <dmitry_belous@xxxxx> wrote:

Why when I uncomment fseek line buf become empty?
#define _GNU_SOURCE
#include <stdio.h>

int main() {
char *buf = 0;
int size = 0;
FILE* f = open_memstream(&buf, &size);
fwrite("test", 1, 4, f);
// fseek(f, 0, SEEK_SET);
fclose(f);
fprintf(stderr, buf);
}

open_memstream() is not an ISO C function. It, or its return value,
probably interacts with fseek() in a way that clears buf, but _why_ this
happens is off-topic here. If it's a POSIX function (I don't know, your
compiler should tell you), ask in comp.unix.programmer. If it's not,
find a newsgroup that deals with your implementation - from the looks of
it, that's gcc, so ask gnu.help.something.

Richard
.



Relevant Pages