As of 2.23 the glibc seems to have changed its behavior on an fflush of a stream created with fmemopen, in that it resets the position to 0. I saw in the change-log that a the implementation of fmemopen was updated to fix a bunch of bugs, but none of those bugs talk about this behavior, and to me it seems like an incorrect change. I've been trying to determine if this a new bug, or a correct fix. My own code relies on the old behavior and broke after I updated to Ubuntu 16.04 which comes with glibc 2.23. Anybody know anything about this?
Here's some sample code:
char buffer[500] = "x";
FILE *stream;
stream = fmemopen(buffer, 500, "r+");
fwrite("fish",sizeof(char),5,stream);
printf("pos-1:%ld\n",ftell(stream));
fflush(stream);
printf("pos-2:%ld\n",ftell(stream));
On earlier versions (e.g. under ubuntu 5.10<) this would result in:
pos-1:5
pos-2:5
Now it returns:
pos-1:5
pos-2:0
It turns out to be a bug in 2.23. The bug was logged and has been fixed.