It is possible that we run out of available file descriptors. * However, if we are going to close anyway, we could just try * closing file descriptors until we reach maxfd. */
| 118 | * closing file descriptors until we reach maxfd. |
| 119 | */ |
| 120 | static |
| 121 | DIR *try_opendir(const char *dnam, int *fromfd, int maxfd) |
| 122 | { |
| 123 | DIR *dir; |
| 124 | |
| 125 | do { |
| 126 | dir = opendir(dnam); |
| 127 | if (!dir && (errno == ENFILE || errno == EMFILE)) { |
| 128 | if (*fromfd < maxfd) |
| 129 | close((*fromfd)++); |
| 130 | else |
| 131 | break; |
| 132 | } |
| 133 | } while (!dir && (errno == ENFILE || errno == EMFILE)); |
| 134 | |
| 135 | return dir; |
| 136 | } |
| 137 | |
| 138 | void closefrom(int fromfd) |
| 139 | { |