git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: "René Scharfe" <rene.scharfe@lsrfire.ath.cx>
To: Junio C Hamano <gitster@pobox.com>
Cc: carlos.duclos@nokia.com, git@vger.kernel.org
Subject: Re: [PATCH v3] git-archive: Add new option "--output" to write   archive to a file instead of stdout.
Date: Tue, 17 Feb 2009 23:59:50 +0100	[thread overview]
Message-ID: <499B4166.90609@lsrfire.ath.cx> (raw)
In-Reply-To: <7v7i3o6h8x.fsf@gitster.siamese.dyndns.org>

Junio C Hamano schrieb:
> <carlos.duclos@nokia.com> writes:
>> +static void create_output_file(const char *output_file)
>> +{
>> +	int output_fd = open(output_file, O_CREAT | O_WRONLY | O_TRUNC, 0666);
>> +	if (output_fd < 0)
>> +		die("could not create archive file: %s ", output_file);
>> +	if (output_fd != 1)
>> +		if (dup2(output_fd, 1) < 0) {
>> +			/*
>> +			 * dup2 closes output_fd on success, if something 
>> +			 * goes wrong we close output_fd here to avoid
>> +			 * problems.
>> +			 */
>> +			close(output_fd);
>> +			die("could not redirect output");
> 
> The comment and close() are probably unnecessary, as you will die()
> immediately.

dup2() closes the second file, not the first one (but not if it's the
same as the first one), so the comment is incorrect.  And I agree it's
OK to just die() without cleaning up, as this is a fatal error anyway
and an unlikely one on top of that.  How about something like this?

	if (dup2(output_fd, 1) < 0)
		die("could not redirect output");
	close(output_fd);

René

      reply	other threads:[~2009-02-17 23:01 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2009-02-17  9:42 [PATCH v3] git-archive: Add new option "--output" to write archive to a file instead of stdout carlos.duclos
2009-02-17 18:38 ` Junio C Hamano
2009-02-17 22:59   ` René Scharfe [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=499B4166.90609@lsrfire.ath.cx \
    --to=rene.scharfe@lsrfire.ath.cx \
    --cc=carlos.duclos@nokia.com \
    --cc=git@vger.kernel.org \
    --cc=gitster@pobox.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).