Alexandre Julliard : kernel32: Move the DOS file handle functions to file16 .c.

Alexandre Julliard julliard at winehq.org
Fri Oct 9 09:24:09 CDT 2009


Module: wine
Branch: master
Commit: e5288bf42f8d8a356996516428b99549297faaaa
URL:    http://source.winehq.org/git/wine.git/?a=commit;h=e5288bf42f8d8a356996516428b99549297faaaa

Author: Alexandre Julliard <julliard at winehq.org>
Date:   Thu Oct  8 19:22:17 2009 +0200

kernel32: Move the DOS file handle functions to file16.c.

---

 dlls/kernel32/file.c           |  104 ----------------------------------------
 dlls/kernel32/file16.c         |  104 +++++++++++++++++++++++++++++++++++++++-
 dlls/kernel32/kernel_private.h |    4 --
 3 files changed, 103 insertions(+), 109 deletions(-)

diff --git a/dlls/kernel32/file.c b/dlls/kernel32/file.c
index d9fbddb..5432c31 100644
--- a/dlls/kernel32/file.c
+++ b/dlls/kernel32/file.c
@@ -49,8 +49,6 @@
 
 WINE_DEFAULT_DEBUG_CHANNEL(file);
 
-HANDLE dos_handles[DOS_TABLE_SIZE];
-
 /* info structure for FindFirstFile handle */
 typedef struct
 {
@@ -316,32 +314,6 @@ BOOL WINAPI AreFileApisANSI(void)
  *                      Operations on file handles                        *
  **************************************************************************/
 
-/***********************************************************************
- *           FILE_InitProcessDosHandles
- *
- * Allocates the default DOS handles for a process. Called either by
- * Win32HandleToDosFileHandle below or by the DOSVM stuff.
- */
-static void FILE_InitProcessDosHandles( void )
-{
-    static BOOL init_done /* = FALSE */;
-    HANDLE cp = GetCurrentProcess();
-
-    if (init_done) return;
-    init_done = TRUE;
-    DuplicateHandle(cp, GetStdHandle(STD_INPUT_HANDLE), cp, &dos_handles[0],
-                    0, TRUE, DUPLICATE_SAME_ACCESS);
-    DuplicateHandle(cp, GetStdHandle(STD_OUTPUT_HANDLE), cp, &dos_handles[1],
-                    0, TRUE, DUPLICATE_SAME_ACCESS);
-    DuplicateHandle(cp, GetStdHandle(STD_ERROR_HANDLE), cp, &dos_handles[2],
-                    0, TRUE, DUPLICATE_SAME_ACCESS);
-    DuplicateHandle(cp, GetStdHandle(STD_ERROR_HANDLE), cp, &dos_handles[3],
-                    0, TRUE, DUPLICATE_SAME_ACCESS);
-    DuplicateHandle(cp, GetStdHandle(STD_ERROR_HANDLE), cp, &dos_handles[4],
-                    0, TRUE, DUPLICATE_SAME_ACCESS);
-}
-
-
 /******************************************************************
  *		FILE_ReadWriteApc (internal)
  */
@@ -1205,59 +1177,6 @@ BOOL WINAPI UnlockFileEx( HANDLE hFile, DWORD reserved, DWORD count_low, DWORD c
 }
 
 
-/***********************************************************************
- *           Win32HandleToDosFileHandle   (KERNEL32.21)
- *
- * Allocate a DOS handle for a Win32 handle. The Win32 handle is no
- * longer valid after this function (even on failure).
- *
- * Note: this is not exactly right, since on Win95 the Win32 handles
- *       are on top of DOS handles and we do it the other way
- *       around. Should be good enough though.
- */
-HFILE WINAPI Win32HandleToDosFileHandle( HANDLE handle )
-{
-    int i;
-
-    if (!handle || (handle == INVALID_HANDLE_VALUE))
-        return HFILE_ERROR;
-
-    FILE_InitProcessDosHandles();
-    for (i = 0; i < DOS_TABLE_SIZE; i++)
-        if (!dos_handles[i])
-        {
-            dos_handles[i] = handle;
-            TRACE("Got %d for h32 %p\n", i, handle );
-            return (HFILE)i;
-        }
-    CloseHandle( handle );
-    SetLastError( ERROR_TOO_MANY_OPEN_FILES );
-    return HFILE_ERROR;
-}
-
-
-/***********************************************************************
- *           DosFileHandleToWin32Handle   (KERNEL32.20)
- *
- * Return the Win32 handle for a DOS handle.
- *
- * Note: this is not exactly right, since on Win95 the Win32 handles
- *       are on top of DOS handles and we do it the other way
- *       around. Should be good enough though.
- */
-HANDLE WINAPI DosFileHandleToWin32Handle( HFILE handle )
-{
-    HFILE16 hfile = (HFILE16)handle;
-    if (hfile < 5) FILE_InitProcessDosHandles();
-    if ((hfile >= DOS_TABLE_SIZE) || !dos_handles[hfile])
-    {
-        SetLastError( ERROR_INVALID_HANDLE );
-        return INVALID_HANDLE_VALUE;
-    }
-    return dos_handles[hfile];
-}
-
-
 /*************************************************************************
  *           SetHandleCount   (KERNEL32.@)
  */
@@ -1267,29 +1186,6 @@ UINT WINAPI SetHandleCount( UINT count )
 }
 
 
