git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Junio C Hamano <gitster@pobox.com>
To: Johannes Sixt <j6t@kdbg.org>
Cc: "René Scharfe" <l.s.r@web.de>, "Git List" <git@vger.kernel.org>,
	"Johannes Schindelin" <johannes.schindelin@gmx.de>
Subject: Re: [RFC][PATCH] mingw: avoid mktemp() in mkstemp() implementation
Date: Fri, 15 Jul 2022 09:38:57 -0700	[thread overview]
Message-ID: <xmqq1qum2uvy.fsf@gitster.g> (raw)
In-Reply-To: <b7fffe99-63fb-3899-6a6d-882b72b9512f@kdbg.org> (Johannes Sixt's message of "Fri, 15 Jul 2022 08:00:58 +0200")

Johannes Sixt <j6t@kdbg.org> writes:

>> 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.



  reply	other threads:[~2022-07-15 16:39 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-07-15  3:58 [RFC][PATCH] mingw: avoid mktemp() in mkstemp() implementation René Scharfe
2022-07-15  6:00 ` Johannes Sixt
2022-07-15 16:38   ` Junio C Hamano [this message]
2022-07-16  6:30     ` René Scharfe
2022-07-15 14:27 ` Johannes Schindelin

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=xmqq1qum2uvy.fsf@gitster.g \
    --to=gitster@pobox.com \
    --cc=git@vger.kernel.org \
    --cc=j6t@kdbg.org \
    --cc=johannes.schindelin@gmx.de \
    --cc=l.s.r@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).