We could straightforwardly replace gen_tempname and try_tempname with Rust implementations, probably from an existing crate.
This would let us remove tempname.c entirely.
I can grab this if no one else is interested.
It's yours! :)
Update on this. Open invite to anyone who spots any errors to correct me.
After investigation, it looks like __gen_tempname and __try_tempname are glibc functions, part of an internal API. If you attempt to compile emacs with a version of the c standard library that does not provide them, emacs will provide an implementation via tempname.c
It looks like emacs only uses this functions for an implementation of mkostemp, which is used in a number of different places in the code base. w32.c provides a custom implementation of this function for windows that does not utilize __gen_tempname or __try_tempname. __try_tempname only seems to be used by __gen_tempname. The ability to create a temporary directory, or to check if the temporary file exists via these functions seems to go unused in the emacs code base.
From my perspective, it seems that we want a rust-based replacement for mkostemp, that can be used cross platform. It looks like there are a number of solid crates in this space that can give us what we need. After implementing this, I would then delete the implementation of mkostemp in w32.c, and the implementation of __gen_tempname and __try_tempname, and update the places in code that use mkostemp to use our new rust function.