-/***********************************************************************
- *           DisposeLZ32Handle   (KERNEL32.22)
- *
- * Note: this is not entirely correct, we should only close the
- *       32-bit handle and not the 16-bit one, but we cannot do
- *       this because of the way our DOS handles are implemented.
- *       It shouldn't break anything though.
- */
-void WINAPI DisposeLZ32Handle( HANDLE handle )
-{
-    int i;
-
-    if (!handle || (handle == INVALID_HANDLE_VALUE)) return;
-
-    for (i = 5; i < DOS_TABLE_SIZE; i++)
-        if (dos_handles[i] == handle)
-        {
-            dos_handles[i] = 0;
-            CloseHandle( handle );
-            break;
-        }
-}
-
 /**************************************************************************
  *                      Operations on file names                          *
  **************************************************************************/
diff --git a/dlls/kernel32/file16.c b/dlls/kernel32/file16.c
index 3ca3039..30c7bdd 100644
--- a/dlls/kernel32/file16.c
+++ b/dlls/kernel32/file16.c
@@ -37,12 +37,114 @@
 #include "winbase.h"
 #include "winternl.h"
 #include "wine/winbase16.h"
-#include "kernel_private.h"
+#include "kernel16_private.h"
 #include "wine/unicode.h"
 #include "wine/debug.h"
 
 WINE_DEFAULT_DEBUG_CHANNEL(file);
 
