[PATCH] misc: Add mkostempat (BZ 19866)

Adhemerval Zanella Netto adhemerval.zanella@linaro.org
Mon Jun 22 20:03:23 GMT 2026



On 22/06/26 16:55, Paul Eggert wrote:
> 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 trying also to avoid in-place mutation of the template, where makes string literals
usage not possible and Florian [1] has noted that is another footgun.  It does force the
function to create the temporary name itself, but for some usage the caller does not
want always required it.

[1] https://sourceware.org/bugzilla/show_bug.cgi?id=19866#c1

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