yes I did (in fact first version of the test was along these lines |A]) but it doesn't work for FILE_TYPE_CHAR or PIPE types we may also want to test that's why I considered another implementation to support more types, and input or output streams
perhaps another alternative to not use UCRT FILE layout would be to use _get_stream_buffer_pointers() for the ucrtbase tests and check if the test should work depending just on the returned 3 fields (basically dropping the bufsize related tests, and guessing the charbuf by being inside [file, file+1( memory range (or a fixed length if the MSVCRT FILE is too short wrt/ field offset of charbuf in UCRT FILE))
[A] + could even detect if line buffering is happening + fragile on console output because of scrolling (hence the move to top of screenbuffer) + need more work on PIPE + need extra work on input for console ``` #include <wincon.h> static unsigned get_handle_position(HANDLE h) { CONSOLE_SCREEN_BUFFER_INFO sbi;
if (GetConsoleScreenBufferInfo(h, &sbi)) return sbi.dwSize.X * sbi.dwCursorPosition.Y + sbi.dwCursorPosition.X; return GetFileSize(h, NULL); }
static enum buffer_state get_buffer_state(FILE *f) { HANDLE handle = (HANDLE)_get_osfhandle(_fileno(f)); unsigned sz_beg, sz_nonl, sz_nl, sz_flush; COORD c = {};
SetConsoleCursorPosition(handle, c); /* to avoid scrolling if connected to console */ sz_beg = get_handle_position(handle); fwrite("foo", 3, 1, f); sz_nonl = get_handle_position(handle); fwrite("bar\n", 4, 1, f); sz_nl = get_handle_position(handle); fflush(f); sz_flush = get_handle_position(handle); ok(sz_beg <= sz_nonl && sz_nonl <= sz_nl && sz_nl <= sz_flush && sz_beg < sz_flush, "SDF\n"); if (sz_beg == sz_nl && sz_nl < sz_flush) return BUFFER_IOFBF; if (sz_beg == sz_nonl && sz_nonl < sz_nl && sz_nl == sz_flush) return BUFFER_IOLBF; if (sz_beg < sz_nonl && sz_nonl < sz_nl && sz_nl == sz_flush) return BUFFER_IONBF; return BUFFER_ERROR; } ```