Fix error handlings for fprintf().
Fix error handlings for fputs().
Merge pull request #2572 from cubicdaiya/issues/fprintf_error_handlings

Fix error handlings for fprintf() and fputs() to file.