git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Johannes Sixt <j.sixt@viscovery.net>
To: David Aguilar <davvid@gmail.com>
Cc: git@vger.kernel.org, gitster@pobox.com, markus.heidelberg@web.de,
	jnareb@gmail.com
Subject: Re: [PATCH v2 1/2] compat: add a mkstemps() compatibility function
Date: Thu, 28 May 2009 09:07:32 +0200	[thread overview]
Message-ID: <4A1E3834.3020502@viscovery.net> (raw)
In-Reply-To: <1243491077-27738-1-git-send-email-davvid@gmail.com>

David Aguilar schrieb:
> +++ b/compat/mkstemps.c
> @@ -0,0 +1,78 @@
> +#include <string.h>
> +#include <errno.h>
> +#include <stdio.h>
> +#include <fcntl.h>
> +#include <inttypes.h>
> +#include <unistd.h>
> +#include <sys/time.h>
> +#include <sys/types.h>
...
> +#ifndef O_BINARY
> +#define O_BINARY 0
> +#endif
...
> +		fd = open(pattern, O_BINARY|O_CREAT|O_EXCL|O_RDWR, 0600);

You should not include "random" system headers, nor has mkstemps any
business deciding whether files are opened in binary mode. We are not
using O_BINARY anywhere else (except in compat/mingw.c). With the patch
below squashed in (I hope it won't be wrapped) you can add:

Tested-by: Johannes Sixt <j6t@kdbg.org> (Windows)

to both your patches. And, yes, I like them :-)

-- Hannes

diff --git a/compat/mkstemps.c b/compat/mkstemps.c
index 10f9ed6..1cf7f3d 100644
--- a/compat/mkstemps.c
+++ b/compat/mkstemps.c
@@ -1,20 +1,9 @@
-#include <string.h>
-#include <errno.h>
-#include <stdio.h>
-#include <fcntl.h>
-#include <inttypes.h>
-#include <unistd.h>
-#include <sys/time.h>
-#include <sys/types.h>
+#include "../git-compat-util.h"

 #ifndef TMP_MAX
 #define TMP_MAX 16384
 #endif

-#ifndef O_BINARY
-#define O_BINARY 0
-#endif
-
 /* Adapted from libiberty's mkstemp.c. */
 int gitmkstemps(char *pattern, int suffix_len)
 {
@@ -57,7 +46,7 @@ int gitmkstemps(char *pattern, int suffix_len)
 		template[4] = letters[v % num_letters]; v/= num_letters;
 		template[5] = letters[v % num_letters]; v/= num_letters;

-		fd = open(pattern, O_BINARY|O_CREAT|O_EXCL|O_RDWR, 0600);
+		fd = open(pattern, O_CREAT|O_EXCL|O_RDWR, 0600);
 		if (fd > 0)
 			return fd;
 		/* Fatal error (EPERM, ENOSPC etc).

  parent reply	other threads:[~2009-05-28  7:07 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2009-05-28  6:11 [PATCH v2 1/2] compat: add a mkstemps() compatibility function David Aguilar
2009-05-28  6:11 ` [PATCH v2 2/2] diff: generate prettier filenames when using GIT_EXTERNAL_DIFF David Aguilar
2009-05-28 17:44   ` Jeff King
2009-05-28 21:30     ` David Aguilar
2009-05-28 22:06       ` Jeff King
2009-05-28  7:07 ` Johannes Sixt [this message]
2009-05-28  9:31   ` [PATCH v2 1/2] compat: add a mkstemps() compatibility function David Aguilar

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=4A1E3834.3020502@viscovery.net \
    --to=j.sixt@viscovery.net \
    --cc=davvid@gmail.com \
    --cc=git@vger.kernel.org \
    --cc=gitster@pobox.com \
    --cc=jnareb@gmail.com \
    --cc=markus.heidelberg@web.de \
    /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).