[PATCH] misc: Add mkostempat (BZ 19866)

Paul Eggert eggert@cs.ucla.edu
Mon Jun 22 19:55:09 GMT 2026


On 2026-06-22 12:23, Adhemerval Zanella Netto wrote:

> Checking gnulib lib/tempname.h, think we can bake the dirfd argument with the
> cost of boilerplate:

Yes, the boilerplate is annoying - it's life in the callbacks big city.

>    struct my_ctx c = { dirfd, oflags, mode };
>    try_tempname (tmpl, suffixlen, &c, my_create);

We can shorten that a bit with a compound literal. And I suggest putting 
the function before its arg. Also, omit suffixlen, as the template's 
"X"s should tell the new function where any prefix and/or suffix lie, 
and how long the random part is. So something like this:

   try_tempname (tmpl, my_create, &(struct my_ctx){dirfd, oflags, mode});


> I am not a fan of these typeless void * arguments, but I live with it.

I'm no fan either but hey! it's C! Type safety is C++'s job (:-).

> there are still the issue of the safe default (forget O_EXCL (loses atomicity)
> or O_CLOEXEC (fd leak)). And these are still footguns that the non-callback avoids
We can address this by documenting a callback for use in a 
mkostempat-like function. People can then cut and paste out of the 
documentation if they like. The documentation can explain why O_EXCL and 
O_CLOEXEC are important.

Another idea is to put the new function, whatever it is, into Gnulib 
first and see whether people use it.


More information about the Libc-alpha mailing list