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

Re: [RFC][PATCH] mingw: avoid mktemp() in mkstemp() implementation

From
Junio C Hamano <gitster@pobox.com>
Date
Jul 15, 2022, 16:38 UTC
Message-ID
<xmqq1qum2uvy.fsf@gitster.g>
In-Reply-To
<b7fffe99-63fb-3899-6a6d-882b72b9512f@kdbg.org>
Johannes Sixt <j6t@kdbg.org> writes:
Show 20 quoted lines
>> diff --git a/compat/mingw.c b/compat/mingw.c
>> index 2607de93af..b5502997e2 100644
>> --- a/compat/mingw.c
>> +++ b/compat/mingw.c
>> @@ -1059,10 +1059,7 @@ char *mingw_mktemp(char *template)
>> 
>>  int mkstemp(char *template)
>>  {
>> -	char *filename = mktemp(template);
>> -	if (!filename)
>> -		return -1;
>> -	return open(filename, O_RDWR | O_CREAT, 0600);
>> +	return git_mkstemp_mode(template, 0600);
>>  }
>> 
>>  int gettimeofday(struct timeval *tv, void *tz)
>
> I hate such an obvious layering violation. But we have already a ton of
> them elsewhere (calling xmalloc from compat/, for example), so this is
> just a rant, not an objection.

There is intended behaviour difference between xmalloc() and malloc() that justifies your "layering violation" observation. A low level library replacement implemented in compat/ should not call die() when it fails to obtain memory and instead report an error.

But it is unclear git_mkstemp_mode() and some others in wrapper.c fall into the same category. With the posted implementation above, the end result is how the platform that lack working mkstemp() would implement it.

If we were to do something to make it "cleaner", I suspect that the above implementatoin of mkstemp() can be moved out of compat/mingw.c and made reusable by _anybody_ who lack mkstemp(), just like we ship memmem() emulation for anybody who lack it in contrib/memmem.c

Thanks.
Previous: Johannes SixtNext: René Scharfe
Message 3 of 5 in “mingw: avoid mktemp() in mkstemp() implementation”
  1. René ScharfeJul 15, 2022
  2. Johannes SixtJul 15, 2022
  3. Junio C HamanoJul 15, 2022
  4. René ScharfeJul 16, 2022
  5. Johannes SchindelinJul 15, 2022

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.