mirror of
git://git.code.sf.net/p/zsh/code
synced 2025-10-23 16:40:24 +02:00
16094: zopenmax() need only return the highest-numbered open descriptor
This commit is contained in:
parent
d98a67c569
commit
c43a6be917
1 changed files with 25 additions and 5 deletions
30
Src/compat.c
30
Src/compat.c
|
|
@ -198,12 +198,32 @@ zpathmax(char *dir)
|
||||||
mod_export long
|
mod_export long
|
||||||
zopenmax(void)
|
zopenmax(void)
|
||||||
{
|
{
|
||||||
long openmax = sysconf(_SC_OPEN_MAX);
|
static long openmax = 0;
|
||||||
|
|
||||||
if (openmax < 1)
|
if (openmax < 1) {
|
||||||
return OPEN_MAX;
|
if ((openmax = sysconf(_SC_OPEN_MAX)) < 1) {
|
||||||
else
|
openmax = OPEN_MAX;
|
||||||
return openmax;
|
} else if (openmax > OPEN_MAX) {
|
||||||
|
/* On some systems, "limit descriptors unlimited" or the *
|
||||||
|
* equivalent will set openmax to a huge number. Unless *
|
||||||
|
* there actually is a file descriptor > OPEN_MAX already *
|
||||||
|
* open, nothing in zsh requires the true maximum, and in *
|
||||||
|
* fact it causes inefficiency elsewhere if we report it. *
|
||||||
|
* So, report the maximum of OPEN_MAX or the largest open *
|
||||||
|
* descriptor (is there a better way to find that?). */
|
||||||
|
long i, j = OPEN_MAX;
|
||||||
|
for (i = j; i < openmax; i += (errno != EINTR)) {
|
||||||
|
errno = 0;
|
||||||
|
if (fcntl(i, F_GETFL, 0) < 0 &&
|
||||||
|
(errno == EBADF || errno == EINTR))
|
||||||
|
continue;
|
||||||
|
j = i;
|
||||||
|
}
|
||||||
|
openmax = j;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return (max_zsh_fd > openmax) ? max_zsh_fd : openmax;
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue