We should never mix FILE I/O with raw I/O. Going from raw I/O to FILE I/O is fine but doing the opposite is extremely tricky and only works under certain conditions (unbuffered stream + no call to ungetc()).