]> sourceware.org Git - newlib-cygwin.git/commitdiff
* dtable.cc (fhandler_base::dup2): Cleanup. Ensure that lock is turned off in
authorChristopher Faylor <me@cgf.cx>
Mon, 24 Jun 2002 20:05:52 +0000 (20:05 +0000)
committerChristopher Faylor <me@cgf.cx>
Mon, 24 Jun 2002 20:05:52 +0000 (20:05 +0000)
error condition.

winsup/cygwin/ChangeLog
winsup/cygwin/dtable.cc

index 6ff5adfdafe3af0f1b0feefc7f3fd0fb44670324..0be5f97ff8cf3224cf3513afb8395c63b328fa6e 100644 (file)
@@ -1,3 +1,8 @@
+2002-06-24  Christopher Faylor  <cgf@redhat.com>
+
+       * dtable.cc (fhandler_base::dup2): Cleanup.  Ensure that lock is turned
+       off in error condition.
+
 2002-06-24  Corinna Vinschen  <corinna@vinschen.de>
 
        * uinfo.cc (internal_getlogin): Set myself->uid and myself->gid instead
index b94e9cf385b667b25d02001420f8f21c7fec0e6a..95225bb498dd399bd267aaf142632db1ecf1a986 100644 (file)
@@ -433,6 +433,7 @@ dtable::dup2 (int oldfd, int newfd)
 
   MALLOC_CHECK;
   debug_printf ("dup2 (%d, %d)", oldfd, newfd);
+  SetResourceLock (LOCK_FD_LIST, WRITE_LOCK | READ_LOCK, "dup");
 
   if (not_open (oldfd))
     {
@@ -441,6 +442,13 @@ dtable::dup2 (int oldfd, int newfd)
       goto done;
     }
 
+  if (newfd < 0)
+    {
+      syscall_printf ("new fd out of bounds: %d", newfd);
+      set_errno (EBADF);
+      goto done;
+    }
+
   if (newfd == oldfd)
     {
       res = 0;
@@ -453,35 +461,28 @@ dtable::dup2 (int oldfd, int newfd)
       goto done;
     }
 
-  debug_printf ("newfh->io_handle %p, oldfh->io_handle %p", newfh->get_io_handle (), fds[oldfd]->get_io_handle ());
-  SetResourceLock (LOCK_FD_LIST, WRITE_LOCK | READ_LOCK, "dup");
+  debug_printf ("newfh->io_handle %p, oldfh->io_handle %p",
+               newfh->get_io_handle (), fds[oldfd]->get_io_handle ());
 
-  if (newfd < 0)
+  if (!not_open (newfd))
+    _close (newfd);
+  else if ((size_t) newfd < size)
+    /* nothing to do */;
+  else if (find_unused_handle (newfd) < 0)
     {
-      syscall_printf ("new fd out of bounds: %d", newfd);
-      set_errno (EBADF);
+      newfh->close ();
+      res = -1;
       goto done;
     }
 
-  if ((size_t) newfd >= size)
-   {
-     int inc_size = NOFILE_INCR * ((newfd + NOFILE_INCR - 1) / NOFILE_INCR) -
-                   size;
-     extend (inc_size);
-   }
-
-  if (!not_open (newfd))
-    _close (newfd);
   fds[newfd] = newfh;
 
-  ReleaseResourceLock (LOCK_FD_LIST, WRITE_LOCK | READ_LOCK, "dup");
-  MALLOC_CHECK;
-
   if ((res = newfd) <= 2)
     set_std_handle (res);
 
-  MALLOC_CHECK;
 done:
+  MALLOC_CHECK;
+  ReleaseResourceLock (LOCK_FD_LIST, WRITE_LOCK | READ_LOCK, "dup");
   syscall_printf ("%d = dup2 (%d, %d)", res, oldfd, newfd);
 
   return res;
This page took 0.035268 seconds and 5 git commands to generate.