qingdoa daoo : msvcrt: Don't duplicate handle in _get_osfhandle.

Alexandre Julliard julliard at wine.codeweavers.com
Mon May 8 15:38:09 CDT 2006


Module: wine
Branch: refs/heads/master
Commit: 4f7adfb04aa4df2c52453aa8c043bde57ae7fd44
URL:    http://source.winehq.org/git/?p=wine.git;a=commit;h=4f7adfb04aa4df2c52453aa8c043bde57ae7fd44

Author: qingdoa daoo <qingdao33122 at yahoo.com>
Date:   Tue Apr 25 10:36:02 2006 +0800

msvcrt: Don't duplicate handle in _get_osfhandle.

---

 dlls/msvcrt/file.c       |   17 +----------------
 dlls/msvcrt/tests/file.c |   20 ++++++++++++++++++++
 2 files changed, 21 insertions(+), 16 deletions(-)

diff --git a/dlls/msvcrt/file.c b/dlls/msvcrt/file.c
index 5a02a29..eadde05 100644
--- a/dlls/msvcrt/file.c
+++ b/dlls/msvcrt/file.c
@@ -1206,24 +1206,9 @@ int _futime(int fd, struct MSVCRT__utimb
 long _get_osfhandle(int fd)
 {
   HANDLE hand = msvcrt_fdtoh(fd);
-  HANDLE newhand = hand;
   TRACE(":fd (%d) handle (%p)\n",fd,hand);
 
-  if (hand != INVALID_HANDLE_VALUE)
-  {
-    /* FIXME: I'm not convinced that I should be copying the
-     * handle here - it may be leaked if the app doesn't
-     * close it (and the API docs don't say that it should)
-     * Not duplicating it means that it can't be inherited
-     * and so lcc's wedit doesn't cope when it passes it to
-     * child processes. I've an idea that it should either
-     * be copied by CreateProcess, or marked as inheritable
-     * when initialised, or maybe both? JG 21-9-00.
-     */
-    DuplicateHandle(GetCurrentProcess(),hand,GetCurrentProcess(),
-		    &newhand,0,TRUE,DUPLICATE_SAME_ACCESS);
-  }
-  return (long)newhand;
+  return (long)hand;
 }
 
 /*********************************************************************
diff --git a/dlls/msvcrt/tests/file.c b/dlls/msvcrt/tests/file.c
index 9166ee9..d1a8d7f 100644
--- a/dlls/msvcrt/tests/file.c
+++ b/dlls/msvcrt/tests/file.c
@@ -24,6 +24,7 @@ #include <stdarg.h>
 #include <stdlib.h>
 #include <stdio.h>
 #include <fcntl.h>
+#include <share.h>
 #include <sys/stat.h>
 #include <io.h>
 #include <windef.h>
@@ -464,6 +465,24 @@ static void test_fopen_fclose_fcloseall(
     ok(_unlink(fname3) == 0, "Couldn't unlink file named '%s'\n", fname3);
 }
 
+static void test_get_osfhandle(void)
+{
+    int fd;
+    char fname[] = "t_get_osfhanle";
+    DWORD bytes_written;
+    HANDLE handle;
+
+    fd = _sopen(fname, _O_CREAT|_O_RDWR, _SH_DENYRW, 0);
+    handle = (HANDLE)_get_osfhandle(fd);
+    WriteFile(handle, "bar", 3, &bytes_written, NULL);
+    _close(fd);
+    fd = _open(fname, _O_RDONLY, 0);
+    ok(fd != -1, "Coudn't open '%s' after _get_osfhanle()\n", fname);
+
+    CloseHandle(handle);
+    _unlink(fname);
+}
+
 START_TEST(file)
 {
     int arg_c;
@@ -489,4 +508,5 @@ START_TEST(file)
     test_fgetwc();
     test_file_put_get();
     test_tmpnam();
+    test_get_osfhandle();
 }




More information about the wine-cvs mailing list