rtlib: Call setvbuf() before doing I/O, to avoid undefined behaviour

based on patch by TeeEmCee from sourceforge.net/u/teeemcee/fbc.