In Windows (MinGW), my program is inheriting unwanted handles from the calling process.
The process has no need to have these files open, but because it lives on beyond the lifetime of the parent I get the usual problems with files being held open.
On Linux I fix the problem like this:
// Close all file descriptors
// It's hard to figure out how many are open, but the first 1000 should do
int fd;
for (fd = 0; fd < 1000; fd++)
close (fd);
This does not appear to work in Windows.
How can I determine which file handles have been inherited? How can I then close them?
The project is written in C (no C++) using MinGW and Windows' Unix compatibility API.