#include #include #include int main() { fprintf(stderr, "Writing incomplete line to stdout (_IOLBF=%d)...\n", stdout->_buf.mode); fputs("hi!", stdout); sleep(3); putchar('\n'); fprintf(stderr, "Incomplete line should have been written.\n"); FILE* f = fopen("/dev/console", "w+"); assert(f); assert(setvbuf(f, NULL, _IOFBF, 0) == 0); fprintf(stderr, "Writing long text to file (_IOFBF=%d)...\n", f->_buf.mode); fputs("Hello world!\nHow are you doing!\nThis is a test for many lines of buffering.\n", f); sleep(3); fflush(f); fprintf(stderr, "Long text should have been written.\n"); fclose(f); }