Improve insert-file-contents on non-regular files
This is part of a fix for Bug#77315,
and improves on the fix for Bug#71258.
* src/fileio.c (Finsert_file_contents): Do not pretend that
directories are regular files. Instead, signal an error when
attempting to read from them in the usual case where the OS
prohibits that; and otherwise read from them. However, when
visiting a directory report an error right away rather than
waiting until later, as this function is documented to not allow
visiting non-regular files. Nest the struct stat into a small
code block, to keep the code simpler and so that the compiler can
see what parts are used and can issue better diagnostics if
uninitialized storage is accessed. Be more skeptical of st_size,
when the file is not regular.
(cherry picked from commit
6d09a339ceb986de6d2a49ac8c20a7360f57b7d6)