Welcome to mirror list, hosted at ThFree Co, Russian Federation.

cygwin.com/git/newlib-cygwin.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChristopher Faylor <me@cgf.cx>2013-12-05 23:43:34 +0400
committerChristopher Faylor <me@cgf.cx>2013-12-05 23:43:34 +0400
commit09244c002e00fe24571c50d249bc649694fb1837 (patch)
treee8d67283584d7ad72fac50e7730eb886726b56ec /winsup/cygwin/dtable.cc
parent2f8a6f194746751fbfe8ba2fef483e8bc371ba29 (diff)
* cygheap.h (cygheap_fdnew): Avoid setting errno directly since it will have
been set by a previous function. * dtable.h (dtable::extend): Accept second size_t argument. * dtable.cc (dtable::extend): Accept second "min" argument which allows checking for OPEN_MAX_MAX boundary conditions. (dtable_init): Accommodate second argument to dtable::extend. (dtable::find_unused_handle): Ditto. * syscalls.cc (setdtablesize): Ditto. (dup): Return any error passed by cygheap_fdnew() directly. (getdtablesize): Just return dtable size directly.
Diffstat (limited to 'winsup/cygwin/dtable.cc')
-rw-r--r--winsup/cygwin/dtable.cc14
1 files changed, 9 insertions, 5 deletions
diff --git a/winsup/cygwin/dtable.cc b/winsup/cygwin/dtable.cc
index 454798427..2e9ee5481 100644
--- a/winsup/cygwin/dtable.cc
+++ b/winsup/cygwin/dtable.cc
@@ -58,7 +58,7 @@ void
dtable_init ()
{
if (!cygheap->fdtab.size)
- cygheap->fdtab.extend (NOFILE_INCR);
+ cygheap->fdtab.extend (NOFILE_INCR, 0);
}
void __stdcall
@@ -72,12 +72,16 @@ set_std_handle (int fd)
}
int
-dtable::extend (size_t howmuch)
+dtable::extend (size_t howmuch, size_t min)
{
size_t new_size = size + howmuch;
fhandler_base **newfds;
- if (new_size > OPEN_MAX_MAX)
+ if (new_size <= OPEN_MAX_MAX)
+ /* ok */;
+ else if (size < OPEN_MAX_MAX && min < OPEN_MAX_MAX)
+ new_size = OPEN_MAX_MAX;
+ else
{
set_errno (EMFILE);
return 0;
@@ -223,7 +227,7 @@ dtable::delete_archetype (fhandler_base *fh)
int
dtable::find_unused_handle (size_t start)
{
- /* When extending, always make sure that there is a NOFILE_INCR chunk
+ /* When extending, try to allocate a NOFILE_INCR chunk
following the empty fd. */
size_t extendby = NOFILE_INCR + ((start >= size) ? 1 + start - size : 0);
@@ -238,7 +242,7 @@ dtable::find_unused_handle (size_t start)
goto out;
}
}
- while (extend (extendby));
+ while (extend (extendby, start));
out:
return res;
}