[PATCH] misc: Add mkostempat (BZ 19866)
Paul Eggert
eggert@cs.ucla.edu
Thu Jun 18 21:06:36 GMT 2026
On 2026-06-18 12:55, Adhemerval Zanella Netto wrote:
> * openat2 as generic ABI with its extendable open_how is not a good fit:
> it would require additional versions each time we extend it.
Do you mean multiple versions like the _TIME_BITS mess? But openat2
shouldn't need additional versions for that, if it increases the size of
its struct layout. And I'm not seeing why a revised mkostempat would
need it either. So I'm not quite following here.
> * We will need to add a fallback for older kernels and Hurd; and I *really*
> do not want to pull the gnulib implementation. Mainly because kernel
> fallback has bitten us in the past and it is a pain to maintain.
That's fine, just return EOPNOTSUPP for flags you can't implement.
> There is also the question of each openat2 flag would be really a gain
> for this interface.
I suspect the designers of mkstemp had similar thoughts, many years ago:
"Who needs all those flags? Let's just keep the interface simple. Nobody
will want to use those flags." That was a mistake.
Come to think of it, why not address this issue with a callback instead?
That is, replace the dirfd, oflags and mode argument with a closure,
namely, a function f and a void *arg. mkostemp calls f (name, arg) to
create the file. Then the caller can use whatever fancy flags they like.
sysdeps/posix/tempname's try_tempname function, which is currently
compiled only for Gnulib, already does this. So why not do something
along those lines? It would avoid the ABI and fallback issues that you
mention. And Gnulib provides existing practice for this idea.
More information about the Libc-alpha
mailing list