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

Re: [PATCH 1/4] wrapper: add git_mkdtemp()

From
Junio C Hamano <gitster@pobox.com>
Date
Dec 5, 2025, 23:05 UTC
Message-ID
<xmqqikek7cn1.fsf@gitster.g>
In-Reply-To
<65c997a7-e480-4617-a761-fc9dc8a7b20d@web.de>
René Scharfe <l.s.r@web.de> writes:
> -int git_mkstemps_mode(char *pattern, int suffix_len, int mode)
> +static int git_mkdstemps_mode(char *pattern, int suffix_len, int mode, bool dir)

This is a file-scope static, so as long as it is understood by those who futz with things in this file well, there is no need to go extra mile to avoid confusion, but the meaning of the returned value from this function is vastly different depending on the value of "dir". It used to be that you can subject it to write(2), but obviously that is not relevant when you called mkdir(2) here.

Show 10 quoted lines
>  {
>  	static const char letters[] =
>  		"abcdefghijklmnopqrstuvwxyz"
> @@ -471,7 +471,10 @@ int git_mkstemps_mode(char *pattern, int suffix_len, int mode)
>  			v /= num_letters;
>  		}
>  
> -		fd = open(pattern, O_CREAT | O_EXCL | O_RDWR, mode);
> +		if (dir)
> +			fd = mkdir(pattern, mode);

OK. The caller calls this helper with 0700 (S_IRWXU), so that's probably OK. If we can make this into two helper functions with distinct function signatures that share the majority of logic, it would have been much nicer, but short of introducing a callback function I do not think of a good way, so I'll let it pass.

> +		else
> +			fd = open(pattern, O_CREAT | O_EXCL | O_RDWR, mode);
>  		if (fd >= 0)
>  			return fd;
Previous: Chris TorekNext: René Scharfe
Message 4 of 19 in “ban mktemp(3)”
  1. 0/4 ban mktemp(3)René Scharfe, Dec 3, 2025
  2. 1/4 wrapper: add git_mkdtemp()René Scharfe, Dec 3, 2025
  3. Chris TorekDec 4, 2025
  4. Junio C HamanoDec 5, 2025
  5. 2/4 compat: use git_mkdtemp()René Scharfe, Dec 3, 2025
  6. Jeff KingDec 3, 2025
  7. René ScharfeDec 5, 2025
  8. Jeff KingDec 6, 2025
  9. Junio C HamanoDec 5, 2025
  10. 3/4 compat: remove mingw_mktemp()René Scharfe, Dec 3, 2025
  11. 4/4 banned.h: ban mktemp(3)René Scharfe, Dec 3, 2025
  12. Jeff KingDec 3, 2025
  13. 0/5 ban mktemp(3)René Scharfe, Dec 6, 2025
  14. 1/5 wrapper: add git_mkdtemp()René Scharfe, Dec 6, 2025
  15. 2/5 compat: use git_mkdtemp()René Scharfe, Dec 6, 2025
  16. 3/5 compat: remove mingw_mktemp()René Scharfe, Dec 6, 2025
  17. 4/5 banned.h: ban mktemp(3)René Scharfe, Dec 6, 2025
  18. 5/5 compat: remove gitmkdtemp()René Scharfe, Dec 6, 2025
  19. Jeff KingDec 8, 2025

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.