From: Johannes Sixt Date: Thu, 28 May 2009 07:07:32 GMT Subject: Re: [PATCH v2 1/2] compat: add a mkstemps() compatibility function Message-ID: <4A1E3834.3020502@viscovery.net> In-Reply-To: <1243491077-27738-1-git-send-email-davvid@gmail.com> David Aguilar schrieb: > +++ b/compat/mkstemps.c > @@ -0,0 +1,78 @@ > +#include > +#include > +#include > +#include > +#include > +#include > +#include > +#include ... > +#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 (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 -#include -#include -#include -#include -#include -#include -#include +#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).