Re: [PATCH v5 03/13] bisect--helper: introduce new `write_in_file()` function

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Miriam Rubio <mirucam@xxxxxxxxx> writes:

> +	fp = fopen(path, mode);
> +	if (!fp)
> +		return error_errno(_("cannot open file '%s' in mode '%s'"), path, mode);
> +	res = vfprintf(fp, format, args);
> +
> +	if (res < 0) {
> +		fclose(fp);
> +		return error_errno(_("could not write to file '%s'"), path);

If the fclose(fp) failed, the errno from that failure (i.e. why fp
cannot be closed) would be reported by the error_errno(), which may
not be ideal.  Either use just error() (which may be suboptimal),
follow an often-used pattern to use save_errno (grep for the symbol
to learn from the existing code) and keep using error_errno(), or
check errors from fclose() too (which may be overkill).

	if (res < 0) {
		int saved_errno = errno;
#if OVERKILL
		if (fclose(fp))
                	error_errno(_("..."));
#else
		fclose(fp);
#endif
		errno = saved_errno;
		return error_errno(_("..."), ...);
	}



[Index of Archives]     [Linux Kernel Development]     [Gcc Help]     [IETF Annouce]     [DCCP]     [Netdev]     [Networking]     [Security]     [V4L]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Linux SCSI]     [Fedora Users]

  Powered by Linux