I have encountered unexpected behaviour with open_memstream(). Below is a test case that shows the problem. Shouldn't each invocation of open_memstream() create a a stream in the same initial state? Shouldn't 'B' be written to the beginning of the buffer?
I am running Windows 7 Professional Ver 6.1 Build 7601 Service Pack 1 on an 8 processor amd64. My cygwin DLL version is 1.7.28. I am running the 32-bit install. Actual output: test: A buf: 41 0 0 0 0 0 0 0 0 0 test: B buf: 0 42 0 0 0 0 0 0 0 0 assertion "0 == strcmp(msg, buf)" failed: file "test_open_memstream.c", line 33, function: Test Aborted (core dumped) Expected output: test: A buf: 41 0 0 0 0 0 0 0 0 0 test: B buf: 42 0 0 0 0 0 0 0 0 0 Test program for GCC 4.8.2 (gcc -Wall -Wextra -pedantic -g test_open_memstream.c): #include <assert.h> #include <stdio.h> #include <stdlib.h> #include <string.h> FILE* RS232_1_tx = 0; void printbuf(char* buf){ int i = 0; printf("buf: "); for (i = 0; i < 10; ++i) { printf("%x ", buf[i]); } printf("\n"); } void io_operations(char* msg){ fprintf(RS232_1_tx, msg); } void Test(char* msg) { char* buf = 0; size_t size = 0; printf("test: %s\n", msg); RS232_1_tx = open_memstream(&buf, &size); /* Following fseek required to work around suspected bug in the lib. */ /* fseek(RS232_1_tx, 0, SEEK_SET); */ assert(RS232_1_tx); io_operations(msg); fflush(RS232_1_tx); printbuf(buf); assert(0 == strcmp(msg, buf)); fclose(RS232_1_tx); RS232_1_tx = 0; free(buf); } int main() { Test("A"); Test("B"); return 0; } -- Adam Burry -- Problem reports: http://cygwin.com/problems.html FAQ: http://cygwin.com/faq/ Documentation: http://cygwin.com/docs.html Unsubscribe info: http://cygwin.com/ml/#unsubscribe-simple