> Manually calling close() in a loop is slow and it's not clear how many
> fd's to try.
An emulation would go something like this:
static int
closefrom(int n)
{
int max;
max = sysconf(_SC_OPEN_MAX);
while ((n >= 0) && (n <= max)) {
for (;;) {
if (close(n) == 0) {
break;
}
if (errno == EBADF) {
break;
}
if (errno != EINTR) {
return -1;
}
}
n++;
}
return 0;
}