fixed fwrite error reporting bug