git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: [PATCH v3] git-archive: Add new option "--output" to write archive to a file instead of stdout.

From
René Scharfe <rene.scharfe@lsrfire.ath.cx>
Date
Feb 17, 2009, 22:59 UTC
Message-ID
<499B4166.90609@lsrfire.ath.cx>
In-Reply-To
<7v7i3o6h8x.fsf@gitster.siamese.dyndns.org>
Junio C Hamano schrieb:
Show 18 quoted lines
> <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é
Previous: Junio C Hamano
Message 3 of 3 in “git-archive: Add new option "--output" to write archive to a file instead of stdout.”
  1. git-archive: Add new option "--output" to write archive to a file instead of stdout.carlos.duclos@nokia.com, Feb 17, 2009
  2. Junio C HamanoFeb 17, 2009
  3. René ScharfeFeb 17, 2009

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.