+#define DOS_TABLE_SIZE 256
+
+static HANDLE dos_handles[DOS_TABLE_SIZE];
+
+/***********************************************************************
+ *           FILE_InitProcessDosHandles
+ *
+ * Allocates the default DOS handles for a process. Called either by
+ * Win32HandleToDosFileHandle below or by the DOSVM stuff.
+ */
+static void FILE_InitProcessDosHandles( void )
+{
+    static BOOL init_done /* = FALSE */;
+    HANDLE cp = GetCurrentProcess();
+
+    if (init_done) return;
+    init_done = TRUE;
+    DuplicateHandle(cp, GetStdHandle(STD_INPUT_HANDLE), cp, &dos_handles[0],
+                    0, TRUE, DUPLICATE_SAME_ACCESS);
+    DuplicateHandle(cp, GetStdHandle(STD_OUTPUT_HANDLE), cp, &dos_handles[1],
+                    0, TRUE, DUPLICATE_SAME_ACCESS);
+    DuplicateHandle(cp, GetStdHandle(STD_ERROR_HANDLE), cp, &dos_handles[2],
+                    0, TRUE, DUPLICATE_SAME_ACCESS);
+    DuplicateHandle(cp, GetStdHandle(STD_ERROR_HANDLE), cp, &dos_handles[3],
+                    0, TRUE, DUPLICATE_SAME_ACCESS);
+    DuplicateHandle(cp, GetStdHandle(STD_ERROR_HANDLE), cp, &dos_handles[4],
+                    0, TRUE, DUPLICATE_SAME_ACCESS);
+}
+
+/***********************************************************************
+ *           DosFileHandleToWin32Handle   (KERNEL32.20)
+ *
+ * Return the Win32 handle for a DOS handle.
+ *
+ * Note: this is not exactly right, since on Win95 the Win32 handles
+ *       are on top of DOS handles and we do it the other way
+ *       around. Should be good enough though.
+ */
+HANDLE WINAPI DosFileHandleToWin32Handle( HFILE handle )
+{
+    HFILE16 hfile = (HFILE16)handle;
+    if (hfile < 5) FILE_InitProcessDosHandles();
+    if ((hfile >= DOS_TABLE_SIZE) || !dos_handles[hfile])
+    {
+        SetLastError( ERROR_INVALID_HANDLE );
+        return INVALID_HANDLE_VALUE;
+    }
+    return dos_handles[hfile];
+}
+
+/***********************************************************************
+ *           Win32HandleToDosFileHandle   (KERNEL32.21)
+ *
+ * Allocate a DOS handle for a Win32 handle. The Win32 handle is no
+ * longer valid after this function (even on failure).
+ *
+ * Note: this is not exactly right, since on Win95 the Win32 handles
+ *       are on top of DOS handles and we do it the other way
+ *       around. Should be good enough though.
+ */
+HFILE WINAPI Win32HandleToDosFileHandle( HANDLE handle )
+{
+    int i;
+
+    if (!handle || (handle == INVALID_HANDLE_VALUE))
+        return HFILE_ERROR;
+
+    FILE_InitProcessDosHandles();
+    for (i = 0; i < DOS_TABLE_SIZE; i++)
+        if (!dos_handles[i])
+        {
+            dos_handles[i] = handle;
+            TRACE("Got %d for h32 %p\n", i, handle );
+            return (HFILE)i;
+        }
+    CloseHandle( handle );
+    SetLastError( ERROR_TOO_MANY_OPEN_FILES );
+    return HFILE_ERROR;
+}
+
+/***********************************************************************
+ *           DisposeLZ32Handle   (KERNEL32.22)
+ *
+ * Note: this is not entirely correct, we should only close the
+ *       32-bit handle and not the 16-bit one, but we cannot do
+ *       this because of the way our DOS handles are implemented.
+ *       It shouldn't break anything though.
+ */
+void WINAPI DisposeLZ32Handle( HANDLE handle )
+{
+    int i;
+
+    if (!handle || (handle == INVALID_HANDLE_VALUE)) return;
+
+    for (i = 5; i < DOS_TABLE_SIZE; i++)
+        if (dos_handles[i] == handle)
+        {
+            dos_handles[i] = 0;
+            CloseHandle( handle );
+            break;
+        }
+}
 
 /***********************************************************************
  *           GetProfileInt   (KERNEL.57)
diff --git a/dlls/kernel32/kernel_private.h b/dlls/kernel32/kernel_private.h
index a65d93f..236f9f8 100644
--- a/dlls/kernel32/kernel_private.h
+++ b/dlls/kernel32/kernel_private.h
@@ -65,10 +65,6 @@ static inline obj_handle_t console_handle_unmap(HANDLE h)
 
 extern HMODULE kernel32_handle;
 
-/* Size of per-process table of DOS handles */
-#define DOS_TABLE_SIZE 256
-extern HANDLE dos_handles[DOS_TABLE_SIZE];
-
 extern const WCHAR *DIR_Windows;
 extern const WCHAR *DIR_System;
 extern const WCHAR *DIR_SysWow64;




More information about the wine-cvs mailing list