Implement fflush for stdout and stderr. #2770.