[PATCH v4] linux: Add openat2 (BZ 31664)
Paul Eggert
eggert@cs.ucla.edu
Tue Aug 26 20:02:52 GMT 2025
On 8/26/25 07:44, Florian Weimer wrote:
> * Paul Eggert:
>> Can you give a sample call that would break?
>
> Starting with GCC 14, the last two lines are reported as containing
> errors:
>
> void f(char *);
> void fc(const char *);
>
> void (*pf)(const char *) = f;
> void (*pfc)(char *) = fc;
Sure, but that's not a sample call as I requested. It's a contrived
example that is not likely to occur in real code. (And if there is true
concern about this instead of language-lawyering, I'm sure there are
workarounds.)
> I don't think sigaction is a good example because it is not extensible.
It is extensible, just perhaps not in the way one might like because one
cannot anticipate all extensions. openat2 is similar.
> POSIX examples for extensible interfaces are posix_spawn and
> pthread_attr_t, where each attribute ends up with two functions. That
> approach isn't great, either.
Agreed that there is no perfection. However, there are real advantages
to having two functions, one for getting and one for setting. That is
why the getter/setter approach has so many instances already. openat2
should follow existing practice and not try to invent a new one (for no
particularly strong reason).
> If we don't pass through the system call interface unchanged, past
> experience tells us that this causes problems in the future.
For this particular case there will be problems no matter what we do.
That's clear from the Linux man pages, which give two disagreeing APIs
for openat2. In cases like these, it's often better to do the right
thing even if it's a bit more work, than to do the wrong thing.
More information about the Libc-alpha
mailing list