Add g_fstat() function to get race-free file status information on open streams
Hi,
I'm writing a GLib application, and I think it's necessary for GLib to add a g_fstat()
function. g_stat()
exists to deal with Windows-specific quirks, but g_fstat()
is needed to avoid time-of-check-to-time-of-use-related race conditions pertaining to already open files. The inode corresponding to a filename might change between calls to fopen()
and g_stat()
. Furthermore, the /dev/fd/
filesystem is not available on Windows.
GLib does provide portable access to file descriptors, but g_fileno()
is necessary to get a file descriptor that can be used with g_fstat()
.
Without these two functions, there is no portable way to get the size, for example, of a file corresponding to an open stream as best as I can tell.
Thanks for your consideration