Index: trunk/src/kernel32/Fileio.cpp
===================================================================
--- trunk/src/kernel32/Fileio.cpp	(revision 4280)
+++ trunk/src/kernel32/Fileio.cpp	(revision 4285)
@@ -1,3 +1,3 @@
-/* $Id: Fileio.cpp,v 1.40 2000-09-18 19:26:15 sandervl Exp $ */
+/* $Id: Fileio.cpp,v 1.41 2000-09-20 21:32:50 hugh Exp $ */
 
 /*
@@ -91,14 +91,14 @@
   dprintf(("FindFirstFileA %s", lpFileName));
   if(lpFileName == NULL || lpFindFileData == NULL) {
-	SetLastError(ERROR_INVALID_PARAMETER);
-	return -1;
+  SetLastError(ERROR_INVALID_PARAMETER);
+  return -1;
   }
   namelen = strlen(lpFileName);
   if(lpFileName[namelen-1] == '\\') {
-	filename = (char *)alloca(namelen+1);
-	strcpy(filename, lpFileName);
-	filename[namelen-1] = 0;
-  }
-  else	filename = (char *)lpFileName;
+  filename = (char *)alloca(namelen+1);
+  strcpy(filename, lpFileName);
+  filename[namelen-1] = 0;
+  }
+  else  filename = (char *)lpFileName;
 
   return (HANDLE)OSLibDosFindFirst(filename,lpFindFileData);
@@ -244,19 +244,19 @@
 {
    if (lpft1 == NULL || lpft2 == NULL) {
-	SetLastError(ERROR_INVALID_PARAMETER);
-	return -1;
-   }     
+  SetLastError(ERROR_INVALID_PARAMETER);
+  return -1;
+   }
 
    if(lpft1->dwHighDateTime > lpft2->dwHighDateTime)
-	return 1;
+  return 1;
 
    if(lpft1->dwHighDateTime < lpft2->dwHighDateTime)
-	return -1;
+  return -1;
 
    if(lpft1->dwLowDateTime > lpft2->dwLowDateTime)
- 	return 1;
+  return 1;
 
    if(lpft1->dwLowDateTime < lpft2->dwLowDateTime)
-	return -1;
+  return -1;
 
    return 0; //equal
@@ -342,5 +342,5 @@
   if((dwCopyFlags & COPY_FILE_FAIL_IF_EXISTS) != 0)
   {
-    	failIfExists = TRUE;
+      failIfExists = TRUE;
   }
 
@@ -416,9 +416,9 @@
   rc = OSLibDosDelete((LPSTR)lpszFile);
   if(!rc) {
-  	dprintf(("DeleteFileA %s returned FALSE; last error %x", lpszFile, GetLastError()));
-	if(GetLastError() == 20) {
-		return TRUE;
-	}
-  } 
+    dprintf(("DeleteFileA %s returned FALSE; last error %x", lpszFile, GetLastError()));
+  if(GetLastError() == 20) {
+    return TRUE;
+  }
+  }
   else  dprintf(("DeleteFileA %s", lpszFile));
 
@@ -509,5 +509,5 @@
 //******************************************************************************
 //******************************************************************************
-ODINFUNCTION5(BOOL,         ReadFileEx, 
+ODINFUNCTION5(BOOL,         ReadFileEx,
               HANDLE,       hFile,
               LPVOID,       lpBuffer,
@@ -557,5 +557,5 @@
  *****************************************************************************/
 
-ODINFUNCTION5(BOOL,         WriteFileEx, 
+ODINFUNCTION5(BOOL,         WriteFileEx,
               HANDLE,       hFile,
               LPVOID,       lpBuffer,
@@ -599,16 +599,16 @@
     }
     else {
-	rc = O32_GetFileAttributes((LPSTR)lpszFileName);
-	if(rc == -1 && lpszFileName[strlen(lpszFileName)-1] != '\\') {
-		char *filename = (char *)alloca(strlen(lpszFileName)+2); //+2!!!!!!
-		strcpy(filename, lpszFileName);
+  rc = O32_GetFileAttributes((LPSTR)lpszFileName);
+  if(rc == -1 && lpszFileName[strlen(lpszFileName)-1] != '\\') {
+    char *filename = (char *)alloca(strlen(lpszFileName)+2); //+2!!!!!!
+    strcpy(filename, lpszFileName);
                 strcat(filename, "\\");
-		rc = O32_GetFileAttributes((LPSTR)filename);
-	}
+    rc = O32_GetFileAttributes((LPSTR)filename);
+  }
     }
     //SvL: Open32 returns FILE_ATTRIBUTE_DIRECTORY|FILE_ATTRIBUTE_NORMAL for
     //     directories whereas NT 4 (SP6) only returns FILE_ATTRIBUTE_DIRECTORY
     if(rc != -1 && (rc & FILE_ATTRIBUTE_DIRECTORY)) {
-	rc = FILE_ATTRIBUTE_DIRECTORY;
+  rc = FILE_ATTRIBUTE_DIRECTORY;
     }
 
@@ -671,5 +671,6 @@
 {
     char *ptr;
-    dprintf(("KERNEL32:  GetFullPathName %s\n", arg1));
+    DWORD rc;
+    dprintf(("KERNEL32:  GetFullPathName called with %s %d %s \n", arg1, arg2, arg3));
       while((ptr = strchr(arg1, '/')) != NULL)
         *ptr = '\\';
@@ -913,7 +914,7 @@
   length = lstrlenA(lpszLongPath) + 1;
   if(length > cchBuffer) {
-	if(lpszShortPath) {
-        	*lpszShortPath = 0;
-	}
+  if(lpszShortPath) {
+          *lpszShortPath = 0;
+  }
         return(length); //return length required (including 0 terminator)
   }
@@ -938,7 +939,7 @@
   length = lstrlenW(lpszLongPath) + 1;
   if(length > cchBuffer) {
-	if(lpszShortPath) {
-        	*lpszShortPath = 0;
-	}
+  if(lpszShortPath) {
+          *lpszShortPath = 0;
+  }
         return(length); //return length required (including 0 terminator)
   }
@@ -1142,5 +1143,5 @@
 
     lpAsciiPath = UnicodeToAsciiString( (LPWSTR) lpPathName);
-    hChange = FindFirstChangeNotificationA(lpAsciiPath, bWatchSubtree, 
+    hChange = FindFirstChangeNotificationA(lpAsciiPath, bWatchSubtree,
                                            dwNotifyFilter );
     if (lpAsciiPath) FreeAsciiString(lpAsciiPath);
Index: trunk/src/kernel32/HandleManager.cpp
===================================================================
--- trunk/src/kernel32/HandleManager.cpp	(revision 4280)
+++ trunk/src/kernel32/HandleManager.cpp	(revision 4285)
@@ -1,3 +1,3 @@
-/* $Id: HandleManager.cpp,v 1.49 2000-09-13 21:10:56 sandervl Exp $ */
+/* $Id: HandleManager.cpp,v 1.50 2000-09-20 21:32:50 hugh Exp $ */
 
 /*
@@ -12,6 +12,6 @@
  */
 
-#undef DEBUG_LOCAL
-//#define DEBUG_LOCAL
+//#undef DEBUG_LOCAL
+#define DEBUG_LOCAL
 
 
@@ -63,5 +63,5 @@
 #include <vmutex.h>
 
-#define DBG_LOCALLOG	DBG_handlemanager
+#define DBG_LOCALLOG  DBG_handlemanager
 #include "dbglocal.h"
 
@@ -78,4 +78,5 @@
  *****************************************************************************/
 
+typedef struct _HMDEVICE;
 
 typedef struct _HMHANDLE
@@ -92,4 +93,5 @@
   LPSTR           pszDeviceName;       /* name or alias of the pseudo-device */
   HMDeviceHandler *pDeviceHandler;         /* handler for this pseudo-device */
+  VOID            *pDevData;         /* Pointer To Device data */
 } HMDEVICE, *PHMDEVICE;
 
@@ -155,4 +157,6 @@
 static ULONG            _Optlink _HMHandleQuery(HANDLE hHandle);
 
+// Get GlobalDeviceData
+static VOID *_HMDeviceGetData (LPSTR pszDeviceName);
 
 
@@ -199,5 +203,33 @@
   return (HMGlobals.pHMOpen32);    /* haven't found anything, return default */
 }
-
+/*****************************************************************************
+ * Name      : static VOID *_HMDeviceGetData
+ * Purpose   : obtain pointer to device data from the table by searching
+ *             for a device name or alias
+ * Parameters: PSZ pszDeviceName
+ * Variables :
+ * Result    : VOID * - pointer to the handlers device data
+ * Remark    :
+ * Status    :
+ *
+ * Author    : Markus Montkowski
+ *****************************************************************************/
+
+static VOID *_HMDeviceGetData (LPSTR pszDeviceName)
+{
+  PHMDEVICE pHMDevice;                     /* iterator over the device table */
+
+  if (pszDeviceName != NULL)
+    for (pHMDevice = TabWin32Devices;  /* loop over all devices in the table */
+         pHMDevice != NULL;
+         pHMDevice = pHMDevice->pNext)
+    {
+      if (stricmp(pHMDevice->pszDeviceName,       /* case-insensitive search */
+                  pszDeviceName) == 0)
+        return (pHMDevice->pDevData);    /* OK, we've found our device */
+    }
+
+  return (NULL);    /* haven't found anything, return NULL */
+}
 
 /*****************************************************************************
@@ -227,8 +259,9 @@
                                                        /* free handle found ? */
     if (INVALID_HANDLE_VALUE == TabWin32Handles[ulLoop].hmHandleData.hHMHandle) {
-	TabWin32Handles[ulLoop].hmHandleData.dwUserData     = 0;
-	TabWin32Handles[ulLoop].hmHandleData.dwInternalType = HMTYPE_UNKNOWN;
-  	handleMutex.leave();
-      	return (ulLoop);                    /* OK, then return it to the caller */
+  TabWin32Handles[ulLoop].hmHandleData.dwUserData     = 0;
+  TabWin32Handles[ulLoop].hmHandleData.dwInternalType = HMTYPE_UNKNOWN;
+  TabWin32Handles[ulLoop].hmHandleData.lpDeviceData   = NULL;
+      handleMutex.leave();
+        return (ulLoop);                    /* OK, then return it to the caller */
     }
   }
@@ -261,5 +294,4 @@
 }
 
-
 /*****************************************************************************
  * Name      : static int _HMHandleQuery
@@ -301,6 +333,7 @@
  *****************************************************************************/
 
-DWORD   HMDeviceRegister(LPSTR           pszDeviceName,
-                         HMDeviceHandler *pDeviceHandler)
+DWORD   HMDeviceRegisterEx(LPSTR           pszDeviceName,
+                           HMDeviceHandler *pDeviceHandler,
+                           VOID            *pDevData)
 {
   PHMDEVICE pHMDevice;                     /* our new device to be allocated */
@@ -324,4 +357,5 @@
   pHMDevice->pDeviceHandler = pDeviceHandler;     /* store pointer to device */
   pHMDevice->pNext = TabWin32Devices;                   /* establish linkage */
+  pHMDevice->pDevData = pDevData;
 
   TabWin32Devices = pHMDevice;        /* insert new node as root in the list */
@@ -330,4 +364,9 @@
 }
 
+DWORD   HMDeviceRegister(LPSTR           pszDeviceName,
+                         HMDeviceHandler *pDeviceHandler)
+{
+  return HMDeviceRegisterEx(pszDeviceName, pDeviceHandler, NULL);
+}
 
 /*****************************************************************************
@@ -355,5 +394,5 @@
     // fill handle table
     for(ulIndex = 0; ulIndex < MAX_OS2_HMHANDLES; ulIndex++) {
-      	TabWin32Handles[ulIndex].hmHandleData.hHMHandle = INVALID_HANDLE_VALUE;
+        TabWin32Handles[ulIndex].hmHandleData.hHMHandle = INVALID_HANDLE_VALUE;
     }
     handleMutex.leave();
@@ -471,5 +510,5 @@
 
   if(ulHandle == 0) {
-	ulHandle = 1; //SvL: Start searching from index 1
+  ulHandle = 1; //SvL: Start searching from index 1
   }
   do
@@ -478,10 +517,11 @@
     if (TabWin32Handles[ulHandle].hmHandleData.hHMHandle == INVALID_HANDLE_VALUE)
     {
-     	*phHandle16 = ulHandle;
-      	TabWin32Handles[ulHandle].hmHandleData.hHMHandle = hHandleOS2;
-      	HMGlobals.ulHandleLast = ulHandle;          /* to shorten search times */
-
-  	handleMutex.leave();
-      	return (NO_ERROR);                                               /* OK */
+      *phHandle16 = ulHandle;
+        TabWin32Handles[ulHandle].hmHandleData.hHMHandle = hHandleOS2;
+        TabWin32Handles[ulHandle].hmHandleData.lpDeviceData = NULL;
+        HMGlobals.ulHandleLast = ulHandle;          /* to shorten search times */
+
+    handleMutex.leave();
+        return (NO_ERROR);                                               /* OK */
     }
 
@@ -771,17 +811,17 @@
 
   if((fdwOdinOptions & DUPLICATE_ACCESS_READWRITE) == DUPLICATE_ACCESS_READWRITE) {
-	pHMHandleData->dwAccess = GENERIC_READ | GENERIC_WRITE;
-  }
-  else 
+  pHMHandleData->dwAccess = GENERIC_READ | GENERIC_WRITE;
+  }
+  else
   if(fdwOdinOptions & DUPLICATE_ACCESS_READ) {
-	pHMHandleData->dwAccess = GENERIC_READ;
+  pHMHandleData->dwAccess = GENERIC_READ;
   }
 
   if(fdwOdinOptions & DUPLICATE_SHARE_READ) {
-	pHMHandleData->dwShare = FILE_SHARE_READ;
-  } 
+  pHMHandleData->dwShare = FILE_SHARE_READ;
+  }
   else
   if(fdwOdinOptions & DUPLICATE_SHARE_DENYNONE) {
-	pHMHandleData->dwShare = FILE_SHARE_READ | FILE_SHARE_WRITE;
+  pHMHandleData->dwShare = FILE_SHARE_READ | FILE_SHARE_WRITE;
   }
   else  pHMHandleData->dwShare = TabWin32Handles[srchandle].hmHandleData.dwShare;
@@ -798,5 +838,4 @@
   TabWin32Handles[iIndexNew].hmHandleData.hHMHandle = iIndexNew;
   TabWin32Handles[iIndexNew].pDeviceHandler         = pDeviceHandler;
-
                                                   /* call the device handler */
   rc = pDeviceHandler->DuplicateHandle(&TabWin32Handles[iIndexNew].hmHandleData,
@@ -854,4 +893,5 @@
   PHMHANDLEDATA   pHMHandleData;
   HMHANDLEDATA    HMHandleTemp;          /* temporary buffer for handle data */
+  VOID            *pDevData;
 
   /* create new handle by either lpFileName or hTemplateFile */
@@ -874,5 +914,4 @@
   {
     pDeviceHandler = _HMDeviceFind((LPSTR)lpFileName);        /* find device */
-
     if (NULL == pDeviceHandler)                /* this name is unknown to us */
     {
@@ -883,6 +922,8 @@
       pHMHandleData  = NULL;
 
+    pDevData       = _HMDeviceGetData((LPSTR)lpFileName);
+
     if(pDeviceHandler == HMGlobals.pHMOpen32) {
-	pDeviceHandler = HMGlobals.pHMFile;
+  pDeviceHandler = HMGlobals.pHMFile;
     }
   }
@@ -910,4 +951,5 @@
     HMHandleTemp.dwFlags    = dwFlagsAndAttributes;
     HMHandleTemp.lpHandlerData = NULL;
+    HMHandleTemp.lpDeviceData  = pDevData;
   }
 
@@ -918,5 +960,4 @@
   HMHandleTemp.hHMHandle                    = iIndexNew;
   TabWin32Handles[iIndexNew].pDeviceHandler = pDeviceHandler;
-
                                   /* now copy back our temporary handle data */
   memcpy(&TabWin32Handles[iIndexNew].hmHandleData,
@@ -1008,4 +1049,5 @@
   int             iIndexNew;                  /* index into the handle table */
   HMDeviceHandler *pDeviceHandler;         /* device handler for this handle */
+  VOID            *pDevData;
   PHMHANDLEDATA   pHMHandleData;
   DWORD           rc;                                     /* API return code */
@@ -1020,4 +1062,6 @@
   else
     pHMHandleData  = NULL;
+
+  pDevData       = _HMDeviceGetData((LPSTR)lpFileName);
 
   if(pDeviceHandler == HMGlobals.pHMOpen32) {
@@ -1046,5 +1090,5 @@
   pHMHandleData->dwFlags    = 0;
   pHMHandleData->lpHandlerData = NULL;
-
+  pHMHandleData->lpDeviceData  = pDevData;
 
       /* we've got to mark the handle as occupied here, since another device */
@@ -1053,5 +1097,5 @@
           /* write appropriate entry into the handle table if open succeeded */
   TabWin32Handles[iIndexNew].hmHandleData.hHMHandle = iIndexNew;
-  TabWin32Handles[iIndexNew].pDeviceHandler       = pDeviceHandler;
+  TabWin32Handles[iIndexNew].pDeviceHandler         = pDeviceHandler;
 
   rc = pDeviceHandler->OpenFile  (lpFileName,     /* call the device handler */
@@ -1069,22 +1113,22 @@
   if(rc != NO_ERROR)     /* oops, creation failed within the device handler */
   {
-    	TabWin32Handles[iIndexNew].hmHandleData.hHMHandle = INVALID_HANDLE_VALUE;
-    	SetLastError(pOFStruct->nErrCode);
-    	return (INVALID_HANDLE_VALUE);                           /* signal error */
+      TabWin32Handles[iIndexNew].hmHandleData.hHMHandle = INVALID_HANDLE_VALUE;
+      SetLastError(pOFStruct->nErrCode);
+      return (INVALID_HANDLE_VALUE);                           /* signal error */
   }
   else {
-  	if(fuMode & (OF_DELETE|OF_EXIST)) {
-		//file handle already closed
-    		TabWin32Handles[iIndexNew].hmHandleData.hHMHandle = INVALID_HANDLE_VALUE;
-		return TRUE; //TODO: correct?
-	}
-	if(fuMode & OF_PARSE) {
-    		TabWin32Handles[iIndexNew].hmHandleData.hHMHandle = INVALID_HANDLE_VALUE;
-		return 0;
-	}
-	if(fuMode & OF_VERIFY) {
-    		TabWin32Handles[iIndexNew].hmHandleData.hHMHandle = INVALID_HANDLE_VALUE;
-		return 1; //TODO: correct?
-	}
+    if(fuMode & (OF_DELETE|OF_EXIST)) {
+    //file handle already closed
+        TabWin32Handles[iIndexNew].hmHandleData.hHMHandle = INVALID_HANDLE_VALUE;
+    return TRUE; //TODO: correct?
+  }
+  if(fuMode & OF_PARSE) {
+        TabWin32Handles[iIndexNew].hmHandleData.hHMHandle = INVALID_HANDLE_VALUE;
+    return 0;
+  }
+  if(fuMode & OF_VERIFY) {
+        TabWin32Handles[iIndexNew].hmHandleData.hHMHandle = INVALID_HANDLE_VALUE;
+    return 1; //TODO: correct?
+  }
   }
 
@@ -1092,5 +1136,5 @@
   dprintf(("KERNEL32/HandleManager: OpenFile(%s)=%08xh\n",
            lpFileName,
-           hResult));
+           iIndexNew));
 #endif
 
@@ -1804,5 +1848,5 @@
     dprintf(("KERNEL32: HandleManager:HMWaitForSingleObject(%08xh) passed on to Open32.\n",
              hObject));
-    
+
     // maybe handles from CreateProcess() ...
     dwResult = O32_WaitForSingleObject(hObject, dwTimeout);
@@ -2576,10 +2620,10 @@
   if (rc != NO_ERROR)     /* oops, creation failed within the device handler */
   {
-    	TabWin32Handles[iIndexNew].hmHandleData.hHMHandle = INVALID_HANDLE_VALUE;
-    	SetLastError(rc);          /* Hehe, OS/2 and NT are pretty compatible :) */
-  	if(rc == ERROR_ALREADY_EXISTS) {
-		return hOldMemMap; //return handle of existing file mapping
-	}
-	else	return (NULL);                                           /* signal error */
+      TabWin32Handles[iIndexNew].hmHandleData.hHMHandle = INVALID_HANDLE_VALUE;
+      SetLastError(rc);          /* Hehe, OS/2 and NT are pretty compatible :) */
+    if(rc == ERROR_ALREADY_EXISTS) {
+    return hOldMemMap; //return handle of existing file mapping
+  }
+  else  return (NULL);                                           /* signal error */
   }
   else
@@ -2758,5 +2802,5 @@
                *pLoop1));
 
-	  *pLoop2 = *pLoop1;
+    *pLoop2 = *pLoop1;
 ////      O32_SetLastError(ERROR_INVALID_HANDLE);
 ////      return (WAIT_FAILED);
@@ -2813,9 +2857,9 @@
  *****************************************************************************/
 
-DWORD  HMMsgWaitForMultipleObjects  (DWORD 			nCount, 
-                                     LPHANDLE 			pHandles, 
-                                     BOOL 			fWaitAll,
-                                     DWORD 			dwMilliseconds, 
-                                     DWORD 			dwWakeMask)
+DWORD  HMMsgWaitForMultipleObjects  (DWORD      nCount,
+                                     LPHANDLE       pHandles,
+                                     BOOL       fWaitAll,
+                                     DWORD      dwMilliseconds,
+                                     DWORD      dwWakeMask)
 {
   ULONG   ulIndex;
@@ -2829,7 +2873,7 @@
   if (pArrayOfHandles == NULL)
   {
-	dprintf(("ERROR: HMMsgWaitForMultipleObjects: alloca failed to allocate %d handles", nCount));
-    	O32_SetLastError(ERROR_NOT_ENOUGH_MEMORY);
-    	return WAIT_FAILED;
+  dprintf(("ERROR: HMMsgWaitForMultipleObjects: alloca failed to allocate %d handles", nCount));
+      O32_SetLastError(ERROR_NOT_ENOUGH_MEMORY);
+      return WAIT_FAILED;
   }
   else
@@ -2854,5 +2898,5 @@
                *pLoop1));
 
-	  *pLoop2 = *pLoop1;
+    *pLoop2 = *pLoop1;
 ////      O32_SetLastError(ERROR_INVALID_HANDLE);
 ////      return (WAIT_FAILED);
@@ -2910,17 +2954,18 @@
 
 
-/*****************************************************************************
- * Name      : HMSetupComm
- * Purpose   : router function for SetupComm
- * Parameters:
- * Variables :
- * Result    :
- * Remark    :
- * Status    :
- *
- * Author    : Achim Hasenmueller [Sat, 1999/11/27 13:13]
- *****************************************************************************/
-
-BOOL HMSetupComm(HANDLE hFile, DWORD dwInQueue, DWORD dwOutQueue)
+
+/*****************************************************************************
+ * Name      : HMCOMGetCommState
+ * Purpose   : router function for GetCommState
+ * Parameters:
+ * Variables :
+ * Result    :
+ * Remark    :
+ * Status    :
+ *
+ * Author    : Achim Hasenmueller [Sat, 1999/11/27 13:40]
+ *****************************************************************************/
+
+BOOL HMCommGetCommState(HANDLE hCommDev, LPDCB lpdcb)
 {
   int       iIndex;                           /* index into the handle table */
@@ -2929,5 +2974,5 @@
 
                                                           /* validate handle */
-  iIndex = _HMHandleQuery(hFile);              /* get the index */
+  iIndex = _HMHandleQuery(hCommDev);              /* get the index */
   if (-1 == iIndex)                                               /* error ? */
   {
@@ -2936,36 +2981,8 @@
   }
 
-  pHMHandle = &TabWin32Handles[iIndex];               /* call device handler */
-  bResult = pHMHandle->pDeviceHandler->SetupComm(&pHMHandle->hmHandleData,
-                                                 dwInQueue, dwOutQueue);
-
-  return (bResult);                                  /* deliver return code */
-}
-
-
-/*****************************************************************************
- * Name      : HMGetCommState
- * Purpose   : router function for GetCommState
- * Parameters:
- * Variables :
- * Result    :
- * Remark    :
- * Status    :
- *
- * Author    : Achim Hasenmueller [Sat, 1999/11/27 13:40]
- *****************************************************************************/
-
-BOOL HMGetCommState(INT hCommDev, LPDCB lpdcb)
-{
-  int       iIndex;                           /* index into the handle table */
-  BOOL      bResult;                /* result from the device handler's API */
-  PHMHANDLE pHMHandle;       /* pointer to the handle structure in the table */
-
-                                                          /* validate handle */
-  iIndex = _HMHandleQuery(hCommDev);              /* get the index */
-  if (-1 == iIndex)                                               /* error ? */
-  {
-    SetLastError(ERROR_INVALID_HANDLE);       /* set win32 error information */
-    return (NULL);                                         /* signal failure */
+  if(IsBadWritePtr(lpdcb,sizeof(DCB)))
+  {
+    SetLastError(ERROR_INVALID_PARAMETER);
+    return FALSE;
   }
 
@@ -2973,4 +2990,539 @@
   bResult = pHMHandle->pDeviceHandler->GetCommState(&pHMHandle->hmHandleData,
                                                     lpdcb);
+
+  return (bResult);                                  /* deliver return code */
+}
+
+BOOL HMCommWaitCommEvent( HANDLE hCommDev,
+                          LPDWORD lpfdwEvtMask,
+                          LPOVERLAPPED lpo)
+{
+  int       iIndex;                           /* index into the handle table */
+  BOOL      bResult;                /* result from the device handler's API */
+  PHMHANDLE pHMHandle;       /* pointer to the handle structure in the table */
+
+                                                          /* validate handle */
+  iIndex = _HMHandleQuery(hCommDev);              /* get the index */
+  if (-1 == iIndex)                                               /* error ? */
+  {
+    SetLastError(ERROR_INVALID_HANDLE);       /* set win32 error information */
+    return FALSE;                                         /* signal failure */
+  }
+
+  if(NULL!=lpo && IsBadReadPtr(lpo,sizeof(OVERLAPPED)) )
+  {
+    SetLastError(ERROR_INVALID_PARAMETER);
+    return FALSE;
+  }
+
+  pHMHandle = &TabWin32Handles[iIndex];               /* call device handler */
+  bResult = pHMHandle->pDeviceHandler->WaitCommEvent( &pHMHandle->hmHandleData,
+                                                      lpfdwEvtMask,
+                                                      lpo);
+
+  return (bResult);                                  /* deliver return code */
+}
+
+BOOL HMCommGetCommProperties( HANDLE hCommDev,
+                              LPCOMMPROP lpcmmp)
+{
+  int       iIndex;                           /* index into the handle table */
+  BOOL      bResult;                /* result from the device handler's API */
+  PHMHANDLE pHMHandle;       /* pointer to the handle structure in the table */
+
+                                                          /* validate handle */
+  iIndex = _HMHandleQuery(hCommDev);              /* get the index */
+  if (-1 == iIndex)                                               /* error ? */
+  {
+    SetLastError(ERROR_INVALID_HANDLE);       /* set win32 error information */
+    return (NULL);                                         /* signal failure */
+  }
+
+  if(IsBadWritePtr(lpcmmp,sizeof(COMMPROP)) )
+  {
+    SetLastError(ERROR_INVALID_PARAMETER);
+    return FALSE;
+  }
+
+  pHMHandle = &TabWin32Handles[iIndex];               /* call device handler */
+  bResult = pHMHandle->pDeviceHandler->GetCommProperties( &pHMHandle->hmHandleData,
+                                                          lpcmmp);
+
+  return (bResult);                                  /* deliver return code */
+}
+
+BOOL HMCommGetCommMask( HANDLE hCommDev,
+                        LPDWORD lpfdwEvtMask)
+{
+  int       iIndex;                           /* index into the handle table */
+  BOOL      bResult;                /* result from the device handler's API */
+  PHMHANDLE pHMHandle;       /* pointer to the handle structure in the table */
+
+                                                          /* validate handle */
+  iIndex = _HMHandleQuery(hCommDev);              /* get the index */
+  if (-1 == iIndex)                                               /* error ? */
+  {
+    SetLastError(ERROR_INVALID_HANDLE);       /* set win32 error information */
+    return (NULL);                                         /* signal failure */
+  }
+
+  if(IsBadWritePtr(lpfdwEvtMask,sizeof(DWORD)) )
+  {
+    SetLastError(ERROR_INVALID_PARAMETER);
+    return FALSE;
+  }
+
+  pHMHandle = &TabWin32Handles[iIndex];               /* call device handler */
+  bResult = pHMHandle->pDeviceHandler->GetCommMask( &pHMHandle->hmHandleData,
+                                                    lpfdwEvtMask);
+
+  return (bResult);                                  /* deliver return code */
+}
+
+BOOL HMCommSetCommMask( HANDLE hCommDev,
+                        DWORD fdwEvtMask)
+{
+  int       iIndex;                           /* index into the handle table */
+  BOOL      bResult;                /* result from the device handler's API */
+  PHMHANDLE pHMHandle;       /* pointer to the handle structure in the table */
+
+                                                          /* validate handle */
+  iIndex = _HMHandleQuery(hCommDev);              /* get the index */
+  if (-1 == iIndex)                                               /* error ? */
+  {
+    SetLastError(ERROR_INVALID_HANDLE);       /* set win32 error information */
+    return (NULL);                                         /* signal failure */
+  }
+
+  pHMHandle = &TabWin32Handles[iIndex];               /* call device handler */
+  bResult = pHMHandle->pDeviceHandler->SetCommMask( &pHMHandle->hmHandleData,
+                                                    fdwEvtMask);
+
+  return (bResult);                                  /* deliver return code */
+}
+
+BOOL HMCommPurgeComm( HANDLE hCommDev,
+                      DWORD fdwAction)
+{
+  int       iIndex;                           /* index into the handle table */
+  BOOL      bResult;                /* result from the device handler's API */
+  PHMHANDLE pHMHandle;       /* pointer to the handle structure in the table */
+
+                                                          /* validate handle */
+  iIndex = _HMHandleQuery(hCommDev);              /* get the index */
+  if (-1 == iIndex)                                               /* error ? */
+  {
+    SetLastError(ERROR_INVALID_HANDLE);       /* set win32 error information */
+    return (NULL);                                         /* signal failure */
+  }
+
+
+  pHMHandle = &TabWin32Handles[iIndex];               /* call device handler */
+  bResult = pHMHandle->pDeviceHandler->PurgeComm( &pHMHandle->hmHandleData,
+                                                  fdwAction);
+
+  return (bResult);                                  /* deliver return code */
+}
+
+BOOL HMCommClearCommError( HANDLE hCommDev,
+                           LPDWORD lpdwErrors,
+                           LPCOMSTAT lpcst)
+{
+  int       iIndex;                           /* index into the handle table */
+  BOOL      bResult;                /* result from the device handler's API */
+  PHMHANDLE pHMHandle;       /* pointer to the handle structure in the table */
+
+                                                          /* validate handle */
+  iIndex = _HMHandleQuery(hCommDev);              /* get the index */
+  if (-1 == iIndex)                                               /* error ? */
+  {
+    SetLastError(ERROR_INVALID_HANDLE);       /* set win32 error information */
+    return (NULL);                                         /* signal failure */
+  }
+
+  if(IsBadWritePtr(lpdwErrors,sizeof(DWORD)) ||
+     (NULL!=lpcst && IsBadWritePtr(lpcst,sizeof(COMSTAT)) ) )
+  {
+    SetLastError(ERROR_INVALID_PARAMETER);
+    return FALSE;
+  }
+
+  pHMHandle = &TabWin32Handles[iIndex];               /* call device handler */
+  bResult = pHMHandle->pDeviceHandler->ClearCommError(&pHMHandle->hmHandleData,
+                                                      lpdwErrors,
+                                                      lpcst);
+
+  return (bResult);                                  /* deliver return code */
+}
+
+BOOL HMCommSetCommState( HANDLE hCommDev,
+                         LPDCB lpdcb)
+{
+  int       iIndex;                           /* index into the handle table */
+  BOOL      bResult;                /* result from the device handler's API */
+  PHMHANDLE pHMHandle;       /* pointer to the handle structure in the table */
+
+                                                          /* validate handle */
+  iIndex = _HMHandleQuery(hCommDev);              /* get the index */
+  if (-1 == iIndex)                                               /* error ? */
+  {
+    SetLastError(ERROR_INVALID_HANDLE);       /* set win32 error information */
+    return (NULL);                                         /* signal failure */
+  }
+
+  if(IsBadReadPtr(lpdcb,sizeof(DCB)) )
+  {
+    SetLastError(ERROR_INVALID_PARAMETER);
+    return FALSE;
+  }
+
+
+  pHMHandle = &TabWin32Handles[iIndex];               /* call device handler */
+  bResult = pHMHandle->pDeviceHandler->SetCommState(&pHMHandle->hmHandleData,
+                                                    lpdcb);
+
+  return (bResult);                                  /* deliver return code */
+}
+
+
+BOOL HMCommGetCommTimeouts( HANDLE hCommDev,
+                            LPCOMMTIMEOUTS lpctmo)
+{
+  int       iIndex;                           /* index into the handle table */
+  BOOL      bResult;                /* result from the device handler's API */
+  PHMHANDLE pHMHandle;       /* pointer to the handle structure in the table */
+
+                                                          /* validate handle */
+  iIndex = _HMHandleQuery(hCommDev);              /* get the index */
+  if (-1 == iIndex)                                               /* error ? */
+  {
+    SetLastError(ERROR_INVALID_HANDLE);       /* set win32 error information */
+    return (NULL);                                         /* signal failure */
+  }
+
+  if(IsBadWritePtr(lpctmo,sizeof(COMMTIMEOUTS)) )
+  {
+    SetLastError(ERROR_INVALID_PARAMETER);
+    return FALSE;
+  }
+
+  pHMHandle = &TabWin32Handles[iIndex];               /* call device handler */
+  bResult = pHMHandle->pDeviceHandler->GetCommTimeouts( &pHMHandle->hmHandleData,
+                                                        lpctmo);
+
+  return (bResult);                                  /* deliver return code */
+}
+BOOL HMCommGetCommModemStatus( HANDLE hCommDev,
+                               LPDWORD lpModemStat )
+{
+  int       iIndex;                           /* index into the handle table */
+  BOOL      bResult;                /* result from the device handler's API */
+  PHMHANDLE pHMHandle;       /* pointer to the handle structure in the table */
+
+                                                          /* validate handle */
+  iIndex = _HMHandleQuery(hCommDev);              /* get the index */
+  if (-1 == iIndex)                                               /* error ? */
+  {
+    SetLastError(ERROR_INVALID_HANDLE);       /* set win32 error information */
+    return (NULL);                                         /* signal failure */
+  }
+
+  if(IsBadWritePtr(lpModemStat,sizeof(DWORD)) )
+  {
+    SetLastError(ERROR_INVALID_PARAMETER);
+    return FALSE;
+  }
+
+  pHMHandle = &TabWin32Handles[iIndex];               /* call device handler */
+  bResult = pHMHandle->pDeviceHandler->GetCommModemStatus( &pHMHandle->hmHandleData,
+                                                           lpModemStat);
+
+  return (bResult);                                  /* deliver return code */
+}
+
+BOOL HMCommSetCommTimeouts( HANDLE hCommDev,
+                            LPCOMMTIMEOUTS lpctmo)
+{
+  int       iIndex;                           /* index into the handle table */
+  BOOL      bResult;                /* result from the device handler's API */
+  PHMHANDLE pHMHandle;       /* pointer to the handle structure in the table */
+
+                                                          /* validate handle */
+  iIndex = _HMHandleQuery(hCommDev);              /* get the index */
+  if (-1 == iIndex)                                               /* error ? */
+  {
+    SetLastError(ERROR_INVALID_HANDLE);       /* set win32 error information */
+    return (NULL);                                         /* signal failure */
+  }
+
+  if(IsBadReadPtr(lpctmo,sizeof(COMMTIMEOUTS)) )
+  {
+    SetLastError(ERROR_INVALID_PARAMETER);
+    return FALSE;
+  }
+
+  pHMHandle = &TabWin32Handles[iIndex];               /* call device handler */
+  bResult = pHMHandle->pDeviceHandler->SetCommTimeouts( &pHMHandle->hmHandleData,
+                                                        lpctmo);
+
+  return (bResult);                                  /* deliver return code */
+}
+
+BOOL HMCommTransmitCommChar( HANDLE hCommDev,
+                             CHAR cChar )
+{
+  int       iIndex;                           /* index into the handle table */
+  BOOL      bResult;                /* result from the device handler's API */
+  PHMHANDLE pHMHandle;       /* pointer to the handle structure in the table */
+
+                                                          /* validate handle */
+  iIndex = _HMHandleQuery(hCommDev);              /* get the index */
+  if (-1 == iIndex)                                               /* error ? */
+  {
+    SetLastError(ERROR_INVALID_HANDLE);       /* set win32 error information */
+    return (NULL);                                         /* signal failure */
+  }
+
+  pHMHandle = &TabWin32Handles[iIndex];               /* call device handler */
+  bResult = pHMHandle->pDeviceHandler->TransmitCommChar( &pHMHandle->hmHandleData,
+                                                         cChar);
+
+  return (bResult);                                  /* deliver return code */
+}
+
+BOOL HMCommSetCommConfig( HANDLE hCommDev,
+                          LPCOMMCONFIG lpCC,
+                          DWORD dwSize )
+{
+  int       iIndex;                           /* index into the handle table */
+  BOOL      bResult;                /* result from the device handler's API */
+  PHMHANDLE pHMHandle;       /* pointer to the handle structure in the table */
+
+                                                          /* validate handle */
+  iIndex = _HMHandleQuery(hCommDev);              /* get the index */
+  if (-1 == iIndex)                                               /* error ? */
+  {
+    SetLastError(ERROR_INVALID_HANDLE);       /* set win32 error information */
+    return (NULL);                                         /* signal failure */
+  }
+
+  if( IsBadReadPtr(lpCC,sizeof(COMMCONFIG)) ||
+      dwSize < sizeof(COMMCONFIG) )
+  {
+    SetLastError(ERROR_INVALID_PARAMETER);
+    return FALSE;
+  }
+
+  pHMHandle = &TabWin32Handles[iIndex];               /* call device handler */
+  bResult = pHMHandle->pDeviceHandler->SetCommConfig( &pHMHandle->hmHandleData,
+                                                      lpCC,
+                                                      dwSize);
+
+  return (bResult);                                  /* deliver return code */
+}
+
+BOOL HMCommSetCommBreak( HANDLE hCommDev )
+{
+  int       iIndex;                           /* index into the handle table */
+  BOOL      bResult;                /* result from the device handler's API */
+  PHMHANDLE pHMHandle;       /* pointer to the handle structure in the table */
+
+                                                          /* validate handle */
+  iIndex = _HMHandleQuery(hCommDev);              /* get the index */
+  if (-1 == iIndex)                                               /* error ? */
+  {
+    SetLastError(ERROR_INVALID_HANDLE);       /* set win32 error information */
+    return (NULL);                                         /* signal failure */
+  }
+
+  pHMHandle = &TabWin32Handles[iIndex];               /* call device handler */
+  bResult = pHMHandle->pDeviceHandler->SetCommBreak( &pHMHandle->hmHandleData);
+
+  return (bResult);                                  /* deliver return code */
+}
+
+BOOL HMCommGetCommConfig( HANDLE hCommDev,
+                          LPCOMMCONFIG lpCC,
+                          LPDWORD lpdwSize )
+{
+  int       iIndex;                           /* index into the handle table */
+  BOOL      bResult;                /* result from the device handler's API */
+  PHMHANDLE pHMHandle;       /* pointer to the handle structure in the table */
+
+                                                          /* validate handle */
+  iIndex = _HMHandleQuery(hCommDev);              /* get the index */
+  if (-1 == iIndex)                                               /* error ? */
+  {
+    SetLastError(ERROR_INVALID_HANDLE);       /* set win32 error information */
+    return (NULL);                                         /* signal failure */
+  }
+
+  if(IsBadWritePtr(lpdwSize,sizeof(DWORD)) )
+  {
+    SetLastError(ERROR_INVALID_PARAMETER);
+    return FALSE;
+  }
+
+  if( IsBadWritePtr(lpCC,sizeof(COMMCONFIG)) ||
+      *lpdwSize< sizeof(COMMCONFIG) )
+  {
+    SetLastError(ERROR_INSUFFICIENT_BUFFER);
+    *lpdwSize= sizeof(COMMCONFIG);
+    return FALSE;
+  }
+
+  pHMHandle = &TabWin32Handles[iIndex];               /* call device handler */
+  bResult = pHMHandle->pDeviceHandler->GetCommConfig( &pHMHandle->hmHandleData,
+                                                      lpCC,
+                                                      lpdwSize);
+
+  return (bResult);                                  /* deliver return code */
+}
+
+BOOL HMCommEscapeCommFunction( HANDLE hCommDev,
+                               UINT dwFunc )
+{
+  int       iIndex;                           /* index into the handle table */
+  BOOL      bResult;                /* result from the device handler's API */
+  PHMHANDLE pHMHandle;       /* pointer to the handle structure in the table */
+
+                                                          /* validate handle */
+  iIndex = _HMHandleQuery(hCommDev);              /* get the index */
+  if (-1 == iIndex)                                               /* error ? */
+  {
+    SetLastError(ERROR_INVALID_HANDLE);       /* set win32 error information */
+    return (NULL);                                         /* signal failure */
+  }
+
+  pHMHandle = &TabWin32Handles[iIndex];               /* call device handler */
+
+  switch(dwFunc)
+  {
+    case CLRDTR:
+    case CLRRTS:
+    case SETDTR:
+    case SETRTS:
+    case SETXOFF:
+    case SETXON:
+      bResult = pHMHandle->pDeviceHandler->EscapeCommFunction( &pHMHandle->hmHandleData,
+                                                               dwFunc);
+      break;
+    case SETBREAK:
+      bResult = pHMHandle->pDeviceHandler->SetCommBreak(&pHMHandle->hmHandleData);
+      break;
+    case CLRBREAK:
+      bResult = pHMHandle->pDeviceHandler->ClearCommBreak(&pHMHandle->hmHandleData);
+      break;
+    default:
+      SetLastError(ERROR_INVALID_PARAMETER);
+      bResult = FALSE;
+  }
+
+
+  return (bResult);                                  /* deliver return code */
+}
+
+BOOL HMCommSetupComm( HANDLE hCommDev,
+                      DWORD dwInQueue,
+                      DWORD dwOutQueue)
+{
+  int       iIndex;                           /* index into the handle table */
+  BOOL      bResult;                /* result from the device handler's API */
+  PHMHANDLE pHMHandle;       /* pointer to the handle structure in the table */
+
+                                                          /* validate handle */
+  iIndex = _HMHandleQuery(hCommDev);              /* get the index */
+  if (-1 == iIndex)                                               /* error ? */
+  {
+    SetLastError(ERROR_INVALID_HANDLE);       /* set win32 error information */
+    return (NULL);                                         /* signal failure */
+  }
+
+  pHMHandle = &TabWin32Handles[iIndex];               /* call device handler */
+  bResult = pHMHandle->pDeviceHandler->SetupComm(&pHMHandle->hmHandleData,
+                                                 dwInQueue,
+                                                 dwOutQueue);
+
+  return (bResult);                                  /* deliver return code */
+}
+
+BOOL HMCommClearCommBreak(HANDLE hCommDev)
+{
+  int       iIndex;                           /* index into the handle table */
+  BOOL      bResult;                /* result from the device handler's API */
+  PHMHANDLE pHMHandle;       /* pointer to the handle structure in the table */
+
+                                                          /* validate handle */
+  iIndex = _HMHandleQuery(hCommDev);              /* get the index */
+  if (-1 == iIndex)                                               /* error ? */
+  {
+    SetLastError(ERROR_INVALID_HANDLE);       /* set win32 error information */
+    return (NULL);                                         /* signal failure */
+  }
+
+  pHMHandle = &TabWin32Handles[iIndex];               /* call device handler */
+  bResult = pHMHandle->pDeviceHandler->ClearCommBreak(&pHMHandle->hmHandleData);
+
+  return (bResult);                                  /* deliver return code */
+}
+
+BOOL HMCommSetDefaultCommConfig( HANDLE hCommDev,
+                                 LPCOMMCONFIG lpCC,
+                                 DWORD dwSize)
+{
+  int       iIndex;                           /* index into the handle table */
+  BOOL      bResult;                /* result from the device handler's API */
+  PHMHANDLE pHMHandle;       /* pointer to the handle structure in the table */
+
+                                                          /* validate handle */
+  iIndex = _HMHandleQuery(hCommDev);              /* get the index */
+  if (-1 == iIndex)                                               /* error ? */
+  {
+    SetLastError(ERROR_INVALID_HANDLE);       /* set win32 error information */
+    return (NULL);                                         /* signal failure */
+  }
+
+  if( (lpCC!=NULL) &&
+      ( IsBadReadPtr(lpCC,sizeof(COMMCONFIG)) ||
+        dwSize != sizeof(COMMCONFIG) ) )
+  {
+    SetLastError(ERROR_INVALID_PARAMETER);
+    return FALSE;
+  }
+
+  pHMHandle = &TabWin32Handles[iIndex];               /* call device handler */
+  bResult = pHMHandle->pDeviceHandler->SetDefaultCommConfig(&pHMHandle->hmHandleData,
+                                                            lpCC,
+                                                            dwSize);
+
+  return (bResult);                                  /* deliver return code */
+}
+
+BOOL HMCommGetDefaultCommConfig( HANDLE hCommDev,
+                                 LPCOMMCONFIG lpCC,
+                                 LPDWORD lpdwSize)
+{
+  int       iIndex;                           /* index into the handle table */
+  BOOL      bResult;                /* result from the device handler's API */
+  PHMHANDLE pHMHandle;       /* pointer to the handle structure in the table */
+
+                                                          /* validate handle */
+  iIndex = _HMHandleQuery(hCommDev);              /* get the index */
+  if (-1 == iIndex)                                               /* error ? */
+  {
+    SetLastError(ERROR_INVALID_HANDLE);       /* set win32 error information */
+    return (NULL);                                         /* signal failure */
+  }
+
+  if(IsBadWritePtr(lpdwSize,sizeof(DWORD)))
+  {
+    SetLastError(ERROR_INVALID_PARAMETER);
+    return FALSE;
+  }
+
+  pHMHandle = &TabWin32Handles[iIndex];               /* call device handler */
+  bResult = pHMHandle->pDeviceHandler->GetDefaultCommConfig( &pHMHandle->hmHandleData,
+                                                             lpCC,
+                                                             lpdwSize);
 
   return (bResult);                                  /* deliver return code */
@@ -3006,5 +3558,5 @@
   {
     SetLastError(ERROR_NOT_ENOUGH_MEMORY);      /* use this as error message */
-    return ERROR_NOT_ENOUGH_MEMORY; 
+    return ERROR_NOT_ENOUGH_MEMORY;
   }
 
@@ -3036,6 +3588,6 @@
   if (rc != NO_ERROR)     /* oops, creation failed within the device handler */
   {
-    	TabWin32Handles[iIndexNew].hmHandleData.hHMHandle = INVALID_HANDLE_VALUE;
-	return (rc);                                           /* signal error */
+      TabWin32Handles[iIndexNew].hmHandleData.hHMHandle = INVALID_HANDLE_VALUE;
+  return (rc);                                           /* signal error */
   }
   else
@@ -3074,5 +3626,5 @@
   {
     SetLastError(ERROR_NOT_ENOUGH_MEMORY);      /* use this as error message */
-    return ERROR_NOT_ENOUGH_MEMORY; 
+    return ERROR_NOT_ENOUGH_MEMORY;
   }
 
@@ -3104,6 +3656,6 @@
   if (rc != NO_ERROR)     /* oops, creation failed within the device handler */
   {
-    	TabWin32Handles[iIndexNew].hmHandleData.hHMHandle = INVALID_HANDLE_VALUE;
-	return (rc);                                           /* signal error */
+      TabWin32Handles[iIndexNew].hmHandleData.hHMHandle = INVALID_HANDLE_VALUE;
+  return (rc);                                           /* signal error */
   }
   else
@@ -3146,5 +3698,5 @@
   {
     SetLastError(ERROR_NOT_ENOUGH_MEMORY);      /* use this as error message */
-    return 0; 
+    return 0;
   }
 
@@ -3176,6 +3728,6 @@
   if (rc == 0)     /* oops, creation failed within the device handler */
   {
-    	TabWin32Handles[iIndexNew].hmHandleData.hHMHandle = INVALID_HANDLE_VALUE;
-	return 0;                                           /* signal error */
+      TabWin32Handles[iIndexNew].hmHandleData.hHMHandle = INVALID_HANDLE_VALUE;
+  return 0;                                           /* signal error */
   }
 
@@ -3433,5 +3985,5 @@
 /*****************************************************************************
  * Name      : HMSetThreadTerminated
- * Purpose   : 
+ * Purpose   :
  * Parameters:
  * Variables :
@@ -3465,5 +4017,5 @@
 /*****************************************************************************
  * Name      : HMPeekNamedPipe
- * Purpose   : 
+ * Purpose   :
  * Parameters:
  * Variables :
@@ -3495,5 +4047,5 @@
 
   pHMHandle = &TabWin32Handles[iIndex];               /* call device handler */
-  lpResult = pHMHandle->pDeviceHandler->PeekNamedPipe(&TabWin32Handles[iIndex].hmHandleData, 
+  lpResult = pHMHandle->pDeviceHandler->PeekNamedPipe(&TabWin32Handles[iIndex].hmHandleData,
                                                       lpvBuffer,
                                                       cbBuffer,
@@ -3507,5 +4059,5 @@
 /*****************************************************************************
  * Name      : HMCreateNamedPipe
- * Purpose   : 
+ * Purpose   :
  * Parameters:
  * Variables :
@@ -3516,10 +4068,10 @@
  * Author    : Przemyslaw Dobrowolski
  *****************************************************************************/
-DWORD HMCreateNamedPipe(LPCTSTR lpName, 
-                      DWORD   dwOpenMode, 
+DWORD HMCreateNamedPipe(LPCTSTR lpName,
+                      DWORD   dwOpenMode,
                       DWORD   dwPipeMode,
-                      DWORD   nMaxInstances, 
+                      DWORD   nMaxInstances,
                       DWORD   nOutBufferSize,
-                      DWORD   nInBufferSize, 
+                      DWORD   nInBufferSize,
                       DWORD   nDefaultTimeOut,
                       LPSECURITY_ATTRIBUTES lpSecurityAttributes)
@@ -3539,5 +4091,5 @@
   {
     SetLastError(ERROR_NOT_ENOUGH_MEMORY);      /* use this as error message */
-    return 0; 
+    return 0;
   }
 
@@ -3568,6 +4120,6 @@
   if (rc == 0)     /* oops, creation failed within the device handler */
   {
-    	TabWin32Handles[iIndexNew].hmHandleData.hHMHandle = INVALID_HANDLE_VALUE;
-	return 0;                                           /* signal error */
+      TabWin32Handles[iIndexNew].hmHandleData.hHMHandle = INVALID_HANDLE_VALUE;
+  return 0;                                           /* signal error */
   }
 
@@ -3579,5 +4131,5 @@
 /*****************************************************************************
  * Name      : HMConnectNamedPipe
- * Purpose   : 
+ * Purpose   :
  * Parameters:
  * Variables :
@@ -3604,5 +4156,5 @@
 
   pHMHandle = &TabWin32Handles[iIndex];               /* call device handler */
-  lpResult = pHMHandle->pDeviceHandler->ConnectNamedPipe(&TabWin32Handles[iIndex].hmHandleData, 
+  lpResult = pHMHandle->pDeviceHandler->ConnectNamedPipe(&TabWin32Handles[iIndex].hmHandleData,
                                                          lpOverlapped);
 
@@ -3612,5 +4164,5 @@
 /*****************************************************************************
  * Name      : HMDisconnectNamedPipe
- * Purpose   : 
+ * Purpose   :
  * Parameters:
  * Variables :
@@ -3644,5 +4196,5 @@
 /*****************************************************************************
  * Name      : HMGetNamedPipeHandleState
- * Purpose   : 
+ * Purpose   :
  * Parameters:
  * Variables :
@@ -3689,5 +4241,5 @@
 /*****************************************************************************
  * Name      : HMGetNamedPipeInfo
- * Purpose   : 
+ * Purpose   :
  * Parameters:
  * Variables :
@@ -3729,5 +4281,5 @@
 /*****************************************************************************
  * Name      : HMTransactNamedPipe
- * Purpose   : 
+ * Purpose   :
  * Parameters:
  * Variables :
@@ -3773,5 +4325,5 @@
 /*****************************************************************************
  * Name      : HMSetNamedPipeHandleState
- * Purpose   : 
+ * Purpose   :
  * Parameters:
  * Variables :
@@ -3811,5 +4363,5 @@
 /*****************************************************************************
  * Name      : HMCreatePipe
- * Purpose   : 
+ * Purpose   :
  * Parameters:
  * Variables :
@@ -3822,5 +4374,5 @@
 BOOL HMCreatePipe(PHANDLE phRead,
                 PHANDLE phWrite,
-                LPSECURITY_ATTRIBUTES lpsa, 
+                LPSECURITY_ATTRIBUTES lpsa,
                 DWORD                 cbPipe)
 {
@@ -3840,5 +4392,5 @@
   {
     SetLastError(ERROR_NOT_ENOUGH_MEMORY);      /* use this as error message */
-    return 0; 
+    return 0;
   }
 
@@ -3847,5 +4399,5 @@
   {
     SetLastError(ERROR_NOT_ENOUGH_MEMORY);      /* use this as error message */
-    return 0; 
+    return 0;
   }
 
@@ -3891,7 +4443,7 @@
   if (rc == 0)     /* oops, creation failed within the device handler */
   {
-    	TabWin32Handles[iIndexNewRead].hmHandleData.hHMHandle = INVALID_HANDLE_VALUE;
-    	TabWin32Handles[iIndexNewWrite].hmHandleData.hHMHandle = INVALID_HANDLE_VALUE;
-	return FALSE;                                           /* signal error */
+      TabWin32Handles[iIndexNewRead].hmHandleData.hHMHandle = INVALID_HANDLE_VALUE;
+      TabWin32Handles[iIndexNewWrite].hmHandleData.hHMHandle = INVALID_HANDLE_VALUE;
+  return FALSE;                                           /* signal error */
   }
 
Index: trunk/src/kernel32/cio.h
===================================================================
--- trunk/src/kernel32/cio.h	(revision 4280)
+++ trunk/src/kernel32/cio.h	(revision 4285)
@@ -1,3 +1,3 @@
-/* $Id: cio.h,v 1.4 1999-06-10 19:11:29 phaller Exp $ */
+/* $Id: cio.h,v 1.5 2000-09-20 21:32:54 hugh Exp $ */
 
 /* Copyright (C) 1995 by Holger Veit (Holger.Veit@gmd.de) */
@@ -16,17 +16,15 @@
 #endif
 
-int CDECL io_init(void);
-int CDECL io_exit(void);
+int io_init1(void);
+int io_init2(short);
+int io_exit1(void);
 
-int CDECL io_init1(void);
-int CDECL io_exit1(void);
-
-char CDECL  c_inb(short);
-short CDECL c_inw(short);
-long CDECL  c_inl(short);
-void CDECL  c_outb(short,char);
-void CDECL  c_outw(short,short);
-void CDECL  c_outl(short,long);
-void CDECL  c_readmsr(long, long *);
+char c_inb(short);
+short c_inw(short);
+long c_inl(short);
+void c_outb(short,char);
+void c_outw(short,short);
+void c_outl(short,long);
+//void CDECL  c_readmsr(long, long *);
 
 #ifdef __cplusplus
Index: trunk/src/kernel32/comm.cpp
===================================================================
--- trunk/src/kernel32/comm.cpp	(revision 4280)
+++ trunk/src/kernel32/comm.cpp	(revision 4285)
@@ -1,29 +1,44 @@
-/* $Id: comm.cpp,v 1.4 2000-02-16 14:25:30 sandervl Exp $ */
+/* $Id: comm.cpp,v 1.5 2000-09-20 21:32:49 hugh Exp $ */
 
 /*
- * PE2LX dialog conversion code
+ * Comport functions
  *
  * Copyright 1998 Patrick Haller (?)
- * Copyright 1998 Felix Maschek	 (?)
+ * Copyright 1998 Felix Maschek  (?)
+ * Copyright 2000 Markus Montkowski
  *
  * Project Odin Software License can be found in LICENSE.TXT
  *
  */
-/*
- * *Comm* stubs
- */
 #include <os2win.h>
+#include <odinwrap.h>
+#include <ctype.h>
+#include <string.h>
+#include <stdio.h>
+#include "winreg.h"
+#include "global.h"
+#include "winnt.h"
+#include "winerror.h"
+#include "winreg.h"
+
 #include "unicode.h"
 #include "handlemanager.h"
 
-#define DBG_LOCALLOG	DBG_comm
+#define DBG_LOCALLOG  DBG_comm
 #include "dbglocal.h"
-
-//------------------------------------------------------------------------------
+ODINDEBUGCHANNEL(KERNEL32-COMM)
+
+/*****************************************************************************
+ * @returns   True on success and fills the COMMCONFIG structure
+ * @param     lpDef        Pointer to device-control string
+ * @param     lpDCB        Pointer to device-control buffer
+ * @remark
+ * @status    untested
+ * @author    Markus Montkowski
+ *****************************************************************************/
 
 BOOL WIN32API BuildCommDCBA( LPCSTR lpDef, LPDCB lpDCB )
 {
-  dprintf(("BuildCommDCBA Not implemented (TRUE)\n"));
-  return(TRUE);
+  return BuildCommDCBAndTimeoutsA(lpDef,lpDCB,NULL);
 }
 
@@ -32,14 +47,295 @@
 BOOL WIN32API BuildCommDCBW( LPCWSTR lpDef, LPDCB lpDCB )
 {
-  dprintf(("BuildCommDCBW Not implemented (TRUE)\n"));
-  return(TRUE);
-}
-
-//------------------------------------------------------------------------------
+  char *asciiname;
+  BOOL rc;
+
+  asciiname  = UnicodeToAsciiString((LPWSTR)lpDef);
+  rc = BuildCommDCBAndTimeoutsA(asciiname, lpDCB, NULL);
+  FreeAsciiString(asciiname);
+  return(rc);
+}
+
+//------------------------------------------------------------------------------
+
+BOOL ValidCOMPort(int Port)
+{
+  // @@@ Todo check in the handlemanager for a registered COM DeviceHandle for this number
+  //     We currently only do static add COM1-COM8 so we simply check for 8
+  return (Port <=8);
+}
+
+/*****************************************************************************
+ * @returns   True on success and fills the COMMCONFIG structure
+ * @param     lpDef          Pointer to device-control string
+ * @param     lpDCB          Pointer to device-control buffer
+ * @param     lpCommTimeouts Pointer to COMMTIMEOUTS
+ * @remark
+ * @status    partly implemented
+ * @author    Markus Montkowski
+ *****************************************************************************/
+
 
 BOOL WIN32API BuildCommDCBAndTimeoutsA( LPCSTR lpDef, LPDCB lpDCB, LPCOMMTIMEOUTS lpCommTimeouts )
 {
-  dprintf(("BuildCommDCBAndTimeoutsA Not implemented (TRUE)\n"));
-  return(TRUE);
+  int port,i;
+  char szNumber[4];
+  char  *ptr,*temp;
+
+  dprintf(("(%s,%p,%p)\n",lpDef,lpDCB,lpCommTimeouts));
+
+  port = -1;
+
+  if (!strnicmp(lpDef,"COM",3))
+  {
+
+    for(i=0;((lpDef[3+i]!=':') && (i<3));i++)
+      szNumber[i] = lpDef[3+i];
+    szNumber[i] = 0;
+
+    port = atoi(szNumber);
+    if (port==0 || lpDef[i]!=':')
+    {
+      SetLastError(ERROR_INVALID_PARAMETER);
+      return FALSE;
+    }
+
+    if (!ValidCOMPort(port))
+    {
+      SetLastError(ERROR_FILE_NOT_FOUND);
+      return FALSE;
+    }
+    temp=(LPSTR)(lpDef+4+i);
+  }
+  else
+    temp=(LPSTR)lpDef;
+
+  lpDCB->DCBlength  = sizeof(DCB);
+  if (strchr(temp,','))
+  {
+    // old style
+
+    char  last=temp[strlen(temp)-1];
+
+    ptr = strtok(temp, ", ");
+
+
+    lpDCB->BaudRate = atoi(ptr);
+    dprintf(("baudrate (%d)\n", lpDCB->BaudRate));
+
+    ptr = strtok(NULL, ", ");
+    if (islower(*ptr))
+      *ptr = toupper(*ptr);
+
+    dprintf(("parity (%c)\n", *ptr));
+    lpDCB->fParity = TRUE;
+    switch (*ptr)
+    {
+      case 'N':
+        lpDCB->Parity = NOPARITY;
+        lpDCB->fParity = FALSE;
+        break;
+      case 'E':
+        lpDCB->Parity = EVENPARITY;
+        break;
+      case 'M':
+        lpDCB->Parity = MARKPARITY;
+        break;
+      case 'O':
+        lpDCB->Parity = ODDPARITY;
+        break;
+      default:
+        SetLastError(ERROR_INVALID_PARAMETER);
+        dprintf(("Unknown parity `%c'!\n", *ptr));
+        return FALSE;
+    }
+
+    ptr = strtok(NULL, ", ");
+    dprintf(("charsize (%c)\n", *ptr));
+    lpDCB->ByteSize = *ptr - '0';
+
+    if((lpDCB->ByteSize<5) ||
+       (lpDCB->ByteSize>8))
+    {
+      SetLastError(ERROR_INVALID_PARAMETER);
+      dprintf(("Unsupported bytesize `%d'!\n", lpDCB->ByteSize));
+      return FALSE;
+    }
+
+    ptr = strtok(NULL, ", ");
+    dprintf(("stopbits (%c%c%c)\n", *ptr,*(ptr+1)=='.'?'.':' ',*(ptr+1)=='.'?*(ptr+2):' '));
+    switch (*ptr)
+    {
+      case '1':
+        if(*(ptr+1)=='.')
+        {
+          if(*(ptr+2)=='5')
+            lpDCB->StopBits = ONE5STOPBITS;
+          else
+          {
+            SetLastError(ERROR_INVALID_PARAMETER);
+            dprintf(("Unsupported # of stopbits !\n"));
+            return FALSE;
+          }
+        }
+        else
+          lpDCB->StopBits = ONESTOPBIT;
+        break;
+      case '2':
+        lpDCB->StopBits = TWOSTOPBITS;
+        break;
+      default:
+        SetLastError(ERROR_INVALID_PARAMETER);
+        dprintf(("Unknown # of stopbits `%c'!\n", *ptr));
+        return FALSE;
+    }
+
+    if(lpDCB->BaudRate==110)
+      lpDCB->StopBits =2;
+
+    if(((lpDCB->ByteSize==5)&&(lpDCB->StopBits==TWOSTOPBITS))||
+       ((lpDCB->ByteSize!=5)&&(lpDCB->StopBits==ONE5STOPBITS)) )
+    {
+      dprintf(("Unsupported Combination of Bytesize `%d' and StopBits %s!\n",
+              lpDCB->ByteSize,lpDCB->StopBits==ONE5STOPBITS?"1.5":"2"));
+      SetLastError(ERROR_INVALID_PARAMETER);
+      return FALSE;
+    }
+
+    lpDCB->fBinary    = TRUE;
+    lpDCB->fNull      = FALSE;
+
+    if (last == 'x')
+    {
+      lpDCB->fInX   = TRUE;
+      lpDCB->fOutX    = TRUE;
+      lpDCB->fOutxCtsFlow = FALSE;
+      lpDCB->fOutxDsrFlow = FALSE;
+      lpDCB->fDtrControl  = DTR_CONTROL_ENABLE;
+      lpDCB->fRtsControl  = RTS_CONTROL_ENABLE;
+    }
+    else
+      if (last=='p')
+      {
+        lpDCB->fInX   = FALSE;
+        lpDCB->fOutX    = FALSE;
+        lpDCB->fOutxCtsFlow = TRUE;
+        lpDCB->fOutxDsrFlow = TRUE;
+        lpDCB->fDtrControl  = DTR_CONTROL_HANDSHAKE;
+        lpDCB->fRtsControl  = RTS_CONTROL_HANDSHAKE;
+      }
+      else
+      {
+        lpDCB->fInX   = FALSE;
+        lpDCB->fOutX    = FALSE;
+        lpDCB->fOutxCtsFlow = FALSE;
+        lpDCB->fOutxDsrFlow = FALSE;
+        lpDCB->fDtrControl  = DTR_CONTROL_ENABLE;
+        lpDCB->fRtsControl  = RTS_CONTROL_ENABLE;
+      }
+    lpDCB->XonChar    = 0;
+    lpDCB->XoffChar   = 0;
+    lpDCB->ErrorChar  = 0;
+    lpDCB->fErrorChar = 0;
+    lpDCB->EofChar    = 0;
+    lpDCB->EvtChar    = 0;
+    lpDCB->XonLim     = 0;
+    lpDCB->XoffLim    = 0;
+    return TRUE;
+  }
+
+  ptr=strtok(temp," ");
+  while (ptr)
+  {
+    DWORD flag,x;
+
+    flag=0;
+    if (!strnicmp("baud=",ptr,5))
+    {
+      if (!sscanf(ptr+5,"%ld",&x))
+      {
+        dprintf(("Couldn't parse %s\n",ptr));
+        SetLastError(ERROR_INVALID_PARAMETER);
+        return FALSE;
+      }
+      lpDCB->BaudRate = x;
+      flag=1;
+    }
+    if (!strnicmp("stop=",ptr,5))
+    {
+      if (!sscanf(ptr+5,"%ld",&x))
+      {
+        dprintf(("Couldn't parse %s\n",ptr));
+        SetLastError(ERROR_INVALID_PARAMETER);
+        return FALSE;
+      }
+      lpDCB->StopBits = x;
+      flag=1;
+    }
+    if (!strnicmp("data=",ptr,5))
+    {
+      if (!sscanf(ptr+5,"%ld",&x))
+      {
+        dprintf(("Couldn't parse %s\n",ptr));
+        SetLastError(ERROR_INVALID_PARAMETER);
+        return FALSE;
+      }
+      lpDCB->ByteSize = x;
+      flag=1;
+    }
+    if (!strnicmp("parity=",ptr,7))
+    {
+      lpDCB->fParity  = TRUE;
+      switch (ptr[8])
+      {
+        case 'N':case 'n':
+          lpDCB->fParity  = FALSE;
+          lpDCB->Parity = NOPARITY;
+          break;
+        case 'E':case 'e':
+          lpDCB->Parity = EVENPARITY;
+          break;
+        case 'O':case 'o':
+          lpDCB->Parity = ODDPARITY;
+          break;
+        case 'M':case 'm':
+          lpDCB->Parity = MARKPARITY;
+          break;
+      }
+      flag=1;
+    }
+    if (!strnicmp("to=",ptr,3))
+    {
+      if (!strnicmp("on",ptr+3,2))
+      {
+        if(NULL==lpCommTimeouts)
+        {
+          dprintf(("TO=ON and no lpCommTimeout"));
+          SetLastError(ERROR_INVALID_PARAMETER);
+          return FALSE;
+        }
+        else
+        {
+          // @@@ Todo Implement timout handling
+          flag=1;
+        }
+      }
+      if (!strnicmp("off",ptr+3,3))
+      {
+        flag=1;
+      }
+    }
+
+    if (!flag)
+    {
+      dprintf(("Unhandled specifier '%s', please report.\n",ptr));
+      SetLastError(ERROR_INVALID_PARAMETER);
+      return FALSE;
+    }
+    ptr=strtok(NULL," ");
+  }
+
+  if (lpDCB->BaudRate==110)
+    lpDCB->StopBits = 2;
+  return TRUE;
 }
 
@@ -48,14 +344,106 @@
 BOOL WIN32API BuildCommDCBAndTimeoutsW( LPCWSTR lpDef, LPDCB lpDCB, LPCOMMTIMEOUTS lpCommTimeouts )
 {
-  dprintf(("BuildCommDCBAndTimeoutsW Not implemented (TRUE)\n"));
-  return(TRUE);
-}
-
-//------------------------------------------------------------------------------
+  char *asciiname;
+  BOOL rc;
+
+  asciiname  = UnicodeToAsciiString((LPWSTR)lpDef);
+  rc = BuildCommDCBAndTimeoutsA(asciiname, lpDCB, lpCommTimeouts);
+  FreeAsciiString(asciiname);
+  return(rc);
+}
+
+//------------------------------------------------------------------------------
+
+typedef BOOL (* WIN32API COMMDLGFUNC)(LPCSTR, HWND, LPCOMMCONFIG );
 
 BOOL WIN32API CommConfigDialogA( LPCSTR lpszName, HWND hWnd, LPCOMMCONFIG lpCC )
 {
-  dprintf(("CommConfigDialogA Not implemented (TRUE)\n"));
-  return(TRUE);
+  COMMDLGFUNC lpfnCommDialog;
+  HMODULE hConfigModule;
+  char    szSerialUI[MAX_PATH+1];
+  char    szKeyname[5];
+  BOOL r;
+  HKEY hkPorts, hkName;
+  LONG rc;
+  DWORD dwType,dwSize;
+  int port;
+
+  dprintf(("CommConfigDialogA (%p %x %p)\n",lpszName, hWnd, lpCC));
+
+  if( strnicmp(lpszName,"com",3) ||
+      strlen(lpszName)<4 ||
+      strlen(lpszName)>7)
+  {
+    SetLastError(ERROR_INVALID_PARAMETER);
+    return FALSE;
+  }
+  port = atoi(lpszName+3);
+  if( (0==port) ||(port>9999))
+  {
+    SetLastError(ERROR_INVALID_PARAMETER);
+    return FALSE;
+  }
+  port--;
+
+  sprintf(szKeyname,"%04d",port);
+  dprintf(("CommConfigDialogA look in reg for port %s",szKeyname));
+  rc = RegOpenKeyExA( HKEY_LOCAL_MACHINE,
+                      "System\\CurrentControlSet\\Services\\Class\\Ports",
+                      0,
+                      KEY_READ,
+                      &hkPorts);
+
+  if(rc!=ERROR_SUCCESS)
+  {
+    SetLastError(ERROR_DEV_NOT_EXIST);
+    return FALSE;
+  }
+
+  rc = RegOpenKeyExA( hkPorts,
+                      szKeyname,
+                      0,
+                      KEY_READ,
+                      &hkName);
+
+  if(rc!=ERROR_SUCCESS)
+  {
+    SetLastError(ERROR_DEV_NOT_EXIST);
+    RegCloseKey(hkPorts);
+    return FALSE;
+  }
+
+  dwSize = sizeof(szSerialUI);
+
+  rc = RegQueryValueExA( hkName,
+                         "ConfigDialog",
+                         NULL,
+                         &dwType,
+                         (LPBYTE)szSerialUI,
+                         &dwSize);
+
+  RegCloseKey(hkName);
+  RegCloseKey(hkPorts);
+  if( (rc!=ERROR_SUCCESS) && (dwType!=REG_SZ) )
+  {
+    SetLastError(ERROR_DEV_NOT_EXIST);
+    return FALSE;
+  }
+
+  hConfigModule = LoadLibraryA(szSerialUI);
+  if(!hConfigModule)
+    return FALSE;
+
+  lpfnCommDialog = (COMMDLGFUNC)GetProcAddress(hConfigModule, (LPCSTR)3L);
+
+  if(!lpfnCommDialog)
+    return FALSE;
+
+  SetLastError(ERROR_SUCCESS);
+
+  r = lpfnCommDialog(lpszName,hWnd,lpCC);
+
+  FreeLibrary(hConfigModule);
+
+  return r;
 }
 
@@ -64,14 +452,66 @@
 BOOL WIN32API CommConfigDialogW( LPCWSTR lpszName, HWND hWnd, LPCOMMCONFIG lpCC )
 {
-  dprintf(("CommConfigDialogW Not implemented (TRUE)\n"));
-  return(TRUE);
-}
-
-//------------------------------------------------------------------------------
-
-BOOL WIN32API GetDefaultCommConfigA( LPCSTR lpszName, LPCOMMCONFIG lpCC, LPDWORD lpdwSize )
-{
-  dprintf(("GetDefaultCommConfigA Not implemented (TRUE)\n"));
-  return(TRUE);
+  char *asciiname;
+  BOOL rc;
+
+  asciiname  = UnicodeToAsciiString((LPWSTR)lpszName);
+  rc = CommConfigDialogA(asciiname,hWnd,lpCC);
+  FreeAsciiString(asciiname);
+  return rc;
+}
+
+/*****************************************************************************
+ * @returns   True on success and fills the COMMCONFIG structure
+ * @param     lpszName     Pointer to devicename
+ * @param     lpCC         Pointer to COMMCONFIG buffer.
+ * @param     lpdwSize     [in]    Pointer to size of Buffer pointed to by lpCC
+ *                         [out]   Number of bytes copied to the buffer
+ *                         [error] If buffer to small Number of bytes needed
+ * @remark
+ * @status    untested
+ * @author    Markus Montkowski
+ *****************************************************************************/
+
+ODINFUNCTION3(BOOL,GetDefaultCommConfigA,
+               LPCSTR, lpszName,
+               LPCOMMCONFIG, lpCC,
+               LPDWORD, lpdwSize )
+{
+  HFILE hCOM;
+  BOOL rc;
+
+  dprintf(("GetDefaultCommConfigA untested stub \n"));
+  SetLastError(ERROR_SUCCESS);
+
+  if(IsBadReadPtr(lpszName,5) ||
+     IsBadWritePtr(lpdwSize,sizeof(DWORD)) ||
+     IsBadWritePtr(lpCC,*lpdwSize) )
+  {
+    SetLastError(ERROR_INVALID_PARAMETER);    /* set win32 error information */
+    return(FALSE);
+  }
+
+  if(strnicmp(lpszName,"COM",3) &&
+     strnicmp(lpszName,"\\COM",4) &&
+     strnicmp(lpszName,"\\dev\\COM",8) )
+  {
+    SetLastError(ERROR_FILE_NOT_FOUND);       /* set win32 error information */
+    return(FALSE);
+  }
+
+  hCOM = HMCreateFile( lpszName,
+                        GENERIC_READ | GENERIC_WRITE,
+                        0,
+                        NULL,
+                        OPEN_EXISTING,
+                        FILE_ATTRIBUTE_NORMAL | FILE_FLAG_OVERLAPPED,
+                        NULL);
+  if(0!=hCOM)
+  {
+    rc = HMCommGetDefaultCommConfig(hCOM, lpCC, lpdwSize);
+    HMCloseHandle(hCOM);
+    return(rc);
+  }
+  return(FALSE);
 }
 
@@ -80,14 +520,75 @@
 BOOL WIN32API GetDefaultCommConfigW( LPCWSTR lpszName, LPCOMMCONFIG lpCC, LPDWORD lpdwSize )
 {
-  dprintf(("GetDefaultCommConfigW Not implemented (TRUE)\n"));
-  return(TRUE);
-}
-
-//------------------------------------------------------------------------------
-
-BOOL WIN32API SetDefaultCommConfigA( LPCSTR lpszName, LPCOMMCONFIG lpCC, DWORD dwSize )
-{
-  dprintf(("SetDefaultCommConfigA Not implemented (TRUE)\n"));
-  return(TRUE);
+  char *asciiname;
+  BOOL rc;
+
+  asciiname  = UnicodeToAsciiString((LPWSTR)lpszName);
+  rc = GetDefaultCommConfigA(asciiname, lpCC, lpdwSize);
+  FreeAsciiString(asciiname);
+  return(rc);
+}
+
+/*****************************************************************************
+ * @returns   True on Success
+ * @param     lpszName     Pointer to devicename
+ * @param     lpCC         Pointer to COMMCONFIG buffer.
+ * @param     dwSize       Size of Buffer pointed to by lpCC
+ * @remark
+ * @status    untested
+ * @author    Markus Montkowski
+ *****************************************************************************/
+
+ODINFUNCTION3(BOOL, SetDefaultCommConfigA,
+               LPCSTR, lpszName,
+               LPCOMMCONFIG, lpCC,
+               DWORD, dwSize )
+{
+  HFILE hCOM;
+  BOOL rc;
+
+  dprintf(("SetDefaultCommConfigA untested stub \n"));
+  SetLastError(ERROR_INVALID_PARAMETER);    /* set win32 error information */
+  rc = FALSE;
+
+  if(!IsBadReadPtr(lpszName,5) &&
+     !IsBadWritePtr(lpCC,dwSize)&&
+     lpCC->dwSize== dwSize )
+  {
+    switch(lpCC->dwProviderSubType)
+    {
+      case PST_RS232:
+        if(strnicmp(lpszName,"COM",3) &&
+           strnicmp(lpszName,"\\COM",4) &&
+           strnicmp(lpszName,"\\dev\\COM",8) )
+        {
+          SetLastError(ERROR_FILE_NOT_FOUND);       /* set win32 error information */
+          return(FALSE);
+        }
+
+        SetLastError(ERROR_SUCCESS);
+
+        hCOM = HMCreateFile( lpszName,
+                              GENERIC_READ | GENERIC_WRITE,
+                              0,
+                              NULL,
+                              OPEN_EXISTING,
+                              FILE_ATTRIBUTE_NORMAL | FILE_FLAG_OVERLAPPED,
+                              NULL);
+        if(0!=hCOM)
+        {
+          rc = HMCommSetDefaultCommConfig(hCOM, lpCC, dwSize);
+          HMCloseHandle(hCOM);
+          return(rc);
+        }
+        break;
+      case PST_PARALLELPORT:
+      case PST_MODEM:
+      default:
+        SetLastError(ERROR_FILE_NOT_FOUND);
+        dprintf(("SetDefaultCommConfigA: ProviderSubType &d Not implemented (FALSE)\n",lpCC->dwProviderSubType));
+        break;
+    }
+  }
+  return(rc);
 }
 
@@ -96,29 +597,58 @@
 BOOL WIN32API SetDefaultCommConfigW( LPCWSTR lpszName, LPCOMMCONFIG lpCC, DWORD dwSize )
 {
-  dprintf(("SetDefaultCommConfigW Not implemented (TRUE)\n"));
-  return(TRUE);
-}
-
-//------------------------------------------------------------------------------
-
-BOOL WIN32API ClearCommBreak( HANDLE hFile )
-{
-  dprintf(("ClearCommBreak Not implemented (TRUE)\n"));
-  return(TRUE);
-}
-
-//------------------------------------------------------------------------------
-
-BOOL WIN32API SetupComm( HANDLE hFile, DWORD dwInQueue, DWORD dwOutQueue )
-{
-  return HMSetupComm(hFile, dwInQueue, dwOutQueue);
-}
-
-//------------------------------------------------------------------------------
-
-BOOL WIN32API EscapeCommFunction( HANDLE hFile, UINT dwFunc )
-{
-  dprintf(("EscapeCommFunction Not implemented (TRUE)\n"));
-  return(TRUE);
+  char *asciiname;
+  BOOL rc;
+
+  asciiname  = UnicodeToAsciiString((LPWSTR)lpszName);
+  rc = SetDefaultCommConfigA(asciiname, lpCC, dwSize);
+  FreeAsciiString(asciiname);
+  return(rc);
+}
+
+/*****************************************************************************
+ * @returns
+ * @param     hFile       Comport handle
+ * @remark
+ * @status    untested
+ * @author    Markus Montkowski
+ *****************************************************************************/
+
+ODINFUNCTION1(BOOL, ClearCommBreak, HANDLE, hFile )
+{
+  return HMCommClearCommBreak(hFile);
+}
+
+/*****************************************************************************
+ * @returns
+ * @param     hFile       Comport handle
+ * @param     dwInQueue   recommended internal buffer size in bytes
+ * @param     dwOutQueue  recommended internal buffer size in bytes
+ * @remark
+ * @status    untested
+ * @author    Markus Montkowski
+ *****************************************************************************/
+
+ODINFUNCTION3(BOOL, SetupComm,
+               HANDLE, hFile,
+               DWORD, dwInQueue,
+               DWORD, dwOutQueue )
+{
+  return HMCommSetupComm(hFile, dwInQueue, dwOutQueue);
+}
+
+/*****************************************************************************
+ * @returns
+ * @param     hFile       Comport handle
+ * @param     dwFunc      extended function to perform
+ * @remark
+ * @status    untested
+ * @author    Markus Montkowski
+ *****************************************************************************/
+
+ODINFUNCTION2 (BOOL, EscapeCommFunction,
+                 HANDLE, hFile,
+                 UINT, dwFunc )
+{
+  return HMCommEscapeCommFunction(hFile, dwFunc);
 }
 
@@ -127,6 +657,5 @@
 BOOL WIN32API GetCommConfig( HANDLE hCommDev, LPCOMMCONFIG lpCC, LPDWORD lpdwSize )
 {
-  dprintf(("GetCommConfig Not implemented (TRUE)\n"));
-  return(TRUE);
+  return HMCommGetCommConfig(hCommDev,lpCC, lpdwSize);
 }
 
@@ -135,6 +664,5 @@
 BOOL WIN32API GetCommModemStatus( HANDLE hFile, LPDWORD lpModemStat )
 {
-  dprintf(("GetCommModemStatus Not implemented (TRUE)\n"));
-  return(TRUE);
+  return HMCommGetCommModemStatus(hFile,lpModemStat);
 }
 
@@ -143,6 +671,5 @@
 BOOL WIN32API SetCommBreak( HANDLE hFile )
 {
-  dprintf(("SetCommBreak Not implemented (TRUE)\n"));
-  return(TRUE);
+  return HMCommSetCommBreak(hFile);
 }
 
@@ -151,53 +678,47 @@
 BOOL WIN32API SetCommConfig( HANDLE hCommDev, LPCOMMCONFIG lpCC, DWORD dwSize )
 {
-  dprintf(("SetCommConfig Not implemented (TRUE)\n"));
-  return(TRUE);
-}
-
-//------------------------------------------------------------------------------
-
-BOOL WIN32API TransmitCommChar( INT hFile, CHAR cChar )
-{
-  dprintf(("TransmitCommChar Not implemented (TRUE)\n"));
-  return(TRUE);
-}
-
-//------------------------------------------------------------------------------
-
-BOOL WIN32API SetCommTimeouts(INT hCommDev, LPCOMMTIMEOUTS lpctmo)
-{
-  dprintf(("OS2SetCommTimeouts Not implemented (TRUE)\n"));
-  return(TRUE);
-}
-
-//------------------------------------------------------------------------------
-
-BOOL WIN32API GetCommTimeouts(INT hCommDev, LPCOMMTIMEOUTS lpctmo)
-{
-  dprintf(("OS2GetCommTimeouts Not implemented\n"));
-  return(FALSE);
-}
-
-//------------------------------------------------------------------------------
-
-BOOL WIN32API GetCommState(INT hCommDev, LPDCB lpdcb)
-{
-  return HMGetCommState(hCommDev, lpdcb);
-}
-
-//------------------------------------------------------------------------------
-
-BOOL WIN32API SetCommState(INT hCommDev, LPDCB lpdcb)
-{
-  dprintf(("OS2SetCommState Not implemented\n"));
-  return(FALSE);
-}
-
-//------------------------------------------------------------------------------
-
-BOOL WIN32API ClearCommError(INT hCommDev, LPDWORD lpdwErrors, LPCOMSTAT lpcst)
-{
-  dprintf(("OS2ClearCommError Not implemented\n"));
-  return(FALSE);
+  return HMCommSetCommConfig(hCommDev,lpCC, dwSize);
+}
+
+//------------------------------------------------------------------------------
+
+BOOL WIN32API TransmitCommChar( HANDLE hFile, CHAR cChar )
+{
+  return HMCommTransmitCommChar(hFile,cChar);
+}
+
+//------------------------------------------------------------------------------
+
+BOOL WIN32API SetCommTimeouts( HANDLE hCommDev, LPCOMMTIMEOUTS lpctmo)
+{
+  return HMCommSetCommTimeouts(hCommDev, lpctmo);
+}
+
+//------------------------------------------------------------------------------
+
+BOOL WIN32API GetCommTimeouts(HANDLE hCommDev, LPCOMMTIMEOUTS lpctmo)
+{
+  return HMCommGetCommTimeouts(hCommDev, lpctmo);
+}
+
+//------------------------------------------------------------------------------
+
+BOOL WIN32API GetCommState(HANDLE hCommDev, LPDCB lpDCB)
+{
+  return HMCommGetCommState(hCommDev, lpDCB);
+}
+
+//------------------------------------------------------------------------------
+
+BOOL WIN32API SetCommState(HANDLE hCommDev, LPDCB lpDCB)
+{
+  return HMCommSetCommState(hCommDev, lpDCB);
+}
+
+//------------------------------------------------------------------------------
+
+BOOL WIN32API ClearCommError(HANDLE hCommDev, LPDWORD lpdwErrors, LPCOMSTAT lpcst)
+{
+  return HMCommClearCommError(hCommDev, lpdwErrors, lpcst);
 }
 
@@ -206,22 +727,19 @@
 BOOL WIN32API PurgeComm(HANDLE hCommDev, DWORD fdwAction)
 {
-  dprintf(("OS2PurgeComm Not implemented (TRUE)\n"));
-  return(TRUE);
-}
-
-//------------------------------------------------------------------------------
-
-BOOL WIN32API SetCommMask(INT hCommDev, DWORD fdwEvtMask)
-{
-  dprintf(("SetCommMask Not implemented (TRUE)\n"));
-  return(TRUE);
-}
-
-//------------------------------------------------------------------------------
-
-BOOL WIN32API GetCommMask(HANDLE hCommDev, LPDWORD fdwEvtMask)
-{
-  dprintf(("GetCommMask Not implemented (TRUE)\n"));
-  return(TRUE);
+  return HMCommPurgeComm(hCommDev,fdwAction);
+}
+
+//------------------------------------------------------------------------------
+
+BOOL WIN32API SetCommMask(HANDLE hCommDev, DWORD fdwEvtMask)
+{
+  return HMCommSetCommMask( hCommDev,fdwEvtMask);
+}
+
+//------------------------------------------------------------------------------
+
+BOOL WIN32API GetCommMask(HANDLE hCommDev, LPDWORD lpfdwEvtMask)
+{
+  return HMCommGetCommMask( hCommDev,lpfdwEvtMask);
 }
 
@@ -230,17 +748,16 @@
 BOOL WIN32API GetCommProperties(HANDLE hCommDev, LPCOMMPROP lpcmmp)
 {
-  dprintf(("GetCommProperties Not implemented (TRUE)\n"));
-  return(TRUE);
-}
-
-//------------------------------------------------------------------------------
-
-BOOL WIN32API WaitCommEvent(HANDLE hCommDev, LPDWORD lpfdwEvtMask,
-                   LPOVERLAPPED lpo)
-{
-  dprintf(("WaitCommEvent Not implemented (TRUE)\n"));
-  return(TRUE);
-}
-
-//------------------------------------------------------------------------------
-
+  return HMCommGetCommProperties(hCommDev, lpcmmp);
+}
+
+//------------------------------------------------------------------------------
+
+BOOL WIN32API WaitCommEvent( HANDLE hCommDev,
+                             LPDWORD lpfdwEvtMask,
+                             LPOVERLAPPED lpo)
+{
+  return HMCommWaitCommEvent(hCommDev, lpfdwEvtMask, lpo);
+}
+
+//------------------------------------------------------------------------------
+
Index: trunk/src/kernel32/hmcomm.cpp
===================================================================
--- trunk/src/kernel32/hmcomm.cpp	(revision 4280)
+++ trunk/src/kernel32/hmcomm.cpp	(revision 4285)
@@ -1,3 +1,3 @@
-/* $Id: hmcomm.cpp,v 1.4 2000-02-16 14:23:58 sandervl Exp $ */
+/* $Id: hmcomm.cpp,v 1.5 2000-09-20 21:32:51 hugh Exp $ */
 
 /*
@@ -10,7 +10,8 @@
  */
 
-#include <odin.h>
-#include <win32type.h>
-#include <misc.h>
+
+
+#include <os2win.h>
+#include <string.h>
 #include "handlemanager.h"
 #include "hmdevice.h"
@@ -18,22 +19,133 @@
 #include "oslibdos.h"
 
-#define DBG_LOCALLOG	DBG_hmcomm
+#define DBG_LOCALLOG  DBG_hmcomm
 #include "dbglocal.h"
 
+#define MAGIC_COM 0x12abcd34
+
+#define IOCTL_ASYNC          0x01
+#define ASYNC_GETDCBINFO     0x73
+#define ASYNC_SETDCBINFO     0x53
+#define ASYNC_SETLINECTRL    0x42
+#define ASYNC_GETCOMMEVENT   0x72
+#define ASYNC_EXTGETBAUDRATE 0x63
+#define ASYNC_EXTSETBAUDRATE 0x43
+#define ASYNC_GETCOMMERROR   0x6D
+#define ASYNC_GETCOMMSTATUS  0x65
+#define ASYNC_GETINQUECOUNT  0x68
+#define ASYNC_GETOUTQUECOUNT 0x69
+#define ASYNC_GETMODEMINPUT  0x67
+#define ASYNC_TRANSMITIMM    0x44
+#define ASYNC_SETBREAKON     0x4B
+#define ASYNC_SETBREAKOFF    0x45
+#define ASYNC_SETMODEMCTRL   0x46
+#define ASYNC_STARTTRANSMIT  0x48
+#define ASYNC_STOPTRANSMIT   0x47
+
+
+
+#pragma pack(1)
+typedef struct _DCBINFO
+{
+  USHORT   usWriteTimeout;         /*  Time period used for Write Timeout processing. */
+  USHORT   usReadTimeout;          /*  Time period used for Read Timeout processing. */
+  BYTE     fbCtlHndShake;          /*  HandShake Control flag. */
+  BYTE     fbFlowReplace;          /*  Flow Control flag. */
+  BYTE     fbTimeOut;              /*  Timeout flag. */
+  BYTE     bErrorReplacementChar;  /*  Error Replacement Character. */
+  BYTE     bBreakReplacementChar;  /*  Break Replacement Character. */
+  BYTE     bXONChar;               /*  Character XON. */
+  BYTE     bXOFFChar;              /*  Character XOFF. */
+} DCBINFO;
+typedef DCBINFO *PDCBINFO;
+
+
+typedef struct _RXQUEUE
+{
+  USHORT   cch;  /*  Number of characters in the queue. */
+  USHORT   cb;   /*  Size of receive/transmit queue. */
+} RXQUEUE;
+
+typedef RXQUEUE *PRXQUEUE;
+
+
+typedef struct _MODEMSTATUS
+{
+  BYTE   fbModemOn;   /*  Modem Control Signals ON Mask. */
+  BYTE   fbModemOff;  /*  Modem Control Signals OFF Mask. */
+} MODEMSTATUS;
+
+typedef MODEMSTATUS *PMODEMSTATUS;
+
+
+#pragma pack()
+
+
+
+
+
+typedef struct _HMDEVCOMDATA
+{
+  ULONG ulMagic;
+  // Win32 Device Control Block
+  COMMCONFIG   CommCfg;
+  COMMTIMEOUTS CommTOuts;
+  DWORD dwInBuffer, dwOutBuffer;
+  DWORD dwEventMask;
+  //OS/2 Device Control Block
+  DCBINFO dcbOS2;
+} HMDEVCOMDATA, *PHMDEVCOMDATA;
+
+VOID * CreateDevData()
+{
+  PHMDEVCOMDATA pData;
+  pData = new HMDEVCOMDATA();
+  if(NULL!=pData)
+  {
+    memset(pData,0,sizeof(HMDEVCOMDATA));
+    pData->ulMagic = MAGIC_COM;
+    pData->CommCfg.dwSize   = sizeof(COMMCONFIG);
+    pData->CommCfg.wVersion = 1;
+    pData->CommCfg.dwProviderSubType = PST_RS232;
+    pData->CommCfg.dcb.DCBlength = sizeof(DCB);
+    pData->CommCfg.dcb.BaudRate  = CBR_1200;
+    pData->CommCfg.dcb.ByteSize = 8;
+    pData->CommCfg.dcb.Parity   = NOPARITY;
+    pData->CommCfg.dcb.StopBits = ONESTOPBIT;
+    pData->dwInBuffer  = 16;
+    pData->dwOutBuffer = 16;
+  }
+  return pData;
+}
 
 HMDeviceCommClass::HMDeviceCommClass(LPCSTR lpDeviceName) : HMDeviceHandler(lpDeviceName)
 {
-  dprintf(("HMDeviceCommClass: Register COM1 to COM4 with Handle Manager\n"));
-  HMDeviceRegister("COM1", this);
-  HMDeviceRegister("COM2", this);
-  HMDeviceRegister("COM3", this);
-  HMDeviceRegister("COM4", this);
-  HMDeviceRegister("COM5", this);
-  HMDeviceRegister("COM6", this);
-  HMDeviceRegister("COM7", this);
-  HMDeviceRegister("COM8", this);
-}
-
-
+  VOID *pData;
+  dprintf(("HMDeviceCommClass: Register COM1 to COM8 with Handle Manager\n"));
+  pData = CreateDevData();
+  if(pData!= NULL)
+    HMDeviceRegisterEx("COM1", this, pData);
+  pData = CreateDevData();
+  if(pData!= NULL)
+    HMDeviceRegisterEx("COM2", this, pData);
+  pData = CreateDevData();
+  if(pData!= NULL)
+    HMDeviceRegisterEx("COM3", this, pData);
+  pData = CreateDevData();
+  if(pData!= NULL)
+    HMDeviceRegisterEx("COM4", this, pData);
+  pData = CreateDevData();
+  if(pData!= NULL)
+    HMDeviceRegisterEx("COM5", this, pData);
+  pData = CreateDevData();
+  if(pData!= NULL)
+    HMDeviceRegisterEx("COM6", this, pData);
+  pData = CreateDevData();
+  if(pData!= NULL)
+    HMDeviceRegisterEx("COM7", this, pData);
+  pData = CreateDevData();
+  if(pData!= NULL)
+    HMDeviceRegisterEx("COM8", this, pData);
+}
 
 DWORD HMDeviceCommClass::CreateFile(LPCSTR lpFileName,
@@ -46,5 +158,5 @@
   pHMHandleData->hHMHandle = 0;
 
-  //AH: TODO parse Win32 security handles   
+  //AH: TODO parse Win32 security handles
   OSLibDosDisableHardError(TRUE);
   pHMHandleData->hHMHandle = OSLibDosOpen((char*)lpFileName,
@@ -54,5 +166,28 @@
   OSLibDosDisableHardError(FALSE);
   if (pHMHandleData->hHMHandle != 0)
+  {
+    ULONG ulLen;
+    APIRET rc;
+
+    pHMHandleData->lpHandlerData = new HMDEVCOMDATA();
+    // Init The handle instance with the default default device config
+    memcpy( pHMHandleData->lpHandlerData,
+            pHMHandleData->lpDeviceData,
+            sizeof(HMDEVCOMDATA));
+
+    ulLen = sizeof(DCBINFO);
+
+    rc = OSLibDosDevIOCtl( pHMHandleData->hHMHandle,
+                      IOCTL_ASYNC,
+                      ASYNC_GETDCBINFO,
+                      0,0,0,
+                      &((PHMDEVCOMDATA)pHMHandleData->lpHandlerData)->dcbOS2,ulLen,&ulLen);
+
+    if(!rc)
+    {
+      return -1;
+    }
     return 0;
+  }
   else
     return  -1;
@@ -64,12 +199,13 @@
 {
   dprintf(("HMComm: Serial communication port close request\n"));
+  delete pHMHandleData->lpHandlerData;
   return OSLibDosClose(pHMHandleData->hHMHandle);
 }
 
 /*****************************************************************************
- * Name      : DWORD HMDeviceHandler::SetupComm      
+ * Name      : DWORD HMDeviceHandler::SetupComm
  * Purpose   : set com port parameters (queue)
  * Variables :
- * Result    : 
+ * Result    :
  * Remark    :
  * Status    :
@@ -78,9 +214,750 @@
  *****************************************************************************/
 
-BOOL HMDeviceCommClass::SetupComm(PHMHANDLEDATA pHMHandleData, DWORD dwInQueue, DWORD dwOutQueue)
-{
-  dprintf(("HMDeviceCommClass::SetupComm unimplemented stub!"));
-
-
-  return(TRUE);
-}
+BOOL HMDeviceCommClass::SetupComm( PHMHANDLEDATA pHMHandleData,
+                                   DWORD dwInQueue,
+                                   DWORD dwOutQueue)
+{
+  dprintf(("HMDeviceCommClass::SetupComm "));
+  PHMDEVCOMDATA pDevData = (PHMDEVCOMDATA)pHMHandleData->lpHandlerData;
+  if((NULL==pDevData) || (pDevData->ulMagic != MAGIC_COM) )
+  {
+    O32_SetLastError(ERROR_INVALID_HANDLE);
+    return FALSE;
+  }
+  pDevData->dwInBuffer  = dwInQueue;
+  pDevData->dwOutBuffer = dwOutQueue;
+
+  return(TRUE);
+}
+
+BOOL HMDeviceCommClass::WaitCommEvent( PHMHANDLEDATA pHMHandleData,
+                                       LPDWORD lpfdwEvtMask,
+                                       LPOVERLAPPED lpo)
+{
+  APIRET rc;
+  ULONG ulLen;
+  USHORT COMEvt;
+  DWORD dwEvent,dwMask;
+
+  PHMDEVCOMDATA pDevData = (PHMDEVCOMDATA)pHMHandleData->lpHandlerData;
+
+  dprintf(("HMDeviceCommClass::WaitCommEvent"));
+  ulLen = sizeof(CHAR);
+
+  dwEvent = 0;
+  rc = 0;
+  ulLen = sizeof(COMEvt);
+  dwMask = pDevData->dwEventMask;
+  while( (0==rc) &&
+        !(dwEvent & dwMask) &&
+        (dwMask ==pDevData->dwEventMask) ) // Exit if the Mask gets changed
+  {
+    rc = OSLibDosDevIOCtl( pHMHandleData->hHMHandle,
+                      IOCTL_ASYNC,
+                      ASYNC_GETCOMMEVENT,
+                      0,0,0,
+                      &COMEvt,ulLen,&ulLen);
+    if(!rc)
+    {
+      dwEvent |= (COMEvt&0x0001)? EV_RXCHAR:0;
+      //dwEvent |= (COMEvt&0x0002)? 0:0;
+      dwEvent |= (COMEvt&0x0004)? EV_TXEMPTY:0;
+      dwEvent |= (COMEvt&0x0008)? EV_CTS:0;
+      dwEvent |= (COMEvt&0x0010)? EV_DSR:0;
+      //dwEvent |= (COMEvt&0x0020)? 0:0; DCS = RLSD?
+      dwEvent |= (COMEvt&0x0040)? EV_BREAK:0;
+      dwEvent |= (COMEvt&0x0080)? EV_ERR:0;
+      dwEvent |= (COMEvt&0x0100)? EV_RING:0;
+    }
+    DosSleep(100);
+  }
+  *lpfdwEvtMask = rc==0?dwEvent:0;
+  return(rc==0);
+}
+
+
+#pragma pack(1)
+typedef struct
+{
+  ULONG ulCurrBaud;
+  UCHAR ucCurrFrac;
+  ULONG ulMinBaud;
+  UCHAR ucMinFrac;
+  ULONG ulMaxBaud;
+  UCHAR ucMaxFrac;
+} EXTBAUDGET, *PEXTBAUDGET;
+
+typedef struct
+{
+  ULONG ulBaud;
+  UCHAR ucFrac;
+} EXTBAUDSET, *PEXTBAUDSET;
+#pragma pack()
+
+BAUDTABLEENTRY BaudTable[] =
+{
+  {75,BAUD_075},
+  {110,BAUD_110},
+  {134,BAUD_134_5},
+  {150,BAUD_150},
+  {300,BAUD_300},
+  {600,BAUD_600},
+  {1200,BAUD_1200},
+  {1800,BAUD_1800},
+  {2400,BAUD_2400},
+  {4800,BAUD_4800},
+  {7200,BAUD_7200},
+  {9600,BAUD_9600},
+  {14400,BAUD_14400},
+  {19200,BAUD_19200},
+  {38400,BAUD_38400},
+  {56000,BAUD_56K},
+  {57600,BAUD_57600},
+  {115200,BAUD_115200},
+  {128000,BAUD_128K}
+};
+
+#define BaudTableSize (sizeof(BaudTable)/sizeof(BAUDTABLEENTRY))
+
+BOOL HMDeviceCommClass::GetCommProperties( PHMHANDLEDATA pHMHandleData,
+                                           LPCOMMPROP lpcmmp)
+{
+  EXTBAUDGET BaudInfo;
+  APIRET rc;
+  ULONG ulLen;
+  USHORT COMErr;
+  int i;
+  dprintf(("HMDeviceCommClass::GetCommProperties"));
+
+  ulLen = sizeof(EXTBAUDGET);
+  rc = OSLibDosDevIOCtl( pHMHandleData->hHMHandle,
+                    IOCTL_ASYNC,
+                    ASYNC_EXTGETBAUDRATE,
+                    0,0,0,
+                    &BaudInfo,ulLen,&ulLen);
+  memset(lpcmmp,0,sizeof(COMMPROP));
+  lpcmmp->wPacketLength  = sizeof(COMMPROP);
+  lpcmmp->wPacketVersion = 1; //???
+  lpcmmp->dwServiceMask  = SP_SERIALCOMM;
+  for(i=0;i<BaudTableSize && BaudInfo.ulMaxBaud <= BaudTable[i].dwBaudRate;i++);
+  lpcmmp->dwMaxBaud      = BaudTable[i].dwBaudFlag;
+  lpcmmp->dwProvSubType =  PST_RS232;
+  lpcmmp->dwProvCapabilities = PCF_DTRDSR | PCF_PARITY_CHECK |
+                               PCF_RTSCTS | PCF_SETXCHAR |
+                               PCF_XONXOFF;
+  lpcmmp->dwSettableParams   = SP_BAUD | SP_DATABITS |
+                               SP_HANDSHAKEING | SP_PARITY |
+                               SP_PARITY_CHECK | SP_STOPBIT;
+  lpcmmp->dwSettableBaud = 0;
+  for(i=0;i<BaudTableSize;i++)
+  {
+    if ( (BaudTable[i].dwBaudRate>=BaudInfo.ulMinBaud) &&
+         (BaudTable[i].dwBaudRate<=BaudInfo.ulMaxBaud) )
+      lpcmmp->dwSettableBaud |= BaudTable[i].dwBaudFlag;
+  }
+  lpcmmp->dwSettableBaud |= BAUD_USER;
+  lpcmmp->wSettableData = DATABITS_5 | DATABITS_6 | DATABITS_7 | DATABITS_8;
+  lpcmmp->wSettableStopParity = STOPBITS_10 | STOPBITS_15 | STOPBITS_20 |
+                                PARITY_NONE | PARITY_ODD | PARITY_EVEN |
+                                PARITY_MARK | PARITY_SPACE;
+  return(rc==0);
+}
+
+BOOL HMDeviceCommClass::GetCommMask( PHMHANDLEDATA pHMHandleData,
+                                     LPDWORD lpfdwEvtMask)
+{
+  PHMDEVCOMDATA pDevData = (PHMDEVCOMDATA)pHMHandleData->lpHandlerData;
+
+  dprintf(("HMDeviceCommClass::GetCommMask"));
+
+  *lpfdwEvtMask = pDevData->dwEventMask;
+  return(TRUE);
+}
+
+BOOL HMDeviceCommClass::SetCommMask( PHMHANDLEDATA pHMHandleData,
+                                     DWORD fdwEvtMask)
+{
+  PHMDEVCOMDATA pDevData = (PHMDEVCOMDATA)pHMHandleData->lpHandlerData;
+  dprintf(("HMDeviceCommClass::SetCommMask"));
+
+  pDevData->dwEventMask = fdwEvtMask & ~(EV_RLSD|EV_RXFLAG); // Clear the 2 not supported Flags.
+  return(TRUE);
+}
+
+BOOL HMDeviceCommClass::PurgeComm( PHMHANDLEDATA pHMHandleData,
+                                   DWORD fdwAction)
+{
+  dprintf(("HMDeviceCommClass::PurgeComm unimplemented stub!"));
+  // ToDo: find a way to stop the current transmision didn't find
+  // any clue how to in Control Program Guide and reference
+
+  return(TRUE);
+}
+BOOL HMDeviceCommClass::ClearCommError( PHMHANDLEDATA pHMHandleData,
+                                        LPDWORD lpdwErrors,
+                                        LPCOMSTAT lpcst)
+{
+  APIRET rc;
+  ULONG ulLen;
+  USHORT COMErr;
+
+  dprintf(("HMDeviceCommClass::ClearCommError"));
+  ulLen = sizeof(USHORT);
+
+  rc = OSLibDosDevIOCtl( pHMHandleData->hHMHandle,
+                    IOCTL_ASYNC,
+                    ASYNC_GETCOMMERROR,
+                    0,0,0,
+                    &COMErr,2,&ulLen);
+  *lpdwErrors = 0;
+  *lpdwErrors |= (COMErr & 0x0001)?CE_OVERRUN:0;
+  *lpdwErrors |= (COMErr & 0x0002)?CE_RXOVER:0;
+  *lpdwErrors |= (COMErr & 0x0004)?CE_RXPARITY:0;
+  *lpdwErrors |= (COMErr & 0x0008)?CE_FRAME:0;
+
+  if(lpcst)
+  {
+    UCHAR ucStatus;
+    RXQUEUE qInfo;
+    ulLen = 1;
+    rc = OSLibDosDevIOCtl( pHMHandleData->hHMHandle,
+                      IOCTL_ASYNC,
+                      ASYNC_GETCOMMSTATUS,
+                      0,0,0,
+                      &ucStatus,ulLen,&ulLen);
+    if(!rc)
+    {
+      lpcst->fCtsHold  = ((ucStatus & 0x01)>0);
+      lpcst->fDsrHold  = ((ucStatus & 0x02)>0);
+      lpcst->fRlsdHold = FALSE;//(ucStatus & 0x04)>0);
+      lpcst->fXoffHold = ((ucStatus & 0x08)>0);
+      lpcst->fXoffSend = ((ucStatus & 0x10)>0);
+      lpcst->fEof      = ((ucStatus & 0x20)>0);// Is break = Eof ??
+      lpcst->fTxim     = ((ucStatus & 0x40)>0);
+
+      ulLen = sizeof(qInfo);
+      rc = OSLibDosDevIOCtl( pHMHandleData->hHMHandle,
+                        IOCTL_ASYNC,
+                        ASYNC_GETINQUECOUNT,
+                        0,0,0,
+                        &qInfo,ulLen,&ulLen);
+      if(!rc)
+      {
+        lpcst->cbInQue   = qInfo.cch;
+        rc = OSLibDosDevIOCtl( pHMHandleData->hHMHandle,
+                          IOCTL_ASYNC,
+                          ASYNC_GETOUTQUECOUNT,
+                          0,0,0,
+                          &qInfo,ulLen,&ulLen);
+        if(!rc)
+          lpcst->cbOutQue = qInfo.cch;
+      }
+    }
+  }
+
+  return(rc==0);
+}
+BOOL HMDeviceCommClass::SetCommState( PHMHANDLEDATA pHMHandleData,
+                                      LPDCB lpDCB)
+{
+  APIRET rc;
+  PHMDEVCOMDATA pDevData = (PHMDEVCOMDATA)pHMHandleData->lpHandlerData;
+  DCB *pCurDCB = &pDevData->CommCfg.dcb;
+  dprintf(("HMDeviceCommClass::SetCommState"));
+
+  rc = 0;
+  if(pCurDCB->BaudRate != lpDCB->BaudRate)
+    rc = SetBaud( pHMHandleData,
+                  lpDCB->BaudRate);
+
+  if(!rc)
+  {
+    if( (pCurDCB->ByteSize != lpDCB->ByteSize) ||
+        (pCurDCB->Parity   != lpDCB->Parity) ||
+        (pCurDCB->StopBits != lpDCB->StopBits))
+      rc = SetLine( pHMHandleData,
+                    lpDCB->ByteSize,
+                    lpDCB->Parity,
+                    lpDCB->StopBits);
+  }
+
+  if(!rc)
+  {
+    if( (pCurDCB->fOutxCtsFlow       != lpDCB->fOutxCtsFlow) ||
+        (pCurDCB->fOutxDsrFlow       != lpDCB->fOutxDsrFlow) ||
+        (pCurDCB->fDtrControl        != lpDCB->fDtrControl) ||
+        (pCurDCB->fDsrSensitivity    != lpDCB->fDsrSensitivity) ||
+        (pCurDCB->fTXContinueOnXoff  != lpDCB->fTXContinueOnXoff) ||
+        (pCurDCB->fOutX              != lpDCB->fOutX) ||
+        (pCurDCB->fInX               != lpDCB->fInX) ||
+        (pCurDCB->fErrorChar         != lpDCB->fErrorChar) ||
+        (pCurDCB->fNull              != lpDCB->fNull) ||
+        (pCurDCB->fRtsControl        != lpDCB->fRtsControl) ||
+        (pCurDCB->fAbortOnError      != lpDCB->fAbortOnError) ||
+        (pCurDCB->XonChar            != lpDCB->XonChar) ||
+        (pCurDCB->XoffChar           != lpDCB->XoffChar) ||
+        (pCurDCB->ErrorChar          != lpDCB->ErrorChar))
+      SetOS2DCB( pHMHandleData,
+                 lpDCB->fOutxCtsFlow, lpDCB->fOutxDsrFlow,
+                 lpDCB->fDtrControl,  lpDCB->fDsrSensitivity,
+                 lpDCB->fTXContinueOnXoff, lpDCB->fOutX,
+                 lpDCB->fInX, lpDCB->fErrorChar,
+                 lpDCB->fNull, lpDCB->fRtsControl,
+                 lpDCB->fAbortOnError, lpDCB->XonChar,
+                 lpDCB->XoffChar,lpDCB->ErrorChar);
+  }
+
+  return(rc==0);
+}
+BOOL HMDeviceCommClass::GetCommState( PHMHANDLEDATA pHMHandleData,
+                                      LPDCB lpdcb)
+{
+  PHMDEVCOMDATA pDevData = (PHMDEVCOMDATA)pHMHandleData->lpHandlerData;
+
+  dprintf(("HMDeviceCommClass::GetCommState"));
+  memcpy(lpdcb,&pDevData->CommCfg.dcb,sizeof(DCB));
+
+  return(TRUE);
+}
+BOOL HMDeviceCommClass::GetCommModemStatus( PHMHANDLEDATA pHMHandleData,
+                                          LPDWORD lpModemStat )
+{
+  APIRET rc;
+  ULONG ulLen;
+  USHORT COMErr;
+  UCHAR ucStatus;
+
+  dprintf(("HMDeviceCommClass::TransmitCommChar partly implemented"));
+  ulLen = sizeof(CHAR);
+
+  ulLen = 1;
+  *lpModemStat = 0;
+
+  rc = OSLibDosDevIOCtl( pHMHandleData->hHMHandle,
+                    IOCTL_ASYNC,
+                    ASYNC_GETMODEMINPUT,
+                    0,0,0,
+                    &ucStatus,ulLen,&ulLen);
+  if(!rc)
+  {
+    *lpModemStat |= (ucStatus & 0x10)? MS_CTS_ON:0;
+    *lpModemStat |= (ucStatus & 0x20)? MS_DSR_ON:0;
+    *lpModemStat |= (ucStatus & 0x40)? MS_RING_ON:0;
+    //*lpModemStat |= (ucStatus & 0x80)? MS_RSLD_ON:0;
+  }
+
+  return(rc==0);
+}
+
+BOOL HMDeviceCommClass::GetCommTimeouts( PHMHANDLEDATA pHMHandleData,
+                                         LPCOMMTIMEOUTS lpctmo)
+{
+  PHMDEVCOMDATA pDevData = (PHMDEVCOMDATA)pHMHandleData->lpHandlerData;
+
+  dprintf(("HMDeviceCommClass::GetCommTimeouts stub"));
+  memcpy( lpctmo,
+          &pDevData->CommTOuts,
+          sizeof(COMMTIMEOUTS));
+  return(TRUE);
+}
+BOOL HMDeviceCommClass::SetCommTimeouts( PHMHANDLEDATA pHMHandleData,
+                                         LPCOMMTIMEOUTS lpctmo)
+{
+  PHMDEVCOMDATA pDevData = (PHMDEVCOMDATA)pHMHandleData->lpHandlerData;
+  DCBINFO os2dcb;
+  ULONG ulLen;
+  APIRET rc;
+
+  memcpy( &pDevData->CommTOuts,
+          lpctmo,
+          sizeof(COMMTIMEOUTS));
+
+  memcpy(&os2dcb,&pDevData->dcbOS2,sizeof(DCBINFO));
+
+  os2dcb.fbTimeOut = 0x01;
+  if(MAXDWORD==pDevData->CommTOuts.ReadIntervalTimeout)
+  {
+    if( (0==pDevData->CommTOuts.ReadTotalTimeoutMultiplier) &&
+        (0==pDevData->CommTOuts.ReadTotalTimeoutConstant))
+      os2dcb.fbTimeOut = 0x03;
+    else
+      os2dcb.fbTimeOut = 0x02;
+  }
+  else
+  {
+    DWORD dwTimeout;
+    dwTimeout = pDevData->CommTOuts.ReadIntervalTimeout/10;
+    if(dwTimeout)
+      dwTimeout--; // 0=10 ms unit is 10ms or .01s
+    os2dcb.usWriteTimeout = 0x0000FFFF & dwTimeout;
+    os2dcb.usReadTimeout  = 0x0000FFFF & dwTimeout;
+  }
+  ulLen = sizeof(DCBINFO);
+  rc = OSLibDosDevIOCtl( pHMHandleData->hHMHandle,
+                          IOCTL_ASYNC,
+                          ASYNC_SETDCBINFO,
+                          &os2dcb,ulLen,&ulLen,
+                          NULL,0,NULL);
+
+  return(0==rc);
+}
+BOOL HMDeviceCommClass::TransmitCommChar( PHMHANDLEDATA pHMHandleData,
+                                          CHAR cChar )
+{
+  APIRET rc;
+  ULONG ulLen;
+  USHORT COMErr;
+
+  dprintf(("HMDeviceCommClass::TransmitCommChar"));
+  ulLen = sizeof(CHAR);
+
+  rc = OSLibDosDevIOCtl( pHMHandleData->hHMHandle,
+                    IOCTL_ASYNC,
+                    ASYNC_TRANSMITIMM,
+                    &cChar,ulLen,&ulLen,
+                    NULL,0,NULL);
+
+  return(rc==0);
+}
+
+BOOL HMDeviceCommClass::SetCommBreak( PHMHANDLEDATA pHMHandleData )
+{
+  APIRET rc;
+  ULONG ulLen;
+  USHORT COMErr;
+
+  dprintf(("HMDeviceCommClass::SetCommBreak"));
+  ulLen = sizeof(USHORT);
+
+  rc = OSLibDosDevIOCtl( pHMHandleData->hHMHandle,
+                    IOCTL_ASYNC,
+                    ASYNC_SETBREAKON,
+                    0,0,0,
+                    &COMErr,2,&ulLen);
+
+  return(rc==0);
+}
+
+BOOL HMDeviceCommClass::ClearCommBreak( PHMHANDLEDATA pHMHandleData)
+{
+  APIRET rc;
+  ULONG ulLen;
+  USHORT COMErr;
+
+  dprintf(("HMDeviceCommClass::ClearCommBreak"));
+  ulLen = sizeof(USHORT);
+
+  rc = OSLibDosDevIOCtl( pHMHandleData->hHMHandle,
+                    IOCTL_ASYNC,
+                    ASYNC_SETBREAKOFF,
+                    0,0,0,
+                    &COMErr,2,&ulLen);
+
+  return(rc==0);
+}
+
+BOOL HMDeviceCommClass::SetCommConfig( PHMHANDLEDATA pHMHandleData,
+                                       LPCOMMCONFIG lpCC,
+                                       DWORD dwSize )
+{
+  dprintf(("HMDeviceCommClass::SetCommConfig"));
+
+
+  return(TRUE);
+}
+
+BOOL HMDeviceCommClass::GetCommConfig( PHMHANDLEDATA pHMHandleData,
+                                       LPCOMMCONFIG lpCC,
+                                       LPDWORD lpdwSize )
+{
+  PHMDEVCOMDATA pDevData = (PHMDEVCOMDATA)pHMHandleData->lpHandlerData;
+
+  dprintf(("HMDeviceCommClass::GetCommConfig"));
+
+  if( O32_IsBadWritePtr(lpCC,sizeof(COMMCONFIG)) ||
+      *lpdwSize< sizeof(COMMCONFIG) )
+  {
+    O32_SetLastError(ERROR_INSUFFICIENT_BUFFER);
+    *lpdwSize= sizeof(COMMCONFIG);
+    return FALSE;
+  }
+
+  if((NULL==pDevData) || (pDevData->ulMagic != MAGIC_COM) )
+  {
+    O32_SetLastError(ERROR_INVALID_HANDLE);
+    return FALSE;
+  }
+
+  memcpy(lpCC,&pDevData->CommCfg,sizeof(COMMCONFIG));
+  *lpdwSize = sizeof(COMMCONFIG);
+  return(TRUE);
+
+
+  return(TRUE);
+}
+
+BOOL HMDeviceCommClass::EscapeCommFunction( PHMHANDLEDATA pHMHandleData,
+                                            UINT dwFunc )
+{
+  APIRET rc;
+  ULONG ulDLen,ulPLen;
+  USHORT COMErr;
+  MODEMSTATUS mdm;
+
+  dprintf(("HMDeviceCommClass::EscapeCommFunction"));
+
+  ulDLen = sizeof(USHORT);
+  ulPLen = sizeof(MODEMSTATUS);
+  switch(dwFunc)
+  {
+    case CLRDTR:
+      mdm.fbModemOn  = 0x00;
+      mdm.fbModemOff = 0XFE;
+      rc = OSLibDosDevIOCtl( pHMHandleData->hHMHandle,
+                             IOCTL_ASYNC,
+                             ASYNC_SETMODEMCTRL,
+                             &mdm,ulPLen,&ulPLen,
+                             &COMErr,ulDLen,&ulDLen);
+      break;
+    case CLRRTS:
+      mdm.fbModemOn  = 0x00;
+      mdm.fbModemOff = 0XFD;
+      rc = OSLibDosDevIOCtl( pHMHandleData->hHMHandle,
+                             IOCTL_ASYNC,
+                             ASYNC_SETMODEMCTRL,
+                             &mdm,ulPLen,&ulPLen,
+                             &COMErr,ulDLen,&ulDLen);
+      break;
+    case SETDTR:
+      mdm.fbModemOn  = 0x01;
+      mdm.fbModemOff = 0XFF;
+      rc = OSLibDosDevIOCtl( pHMHandleData->hHMHandle,
+                             IOCTL_ASYNC,
+                             ASYNC_SETMODEMCTRL,
+                             &mdm,ulPLen,&ulPLen,
+                             &COMErr,ulDLen,&ulDLen);
+      break;
+    case SETRTS:
+      mdm.fbModemOn  = 0x02;
+      mdm.fbModemOff = 0XFF;
+      rc = OSLibDosDevIOCtl( pHMHandleData->hHMHandle,
+                             IOCTL_ASYNC,
+                             ASYNC_SETMODEMCTRL,
+                             &mdm,ulPLen,&ulPLen,
+                             &COMErr,ulDLen,&ulDLen);
+      break;
+    case SETXOFF:
+      rc = OSLibDosDevIOCtl( pHMHandleData->hHMHandle,
+                             IOCTL_ASYNC,
+                             ASYNC_STOPTRANSMIT,
+                             0,0,0,
+                             0,0,0);
+      break;
+    case SETXON:
+      rc = OSLibDosDevIOCtl( pHMHandleData->hHMHandle,
+                             IOCTL_ASYNC,
+                             ASYNC_STARTTRANSMIT,
+                             0,0,0,
+                             0,0,0);
+      break;
+    default:
+      O32_SetLastError(ERROR_INVALID_PARAMETER);
+      return(FALSE);
+  }
+
+  return(rc==0);
+}
+
+BOOL HMDeviceCommClass::SetDefaultCommConfig( PHMHANDLEDATA pHMHandleData,
+                                              LPCOMMCONFIG lpCC,
+                                              DWORD dwSize)
+{
+  PHMDEVCOMDATA pDevData = (PHMDEVCOMDATA)pHMHandleData->lpDeviceData;
+  if((NULL==pDevData) || (pDevData->ulMagic != MAGIC_COM) )
+  {
+    O32_SetLastError(ERROR_INVALID_HANDLE);
+    return FALSE;
+  }
+  memset(&pDevData->CommCfg,0, sizeof(COMMCONFIG));
+  memcpy(&pDevData->CommCfg,lpCC,dwSize>sizeof(COMMCONFIG)?sizeof(COMMCONFIG):dwSize);
+
+  return(TRUE);
+}
+BOOL HMDeviceCommClass::GetDefaultCommConfig( PHMHANDLEDATA pHMHandleData,
+                                              LPCOMMCONFIG lpCC,
+                                              LPDWORD lpdwSize)
+{
+  PHMDEVCOMDATA pDevData = (PHMDEVCOMDATA)pHMHandleData->lpDeviceData;
+
+  if( O32_IsBadWritePtr(lpCC,sizeof(COMMCONFIG)) ||
+      *lpdwSize< sizeof(COMMCONFIG) )
+  {
+    O32_SetLastError(ERROR_INSUFFICIENT_BUFFER);
+    *lpdwSize= sizeof(COMMCONFIG);
+    return FALSE;
+  }
+
+  if((NULL==pDevData) || (pDevData->ulMagic != MAGIC_COM) )
+  {
+    O32_SetLastError(ERROR_INVALID_HANDLE);
+    return FALSE;
+  }
+
+  memcpy(lpCC,&pDevData->CommCfg,sizeof(COMMCONFIG));
+  *lpdwSize = sizeof(COMMCONFIG);
+  return(TRUE);
+}
+APIRET HMDeviceCommClass::SetLine( PHMHANDLEDATA pHMHandleData,
+                                   UCHAR ucSize,
+                                   UCHAR ucParity,
+                                   UCHAR ucStop)
+{
+  APIRET rc;
+  ULONG ulLen;
+  PHMDEVCOMDATA pDevData = (PHMDEVCOMDATA)pHMHandleData->lpHandlerData;
+  DCB *pCurDCB = &pDevData->CommCfg.dcb;
+  struct
+  {
+    UCHAR ucSize;
+    UCHAR ucParity;
+    UCHAR ucStop;
+    UCHAR ucPadding;
+  }Param;
+
+  ulLen = 3;
+  Param.ucSize   = ucSize;
+  Param.ucParity = ucParity;
+  Param.ucStop   = ucStop;
+
+  rc = OSLibDosDevIOCtl( pHMHandleData->hHMHandle,
+                    IOCTL_ASYNC,
+                    ASYNC_SETLINECTRL,
+                    &Param,ulLen,&ulLen,
+                    NULL,0,NULL);
+
+  if(0==rc)
+  {
+    pCurDCB->ByteSize = ucSize;
+    pCurDCB->Parity   = ucParity;
+    pCurDCB->StopBits = ucStop;
+  }
+
+  return rc;
+}
+
+APIRET HMDeviceCommClass::SetOS2DCB( PHMHANDLEDATA pHMHandleData,
+                                     BOOL fOutxCtsFlow, BOOL fOutxDsrFlow,
+                                     UCHAR ucDtrControl,  BOOL fDsrSensitivity,
+                                     BOOL fTXContinueOnXoff, BOOL fOutX,
+                                     BOOL fInX, BOOL fErrorChar,
+                                     BOOL fNull, UCHAR ucRtsControl,
+                                     BOOL fAbortOnError, BYTE XonChar,
+                                     BYTE XoffChar,BYTE ErrorChar)
+{
+  APIRET rc;
+  ULONG ulLen;
+  DCBINFO os2dcb;
+
+  PHMDEVCOMDATA pDevData = (PHMDEVCOMDATA)pHMHandleData->lpHandlerData;
+  DCB *pCurDCB = &pDevData->CommCfg.dcb;
+
+  memcpy(&os2dcb,&pDevData->dcbOS2,sizeof(DCBINFO));
+  os2dcb.fbCtlHndShake = (ucDtrControl & 0x03) |
+                         (fOutxCtsFlow?0x08:0x00) |
+                         (fOutxDsrFlow?0x10:0x00) |
+                         // No DCD support in Win32 ?!
+                         (fDsrSensitivity?0x40:0x00);
+  os2dcb.fbFlowReplace = (fOutX?0x01:0x00) |
+                         (fInX?0x02:0x00) |
+                         (fErrorChar?0x04:0x00)|
+                         (fNull?0x08:0x00)|
+                         (fTXContinueOnXoff?0x02:0x00)| // Not sure if thats the right flag to test
+                         (ucRtsControl<<6);
+
+  os2dcb.fbTimeOut = 0x01;
+  if(MAXDWORD==pDevData->CommTOuts.ReadIntervalTimeout)
+  {
+    if( (0==pDevData->CommTOuts.ReadTotalTimeoutMultiplier) &&
+        (0==pDevData->CommTOuts.ReadTotalTimeoutConstant))
+      os2dcb.fbTimeOut = 0x03;
+    else
+      os2dcb.fbTimeOut = 0x02;
+  }
+  else
+  {
+    DWORD dwTimeout;
+    dwTimeout = pDevData->CommTOuts.ReadIntervalTimeout/10;
+    if(dwTimeout)
+      dwTimeout--; // 0=10 ms unit is 10ms or .01s
+    os2dcb.usWriteTimeout = 0x0000FFFF & dwTimeout;
+    os2dcb.usReadTimeout  = 0x0000FFFF & dwTimeout;
+  }
+  os2dcb.bErrorReplacementChar = ErrorChar;
+  os2dcb.bXONChar              = XonChar;
+  os2dcb.bXOFFChar             = XoffChar;
+  ulLen = sizeof(DCBINFO);
+  rc = OSLibDosDevIOCtl( pHMHandleData->hHMHandle,
+                          IOCTL_ASYNC,
+                          ASYNC_SETDCBINFO,
+                          &os2dcb,ulLen,&ulLen,
+                          NULL,0,NULL);
+
+  if(0==rc)
+  {
+    memcpy(&pDevData->dcbOS2,&os2dcb,sizeof(DCBINFO));
+    pCurDCB->fOutxCtsFlow       = fOutxCtsFlow;
+    pCurDCB->fOutxDsrFlow       = fOutxDsrFlow;
+    pCurDCB->fDtrControl        = ucDtrControl;
+    pCurDCB->fDsrSensitivity    = fDsrSensitivity;
+    pCurDCB->fTXContinueOnXoff  = fTXContinueOnXoff;
+    pCurDCB->fOutX              = fOutX;
+    pCurDCB->fInX               = fInX;
+    pCurDCB->fErrorChar         = fErrorChar;
+    pCurDCB->fNull              = fNull;
+    pCurDCB->fRtsControl        = ucRtsControl;
+    pCurDCB->fAbortOnError      = fAbortOnError;
+    pCurDCB->XonChar            = XonChar;
+    pCurDCB->XoffChar           = XoffChar;
+    pCurDCB->ErrorChar          = ErrorChar;
+  }
+
+  return rc;
+
+}
+
+APIRET HMDeviceCommClass::SetBaud( PHMHANDLEDATA pHMHandleData,
+                                   DWORD dwNewBaud)
+{
+  APIRET rc;
+  ULONG ulLen;
+  EXTBAUDSET SetBaud;
+  EXTBAUDGET GetBaud;
+  ulLen = sizeof(SetBaud);
+  SetBaud.ulBaud = dwNewBaud;
+  rc = OSLibDosDevIOCtl( pHMHandleData->hHMHandle,
+                    IOCTL_ASYNC,
+                    ASYNC_EXTSETBAUDRATE,
+                    &SetBaud,ulLen,&ulLen,
+                    NULL,0,NULL);
+  if(0==rc)
+  {
+    ulLen = sizeof(GetBaud);
+    rc = OSLibDosDevIOCtl( pHMHandleData->hHMHandle,
+                      IOCTL_ASYNC,
+                      ASYNC_EXTGETBAUDRATE,
+                      NULL,0,NULL,
+                      &GetBaud,ulLen,&ulLen);
+    if(0==rc)
+    {
+      if(dwNewBaud !=GetBaud.ulCurrBaud)
+        rc = 1; // ToDo set a proper Errorhandling
+      else
+      {
+        ((PHMDEVCOMDATA)pHMHandleData->lpDeviceData)->CommCfg.dcb.BaudRate = dwNewBaud;
+        ((PHMDEVCOMDATA)pHMHandleData->lpDeviceData)->CommCfg.dcb.BaudRate = dwNewBaud;
+      }
+    }
+  }
+  return rc;
+}
+
Index: trunk/src/kernel32/hmcomm.h
===================================================================
--- trunk/src/kernel32/hmcomm.h	(revision 4280)
+++ trunk/src/kernel32/hmcomm.h	(revision 4285)
@@ -1,3 +1,3 @@
-/* $Id: hmcomm.h,v 1.4 1999-11-27 12:48:26 achimha Exp $ */
+/* $Id: hmcomm.h,v 1.5 2000-09-20 21:32:54 hugh Exp $ */
 
 /*
@@ -12,4 +12,9 @@
 #ifndef _HM_COMM_H_
 #define _HM_COMM_H_
+typedef struct
+{
+  DWORD dwBaudRate;
+  DWORD dwBaudFlag;
+}BAUDTABLEENTRY;
 
 class HMDeviceCommClass : public HMDeviceHandler
@@ -29,6 +34,63 @@
 
   /* this is the handler method for SetComm() */
-  virtual BOOL SetupComm(PHMHANDLEDATA pHMHandleData, DWORD dwInQueue, DWORD dwOutQueue);
+  virtual BOOL WaitCommEvent( PHMHANDLEDATA pHMHandleData,
+                              LPDWORD lpfdwEvtMask,
+                              LPOVERLAPPED lpo);
 
+  virtual BOOL GetCommProperties( PHMHANDLEDATA pHMHandleData,
+                                  LPCOMMPROP lpcmmp);
+  virtual BOOL GetCommMask( PHMHANDLEDATA pHMHandleData,
+                            LPDWORD lpfdwEvtMask);
+  virtual BOOL SetCommMask( PHMHANDLEDATA pHMHandleData,
+                            DWORD fdwEvtMask);
+  virtual BOOL PurgeComm( PHMHANDLEDATA pHMHandleData,
+                          DWORD fdwAction);
+  virtual BOOL ClearCommError( PHMHANDLEDATA pHMHandleData,
+                               LPDWORD lpdwErrors,
+                               LPCOMSTAT lpcst);
+  virtual BOOL SetCommState( PHMHANDLEDATA pHMHandleData,
+                             LPDCB lpdcb) ;
+  virtual BOOL GetCommState( PHMHANDLEDATA pHMHandleData,
+                             LPDCB lpdcb);
+  virtual BOOL GetCommModemStatus( PHMHANDLEDATA pHMHandleData,
+                                   LPDWORD lpModemStat );
+  virtual BOOL GetCommTimeouts( PHMHANDLEDATA pHMHandleData,
+                                LPCOMMTIMEOUTS lpctmo);
+  virtual BOOL SetCommTimeouts( PHMHANDLEDATA pHMHandleData,
+                                LPCOMMTIMEOUTS lpctmo);
+  virtual BOOL TransmitCommChar( PHMHANDLEDATA pHMHandleData,
+                                 CHAR cChar );
+  virtual BOOL SetCommConfig( PHMHANDLEDATA pHMHandleData,
+                              LPCOMMCONFIG lpCC,
+                              DWORD dwSize );
+  virtual BOOL SetCommBreak( PHMHANDLEDATA pHMHandleData );
+  virtual BOOL GetCommConfig( PHMHANDLEDATA pHMHandleData,
+                              LPCOMMCONFIG lpCC,
+                              LPDWORD lpdwSize );
+  virtual BOOL EscapeCommFunction( PHMHANDLEDATA pHMHandleData,
+                                   UINT dwFunc );
+  virtual BOOL SetupComm( PHMHANDLEDATA pHMHandleData,
+                          DWORD dwInQueue,
+                          DWORD dwOutQueue);
+  virtual BOOL ClearCommBreak( PHMHANDLEDATA pHMHandleData);
+  virtual BOOL SetDefaultCommConfig( PHMHANDLEDATA pHMHandleData,
+                                     LPCOMMCONFIG lpCC,
+                                     DWORD dwSize);
+  virtual BOOL GetDefaultCommConfig( PHMHANDLEDATA pHMHandleData,
+                                     LPCOMMCONFIG lpCC,
+                                     LPDWORD lpdwSize);
+  private:
+  APIRET SetLine( PHMHANDLEDATA pHMHandleData,
+                  UCHAR ucSize,UCHAR Parity, UCHAR Stop);
+  APIRET SetOS2DCB( PHMHANDLEDATA pHMHandleData,
+                    BOOL fOutxCtsFlow, BOOL fOutxDsrFlow,
+                    UCHAR ucDtrControl,  BOOL fDsrSensitivity,
+                    BOOL fTXContinueOnXoff, BOOL fOutX,
+                    BOOL fInX, BOOL fErrorChar,
+                    BOOL fNull, UCHAR ucRtsControl,
+                    BOOL fAbortOnError, BYTE XonChar,
+                    BYTE XoffChar,BYTE ErrorChar);
+  APIRET SetBaud( PHMHANDLEDATA pHMHandleData,
+                  DWORD dwNewBaud);
 };
 
Index: trunk/src/kernel32/hmdevice.cpp
===================================================================
--- trunk/src/kernel32/hmdevice.cpp	(revision 4280)
+++ trunk/src/kernel32/hmdevice.cpp	(revision 4285)
@@ -1,3 +1,3 @@
-/* $Id: hmdevice.cpp,v 1.22 2000-08-04 21:12:06 sandervl Exp $ */
+/* $Id: hmdevice.cpp,v 1.23 2000-09-20 21:32:52 hugh Exp $ */
 
 /*
@@ -24,5 +24,5 @@
 #include "HMDevice.h"
 
-#define DBG_LOCALLOG	DBG_hmdevice
+#define DBG_LOCALLOG  DBG_hmdevice
 #include "dbglocal.h"
 
@@ -117,6 +117,6 @@
                                HANDLE  destprocess,
                                PHANDLE desthandle,
-                      	       DWORD   fdwAccess,
-                      	       BOOL    fInherit,
+                               DWORD   fdwAccess,
+                               BOOL    fInherit,
                                DWORD   fdwOptions,
                                DWORD   fdwOdinOptions)
@@ -1085,6 +1085,6 @@
                                          DWORD                      dwMaximumSizeHigh,
                                          DWORD                      dwMaximumSizeLow,
-               		     	         LPCSTR lpName,   
-				         HFILE *hOldMap)  // if create an existing memmap, return handle of old one
+                                 LPCSTR lpName,
+                 HFILE *hOldMap)  // if create an existing memmap, return handle of old one
 {
   dprintf(("KERNEL32: HandleManager::DeviceHandler::CreateFileMapping(%08xh,%08xh,%08xh,%08xh,%08xh,%08xh,%s)\n",
@@ -1123,5 +1123,5 @@
   dprintf(("KERNEL32: HandleManager::DeviceHandler::OpenFileMapping(%08xh,%08xh,%08xh,%08xh)\n",
            pHMHandleData->hHMHandle,
-	   fdwAccess,
+     fdwAccess,
            fInherit,
            lpName));
@@ -1151,5 +1151,5 @@
                                       DWORD         dwFileOffsetLow,
                                       DWORD         dwNumberOfBytesToMap,
-			              LPVOID        lpBaseAddress)
+                    LPVOID        lpBaseAddress)
 {
   dprintf(("KERNEL32: HandleManager::DeviceHandler::MapViewOfFileEx(%08xh,%08xh,%08xh,%08xh,%08xh,%08xh)\n",
@@ -1167,5 +1167,5 @@
  * Purpose   : send command to device driver
  * Variables :
- * Result    : 
+ * Result    :
  * Remark    :
  * Status    :
@@ -1191,8 +1191,8 @@
 
 /*****************************************************************************
- * Name      : DWORD HMDeviceHandler::SetupComm      
+ * Name      : DWORD HMDeviceHandler::SetupComm
  * Purpose   : set com port parameters (queue)
  * Variables :
- * Result    : 
+ * Result    :
  * Remark    :
  * Status    :
@@ -1206,14 +1206,14 @@
            pHMHandleData->hHMHandle,
            dwInQueue, dwOutQueue));
-
-  return(FALSE);
-}
-
-
-/*****************************************************************************
- * Name      : DWORD HMDeviceHandler::GetCommState   
- * Purpose   : query com port control block   
- * Variables :
- * Result    : 
+  SetLastError(ERROR_INVALID_HANDLE);
+  return(FALSE);
+}
+
+
+/*****************************************************************************
+ * Name      : DWORD HMDeviceHandler::GetCommState
+ * Purpose   : query com port control block
+ * Variables :
+ * Result    :
  * Remark    :
  * Status    :
@@ -1226,5 +1226,192 @@
            pHMHandleData->hHMHandle,
            lpdcb));
-
+  SetLastError(ERROR_INVALID_HANDLE);
+  return(FALSE);
+}
+
+BOOL HMDeviceHandler::WaitCommEvent( PHMHANDLEDATA pHMHandleData,
+                                     LPDWORD lpfdwEvtMask,
+                                     LPOVERLAPPED lpo)
+{
+  dprintf(("KERNEL32: HandleManager::DeviceHandler::WaitCommEvent(%08xh,%08xh,%08xh)\n",
+           pHMHandleData->hHMHandle,
+           lpfdwEvtMask,
+           lpo));
+  SetLastError(ERROR_INVALID_HANDLE);
+  return(FALSE);
+}
+
+BOOL HMDeviceHandler::GetCommProperties( PHMHANDLEDATA pHMHandleData,
+                                         LPCOMMPROP lpcmmp)
+{
+  dprintf(("KERNEL32: HandleManager::DeviceHandler::GetCommProperties(%08xh,%08xh)\n",
+           pHMHandleData->hHMHandle,
+           lpcmmp));
+  SetLastError(ERROR_INVALID_HANDLE);
+  return(FALSE);
+}
+
+BOOL HMDeviceHandler::GetCommMask( PHMHANDLEDATA pHMHandleData,
+                                   LPDWORD lpfdwEvtMask)
+{
+  dprintf(("KERNEL32: HandleManager::DeviceHandler::GetCommMask(%08xh,%08xh)\n",
+           pHMHandleData->hHMHandle,
+           lpfdwEvtMask));
+  SetLastError(ERROR_INVALID_HANDLE);
+  return(FALSE);
+}
+
+BOOL HMDeviceHandler::SetCommMask( PHMHANDLEDATA pHMHandleData,
+                                   DWORD fdwEvtMask)
+{
+  dprintf(("KERNEL32: HandleManager::DeviceHandler::SetCommMask(%08xh,%08xh)\n",
+           pHMHandleData->hHMHandle,
+           fdwEvtMask));
+  SetLastError(ERROR_INVALID_HANDLE);
+  return(FALSE);
+}
+
+BOOL HMDeviceHandler::PurgeComm( PHMHANDLEDATA pHMHandleData,
+                                 DWORD fdwAction)
+{
+  dprintf(("KERNEL32: HandleManager::DeviceHandler::PurgeComm(%08xh,%08xh)\n",
+           pHMHandleData->hHMHandle,
+           fdwAction));
+  SetLastError(ERROR_INVALID_HANDLE);
+  return(FALSE);
+}
+
+BOOL HMDeviceHandler::ClearCommError( PHMHANDLEDATA pHMHandleData,
+                                      LPDWORD lpdwErrors,
+                                      LPCOMSTAT lpcst)
+{
+  dprintf(("KERNEL32: HandleManager::DeviceHandler::ClearCommError(%08xh,%08xh,%08xh)\n",
+           pHMHandleData->hHMHandle,
+           lpdwErrors,
+           lpcst));
+  SetLastError(ERROR_INVALID_HANDLE);
+  return(FALSE);
+}
+
+BOOL HMDeviceHandler::SetCommState( PHMHANDLEDATA pHMHandleData,
+                                    LPDCB lpdcb)
+{
+  dprintf(("KERNEL32: HandleManager::DeviceHandler::SetCommState(%08xh,%08xh)\n",
+           pHMHandleData->hHMHandle,
+           lpdcb));
+  SetLastError(ERROR_INVALID_HANDLE);
+  return(FALSE);
+}
+
+BOOL HMDeviceHandler::GetCommTimeouts( PHMHANDLEDATA pHMHandleData,
+                                       LPCOMMTIMEOUTS lpctmo)
+{
+  dprintf(("KERNEL32: HandleManager::DeviceHandler::GetCommTimeouts(%08xh,%08xh)\n",
+           pHMHandleData->hHMHandle,
+           lpctmo));
+  SetLastError(ERROR_INVALID_HANDLE);
+  return(FALSE);
+}
+BOOL HMDeviceHandler::GetCommModemStatus( PHMHANDLEDATA pHMHandleData,
+                                          LPDWORD lpModemStat )
+{
+  dprintf(("KERNEL32: HandleManager::DeviceHandler::GetCommModemStatus(%08xh,%08xh)\n",
+           pHMHandleData->hHMHandle,
+           lpModemStat));
+  SetLastError(ERROR_INVALID_HANDLE);
+  return(FALSE);
+}
+
+BOOL HMDeviceHandler::SetCommTimeouts( PHMHANDLEDATA pHMHandleData,
+                                       LPCOMMTIMEOUTS lpctmo)
+{
+  dprintf(("KERNEL32: HandleManager::DeviceHandler::SetCommTimeouts(%08xh,%08xh)\n",
+           pHMHandleData->hHMHandle,
+           lpctmo));
+  SetLastError(ERROR_INVALID_HANDLE);
+  return(FALSE);
+}
+
+BOOL HMDeviceHandler::TransmitCommChar( PHMHANDLEDATA pHMHandleData,
+                                        CHAR cChar )
+{
+  dprintf(("KERNEL32: HandleManager::DeviceHandler::TransmitCommChar(%08xh,%02xh)\n",
+           pHMHandleData->hHMHandle,
+           cChar));
+  SetLastError(ERROR_INVALID_HANDLE);
+  return(FALSE);
+}
+
+BOOL HMDeviceHandler::SetCommConfig( PHMHANDLEDATA pHMHandleData,
+                                     LPCOMMCONFIG lpCC,
+                                     DWORD dwSize )
+{
+  dprintf(("KERNEL32: HandleManager::DeviceHandler::SetCommConfig(%08xh,%08xh,%08xh)\n",
+           pHMHandleData->hHMHandle,
+           lpCC,
+           dwSize));
+  SetLastError(ERROR_INVALID_HANDLE);
+  return(FALSE);
+}
+
+BOOL HMDeviceHandler::SetCommBreak( PHMHANDLEDATA pHMHandleData )
+{
+  dprintf(("KERNEL32: HandleManager::DeviceHandler::SetCommBreak(%08xh)\n",
+           pHMHandleData->hHMHandle));
+  SetLastError(ERROR_INVALID_HANDLE);
+  return(FALSE);
+}
+
+BOOL HMDeviceHandler::GetCommConfig( PHMHANDLEDATA pHMHandleData,
+                                     LPCOMMCONFIG lpCC,
+                                     LPDWORD lpdwSize )
+{
+  dprintf(("KERNEL32: HandleManager::DeviceHandler::GetCommConfig(%08xh,%08xh,%08xh)\n",
+           pHMHandleData->hHMHandle,
+           lpCC,
+           lpdwSize));
+  SetLastError(ERROR_INVALID_HANDLE);
+  return(FALSE);
+}
+
+BOOL HMDeviceHandler::EscapeCommFunction( PHMHANDLEDATA pHMHandleData,
+                                          UINT dwFunc )
+{
+  dprintf(("KERNEL32: HandleManager::DeviceHandler::EscapeCommFunction(%08xh,%08xh)\n",
+           pHMHandleData->hHMHandle,
+           dwFunc));
+  SetLastError(ERROR_INVALID_HANDLE);
+  return(FALSE);
+}
+
+BOOL HMDeviceHandler::ClearCommBreak( PHMHANDLEDATA pHMHandleData)
+{
+  dprintf(("KERNEL32: HandleManager::DeviceHandler::ClearCommBreak(%08xh)\n",
+           pHMHandleData->hHMHandle));
+  SetLastError(ERROR_INVALID_HANDLE);
+  return(FALSE);
+}
+
+BOOL HMDeviceHandler::SetDefaultCommConfig( PHMHANDLEDATA pHMHandleData,
+                                            LPCOMMCONFIG lpCC,
+                                            DWORD dwSize)
+{
+  dprintf(("KERNEL32: HandleManager::DeviceHandler::SetDefaultCommConfig(%08xh,%08xh,%08xh)\n",
+           pHMHandleData->hHMHandle,
+           lpCC,
+           dwSize));
+  SetLastError(ERROR_INVALID_HANDLE);
+  return(FALSE);
+}
+
+BOOL HMDeviceHandler::GetDefaultCommConfig( PHMHANDLEDATA pHMHandleData,
+                                            LPCOMMCONFIG lpCC,
+                                            LPDWORD lpdwSize)
+{
+  dprintf(("KERNEL32: HandleManager::DeviceHandler::GetDefaultCommConfig(%08xh,%08xh,%08xh)\n",
+           pHMHandleData->hHMHandle,
+           lpCC,
+           lpdwSize));
+  SetLastError(ERROR_INVALID_HANDLE);
   return(FALSE);
 }
@@ -1232,7 +1419,7 @@
 /*****************************************************************************
  * Name      : DWORD HMDeviceHandler::OpenThreadToken
- * Purpose   : 
- * Variables :
- * Result    : 
+ * Purpose   :
+ * Variables :
+ * Result    :
  * Remark    :
  * Status    :
@@ -1241,5 +1428,5 @@
  *****************************************************************************/
 
-DWORD HMDeviceHandler::OpenThreadToken(PHMHANDLEDATA pHMHandleData, 
+DWORD HMDeviceHandler::OpenThreadToken(PHMHANDLEDATA pHMHandleData,
                                        HANDLE  ThreadHandle,
                                        BOOL    OpenAsSelf)
@@ -1254,7 +1441,7 @@
 /*****************************************************************************
  * Name      : DWORD HMDeviceHandler::OpenThreadToken
- * Purpose   : 
- * Variables :
- * Result    : 
+ * Purpose   :
+ * Variables :
+ * Result    :
  * Remark    :
  * Status    :
@@ -1263,5 +1450,5 @@
  *****************************************************************************/
 
-DWORD HMDeviceHandler::OpenProcessToken(PHMHANDLEDATA pHMHandleData, 
+DWORD HMDeviceHandler::OpenProcessToken(PHMHANDLEDATA pHMHandleData,
                                         DWORD dwUserData,
                                         HANDLE  ProcessHandle)
@@ -1275,7 +1462,7 @@
 /*****************************************************************************
  * Name      : DWORD HMDeviceHandler::CreateThread
- * Purpose   : 
- * Variables :
- * Result    : 
+ * Purpose   :
+ * Variables :
+ * Result    :
  * Remark    :
  * Status    :
@@ -1289,5 +1476,5 @@
                                      LPVOID                 lpvThreadParm,
                                      DWORD                  fdwCreate,
-                                     LPDWORD                lpIDThread, 
+                                     LPDWORD                lpIDThread,
                                      BOOL                   fFirstThread)
 {
@@ -1299,7 +1486,7 @@
 /*****************************************************************************
  * Name      : DWORD HMDeviceHandler::GetThreadPriority
- * Purpose   : 
- * Variables :
- * Result    : 
+ * Purpose   :
+ * Variables :
+ * Result    :
  * Remark    :
  * Status    :
@@ -1316,7 +1503,7 @@
 /*****************************************************************************
  * Name      : DWORD HMDeviceHandler::SuspendThread
- * Purpose   : 
- * Variables :
- * Result    : 
+ * Purpose   :
+ * Variables :
+ * Result    :
  * Remark    :
  * Status    :
@@ -1333,7 +1520,7 @@
 /*****************************************************************************
  * Name      : DWORD HMDeviceHandler::SetThreadPriority
- * Purpose   : 
- * Variables :
- * Result    : 
+ * Purpose   :
+ * Variables :
+ * Result    :
  * Remark    :
  * Status    :
@@ -1350,7 +1537,7 @@
 /*****************************************************************************
  * Name      : DWORD HMDeviceHandler::GetThreadContext
- * Purpose   : 
- * Variables :
- * Result    : 
+ * Purpose   :
+ * Variables :
+ * Result    :
  * Remark    :
  * Status    :
@@ -1367,7 +1554,7 @@
 /*****************************************************************************
  * Name      : DWORD HMDeviceHandler::SetThreadContext
- * Purpose   : 
- * Variables :
- * Result    : 
+ * Purpose   :
+ * Variables :
+ * Result    :
  * Remark    :
  * Status    :
@@ -1384,7 +1571,7 @@
 /*****************************************************************************
  * Name      : DWORD HMDeviceHandler::TerminateThread
- * Purpose   : 
- * Variables :
- * Result    : 
+ * Purpose   :
+ * Variables :
+ * Result    :
  * Remark    :
  * Status    :
@@ -1401,7 +1588,7 @@
 /*****************************************************************************
  * Name      : DWORD HMDeviceHandler::ResumeThread
- * Purpose   : 
- * Variables :
- * Result    : 
+ * Purpose   :
+ * Variables :
+ * Result    :
  * Remark    :
  * Status    :
@@ -1418,7 +1605,7 @@
 /*****************************************************************************
  * Name      : DWORD HMDeviceHandler::GetExitCodeThread
- * Purpose   : 
- * Variables :
- * Result    : 
+ * Purpose   :
+ * Variables :
+ * Result    :
  * Remark    :
  * Status    :
@@ -1435,7 +1622,7 @@
 /*****************************************************************************
  * Name      : DWORD HMDeviceHandler::SetThreadTerminated
- * Purpose   : 
- * Variables :
- * Result    : 
+ * Purpose   :
+ * Variables :
+ * Result    :
  * Remark    :
  * Status    :
@@ -1450,7 +1637,7 @@
 /*****************************************************************************
  * Name      : DWORD HMDeviceHandler::PeekNamedPipe
- * Purpose   : 
- * Variables :
- * Result    : 
+ * Purpose   :
+ * Variables :
+ * Result    :
  * Remark    :
  * Status    :
@@ -1473,7 +1660,7 @@
 /*****************************************************************************
  * Name      : DWORD HMDeviceHandler::CreateNamedPipe
- * Purpose   : 
- * Variables :
- * Result    : 
+ * Purpose   :
+ * Variables :
+ * Result    :
  * Remark    :
  * Status    :
@@ -1482,10 +1669,10 @@
  *****************************************************************************/
 DWORD HMDeviceHandler::CreateNamedPipe(PHMHANDLEDATA pHMHandleData,
-                                         LPCTSTR lpName, 
-                                         DWORD  dwOpenMode, 
+                                         LPCTSTR lpName,
+                                         DWORD  dwOpenMode,
                                          DWORD  dwPipeMode,
-                                         DWORD  nMaxInstances, 
+                                         DWORD  nMaxInstances,
                                          DWORD  nOutBufferSize,
-                                         DWORD  nInBufferSize,  
+                                         DWORD  nInBufferSize,
                                          DWORD  nDefaultTimeOut,
                                          LPSECURITY_ATTRIBUTES lpSecurityAttributes)
@@ -1499,7 +1686,7 @@
 /*****************************************************************************
  * Name      : BOOL HMDeviceHandler::ConnectNamedPipe
- * Purpose   : 
- * Variables :
- * Result    : 
+ * Purpose   :
+ * Variables :
+ * Result    :
  * Remark    :
  * Status    :
@@ -1507,5 +1694,5 @@
  * Author    : Przemyslaw Dobrowolski
  *****************************************************************************/
-BOOL HMDeviceHandler::ConnectNamedPipe( PHMHANDLEDATA pHMHandleData, 
+BOOL HMDeviceHandler::ConnectNamedPipe( PHMHANDLEDATA pHMHandleData,
                                           LPOVERLAPPED lpOverlapped)
 {
@@ -1518,7 +1705,7 @@
 /*****************************************************************************
  * Name      : BOOL HMDeviceHandler::DisconnectNamedPipe
- * Purpose   : 
- * Variables :
- * Result    : 
+ * Purpose   :
+ * Variables :
+ * Result    :
  * Remark    :
  * Status    :
@@ -1536,7 +1723,7 @@
 /*****************************************************************************
  * Name      : BOOL HMDeviceHandler::GetNamedPipeHandleState
- * Purpose   : 
- * Variables :
- * Result    : 
+ * Purpose   :
+ * Variables :
+ * Result    :
  * Remark    :
  * Status    :
@@ -1560,7 +1747,7 @@
 /*****************************************************************************
  * Name      : BOOL HMDeviceHandler::GetNamedPipeInfo
- * Purpose   : 
- * Variables :
- * Result    : 
+ * Purpose   :
+ * Variables :
+ * Result    :
  * Remark    :
  * Status    :
@@ -1582,7 +1769,7 @@
 /*****************************************************************************
  * Name      : DWORD HMDeviceHandler::TransactNamedPipe
- * Purpose   : 
- * Variables :
- * Result    : 
+ * Purpose   :
+ * Variables :
+ * Result    :
  * Remark    :
  * Status    :
@@ -1606,7 +1793,7 @@
 /*****************************************************************************
  * Name      : BOOL HMDeviceHandler::SetNamedPipeHandleState
- * Purpose   : 
- * Variables :
- * Result    : 
+ * Purpose   :
+ * Variables :
+ * Result    :
  * Remark    :
  * Status    :
@@ -1627,7 +1814,7 @@
 /*****************************************************************************
  * Name      : BOOL HMDeviceHandler::CreatePipe
- * Purpose   : 
- * Variables :
- * Result    : 
+ * Purpose   :
+ * Variables :
+ * Result    :
  * Remark    :
  * Status    :
@@ -1637,7 +1824,7 @@
 BOOL HMDeviceHandler::CreatePipe(PHMHANDLEDATA pHMHandleDataRead,
                                  PHMHANDLEDATA pHMHandleDataWrite,
-                                 LPSECURITY_ATTRIBUTES lpsa, 
+                                 LPSECURITY_ATTRIBUTES lpsa,
                                  DWORD         cbPipe)
-{ 
+{
   dprintf(("KERNEL32: ERROR: HandleManager::DeviceHandler::CreatePipe (%08x,%08x)\n",
            pHMHandleDataRead->hHMHandle,pHMHandleDataWrite->hHMHandle));
Index: trunk/src/kernel32/hmdevice.h
===================================================================
--- trunk/src/kernel32/hmdevice.h	(revision 4280)
+++ trunk/src/kernel32/hmdevice.h	(revision 4285)
@@ -1,3 +1,3 @@
-/* $Id: hmdevice.h,v 1.22 2000-08-04 21:12:07 sandervl Exp $ */
+/* $Id: hmdevice.h,v 1.23 2000-09-20 21:32:54 hugh Exp $ */
 
 /*
@@ -25,9 +25,9 @@
  *****************************************************************************/
 
-#define HMTYPE_UNKNOWN		0
-#define HMTYPE_MEMMAP		1
-#define HMTYPE_DEVICE   	2
-#define HMTYPE_PROCESSTOKEN 	3
-#define HMTYPE_THREADTOKEN 	4
+#define HMTYPE_UNKNOWN    0
+#define HMTYPE_MEMMAP   1
+#define HMTYPE_DEVICE     2
+#define HMTYPE_PROCESSTOKEN   3
+#define HMTYPE_THREADTOKEN  4
 #define HMTYPE_THREAD           5
 #define HMTYPE_PIPE             6
@@ -53,4 +53,5 @@
 
   LPVOID          lpHandlerData;    /* for private use of the device handler */
+  LPVOID          lpDeviceData;
 } HMHANDLEDATA, *PHMHANDLEDATA;
 
@@ -289,9 +290,9 @@
                                      DWORD                      dwMaximumSizeLow,
                                      LPCSTR                     lpName,
-   				     HFILE                     *hOldMap);
+               HFILE                     *hOldMap);
 
                   /* this is a handler method for calls to OpenFileMapping() */
   virtual DWORD OpenFileMapping     (PHMHANDLEDATA              pHMHandleData,
-		                     DWORD access,   /* [in] Access mode */
+                         DWORD access,   /* [in] Access mode */
                                      BOOL                       fInherit,
                                      LPCSTR                     lpName);
@@ -303,5 +304,5 @@
                                      DWORD                      dwFileOffsetLow,
                                      DWORD                      dwNumberOfBytesToMap,
-			             LPVOID                     lpBaseAddress);
+                   LPVOID                     lpBaseAddress);
 
                     /* this is a handler method for calls to DeviceIoControl() */
@@ -312,9 +313,53 @@
 
  /* COM ports */
- virtual BOOL SetupComm(PHMHANDLEDATA pHMHandleData, DWORD dwInQueue, DWORD dwOutQueue);
-
- virtual BOOL GetCommState(PHMHANDLEDATA pHMHandleData, LPDCB lpdcb);
-
- virtual DWORD  OpenThreadToken(PHMHANDLEDATA pHMHandleData, 
+ virtual BOOL SetupComm( PHMHANDLEDATA pHMHandleData,
+                         DWORD dwInQueue,
+                         DWORD dwOutQueue);
+
+ virtual BOOL GetCommState( PHMHANDLEDATA pHMHandleData,
+                            LPDCB lpdcb);
+ virtual BOOL WaitCommEvent( PHMHANDLEDATA pHMHandleData,
+                             LPDWORD lpfdwEvtMask,
+                             LPOVERLAPPED lpo);
+
+ virtual BOOL GetCommProperties( PHMHANDLEDATA pHMHandleData,
+                                 LPCOMMPROP lpcmmp);
+ virtual BOOL GetCommMask( PHMHANDLEDATA pHMHandleData,
+                           LPDWORD lpfdwEvtMask);
+ virtual BOOL SetCommMask( PHMHANDLEDATA pHMHandleData,
+                           DWORD fdwEvtMask);
+ virtual BOOL PurgeComm( PHMHANDLEDATA pHMHandleData,
+                         DWORD fdwAction);
+ virtual BOOL ClearCommError( PHMHANDLEDATA pHMHandleData,
+                              LPDWORD lpdwErrors,
+                              LPCOMSTAT lpcst);
+ virtual BOOL SetCommState( PHMHANDLEDATA pHMHandleData,
+                            LPDCB lpdcb) ;
+ virtual BOOL GetCommModemStatus( PHMHANDLEDATA pHMHandleData,
+                               LPDWORD lpModemStat );
+ virtual BOOL GetCommTimeouts( PHMHANDLEDATA pHMHandleData,
+                               LPCOMMTIMEOUTS lpctmo);
+ virtual BOOL SetCommTimeouts( PHMHANDLEDATA pHMHandleData,
+                               LPCOMMTIMEOUTS lpctmo);
+ virtual BOOL TransmitCommChar( PHMHANDLEDATA pHMHandleData,
+                                CHAR cChar );
+ virtual BOOL SetCommConfig( PHMHANDLEDATA pHMHandleData,
+                             LPCOMMCONFIG lpCC,
+                             DWORD dwSize );
+ virtual BOOL SetCommBreak( PHMHANDLEDATA pHMHandleData );
+ virtual BOOL GetCommConfig( PHMHANDLEDATA pHMHandleData,
+                             LPCOMMCONFIG lpCC,
+                             LPDWORD lpdwSize );
+ virtual BOOL EscapeCommFunction( PHMHANDLEDATA pHMHandleData,
+                                  UINT dwFunc );
+ virtual BOOL ClearCommBreak( PHMHANDLEDATA pHMHandleData);
+ virtual BOOL SetDefaultCommConfig( PHMHANDLEDATA pHMHandleData,
+                                    LPCOMMCONFIG lpCC,
+                                    DWORD dwSize);
+ virtual BOOL GetDefaultCommConfig( PHMHANDLEDATA pHMHandleData,
+                                    LPCOMMCONFIG lpCC,
+                                    LPDWORD lpdwSize);
+
+ virtual DWORD  OpenThreadToken(PHMHANDLEDATA pHMHandleData,
                                  HANDLE  ThreadHandle,
                                  BOOL    OpenAsSelf);
@@ -329,5 +374,5 @@
                              LPVOID                 lpvThreadParm,
                              DWORD                  fdwCreate,
-                             LPDWORD                lpIDThread, 
+                             LPDWORD                lpIDThread,
                              BOOL                   fFirstThread);
 
@@ -392,5 +437,5 @@
   virtual BOOL  CreatePipe(PHMHANDLEDATA pHMHandleDataRead,
                            PHMHANDLEDATA pHMHandleDataWrite,
-                           LPSECURITY_ATTRIBUTES lpsa, 
+                           LPSECURITY_ATTRIBUTES lpsa,
                            DWORD         cbPipe);
 
@@ -406,4 +451,7 @@
                         HMDeviceHandler *pDeviceHandler);
 
+DWORD  HMDeviceRegisterEx(LPSTR           pszDeviceName,
+                          HMDeviceHandler *pDeviceHandler,
+                          VOID            *pDevData);
 
 #endif /* _HM_DEVICE_H_ */
Index: trunk/src/kernel32/hmdevio.cpp
===================================================================
--- trunk/src/kernel32/hmdevio.cpp	(revision 4280)
+++ trunk/src/kernel32/hmdevio.cpp	(revision 4285)
@@ -1,3 +1,3 @@
-/* $Id: hmdevio.cpp,v 1.4 2000-03-04 19:52:36 sandervl Exp $ */
+/* $Id: hmdevio.cpp,v 1.5 2000-09-20 21:32:52 hugh Exp $ */
 
 /*
@@ -18,5 +18,5 @@
 #define INCL_DOSPROCESS          /* DOS Process values       */
 #define INCL_DOSMISC             /* DOS Miscellanous values  */
-#include <os2wrap.h>	//Odin32 OS/2 api wrappers
+#include <os2wrap.h>  //Odin32 OS/2 api wrappers
 #include <string.h>
 
@@ -28,11 +28,11 @@
 #include "exceptutil.h"
 
-#define DBG_LOCALLOG	DBG_hmdevio
+#define DBG_LOCALLOG  DBG_hmdevio
 #include "dbglocal.h"
 
 static fX86Init  = FALSE;
 //SvL: Used in iccio.asm (how can you put these in the .asm data segment without messing things up?)
-ULONG  ioentry   = 0;
-USHORT gdt       = 0;
+//ULONG  ioentry   = 0;
+//USHORT gdt       = 0;
 char   devname[] = "/dev/fastio$";
 
@@ -42,5 +42,5 @@
 
 static WIN32DRV knownDriver[] =
-    {{"\\\\.\\GpdDev", "",      TRUE,  666,   GpdDevIOCtl},
+    {{"\\\\.\\GpdDev", "/dev/fastio$", TRUE,  666,   GpdDevIOCtl},
     { "\\\\.\\MAPMEM", "PMAP$", FALSE, 0,     MAPMEMIOCtl},
     { "FXMEMMAP.VXD",  "PMAP$", FALSE, 0,     FXMEMMAPIOCtl}};
@@ -55,15 +55,15 @@
  DWORD rc;
 
-    for(int i=0;i<nrKnownDrivers;i++) 
+    for(int i=0;i<nrKnownDrivers;i++)
     {
-	driver = new HMDeviceDriver(knownDriver[i].szWin32Name,
+  driver = new HMDeviceDriver(knownDriver[i].szWin32Name,
                                     knownDriver[i].szOS2Name,
                                     knownDriver[i].fCreateFile,
                                     knownDriver[i].devIOCtl);
 
-	rc = HMDeviceRegister(knownDriver[i].szWin32Name, driver);
-    	if (rc != NO_ERROR)                                  /* check for errors */
-      		dprintf(("KERNEL32:RegisterDevices: registering %s failed with %u.\n",
-              		  knownDriver[i].szWin32Name, rc));
+  rc = HMDeviceRegister(knownDriver[i].szWin32Name, driver);
+      if (rc != NO_ERROR)                                  /* check for errors */
+          dprintf(("KERNEL32:RegisterDevices: registering %s failed with %u.\n",
+                    knownDriver[i].szWin32Name, rc));
     }
     return;
@@ -71,5 +71,5 @@
 //******************************************************************************
 //******************************************************************************
-HMDeviceDriver::HMDeviceDriver(LPCSTR lpDeviceName, LPSTR lpOS2DevName, BOOL fCreate, 
+HMDeviceDriver::HMDeviceDriver(LPCSTR lpDeviceName, LPSTR lpOS2DevName, BOOL fCreate,
                                WINIOCTL pDevIOCtl)
                 : HMDeviceKernelObjectClass(lpDeviceName)
@@ -110,17 +110,17 @@
 
   if(szOS2Name[0] == 0) {
-     	pHMHandleData->hHMHandle = 0;
-     	return (NO_ERROR);
+      pHMHandleData->hHMHandle = 0;
+      return (NO_ERROR);
   }
 
 tryopen:
-  rc = DosOpen(	szOS2Name,                        /* File path name */
-               	&hfFileHandle,                  /* File handle */
-               	&ulAction,                      /* Action taken */
-	       	0,
-         	FILE_NORMAL,
-           	FILE_OPEN,
-           	sharetype,
-               	0L);                            /* No extended attribute */
+  rc = DosOpen( szOS2Name,                        /* File path name */
+                &hfFileHandle,                  /* File handle */
+                &ulAction,                      /* Action taken */
+          0,
+          FILE_NORMAL,
+            FILE_OPEN,
+            sharetype,
+                0L);                            /* No extended attribute */
 
   if(rc == ERROR_TOO_MANY_OPEN_FILES) {
@@ -128,20 +128,22 @@
    LONG  ReqCount = 32;
 
-	rc = DosSetRelMaxFH(&ReqCount, &CurMaxFH);
-	if(rc) {
-		dprintf(("DosSetRelMaxFH returned %d", rc));
-		return rc;
-	}
-	dprintf(("DosOpen failed -> increased nr open files to %d", CurMaxFH));
-	goto tryopen;
+  rc = DosSetRelMaxFH(&ReqCount, &CurMaxFH);
+  if(rc) {
+    dprintf(("DosSetRelMaxFH returned %d", rc));
+    return rc;
+  }
+  dprintf(("DosOpen failed -> increased nr open files to %d", CurMaxFH));
+  goto tryopen;
   }
 
   dprintf(("DosOpen %s returned %d\n", szOS2Name, rc));
 
-  if(rc == NO_ERROR) {
-     	pHMHandleData->hHMHandle = hfFileHandle;
-     	return (NO_ERROR);
-  }
-  else  return(rc);
+  if(rc == NO_ERROR)
+  {
+    pHMHandleData->hHMHandle = hfFileHandle;
+    return (NO_ERROR);
+  }
+  else
+    return(rc);
 }
 //******************************************************************************
@@ -166,9 +168,18 @@
 {
  ULONG port, val = 0;
-
-  if(fX86Init == FALSE) {
-    	if(io_init() == 0)
-        	fX86Init = TRUE;
-    	else   	return(FALSE);
+ WORD  gdt;
+ HRESULT rc;
+ ULONG ulAction;
+
+  if(fX86Init == FALSE)
+  {
+    rc = DosDevIOCtl( hDevice, 118, 100, 0,0,0,&gdt,2,&ulAction);
+
+    if(rc)
+      return FALSE;
+
+    io_init2(gdt);
+
+    fX86Init = TRUE;
   }
 
@@ -298,6 +309,6 @@
   rc = DosTmrQueryTime(&time);
   if(rc) {
-    	dprintf(("DosTmrQueryTime returned %d\n", rc));
-    	return(FALSE);
+      dprintf(("DosTmrQueryTime returned %d\n", rc));
+      return(FALSE);
   }
   lpPerformanceCount->u.LowPart  = time.ulLo;
@@ -314,6 +325,6 @@
   rc = DosTmrQueryFreq(&freq);
   if(rc) {
-    	dprintf(("DosTmrQueryFreq returned %d\n", rc));
-    	return(FALSE);
+      dprintf(("DosTmrQueryFreq returned %d\n", rc));
+      return(FALSE);
   }
   lpFrequency->u.LowPart  = freq;
Index: trunk/src/kernel32/hmopen32.cpp
===================================================================
--- trunk/src/kernel32/hmopen32.cpp	(revision 4280)
+++ trunk/src/kernel32/hmopen32.cpp	(revision 4285)
@@ -1,3 +1,3 @@
-/* $Id: hmopen32.cpp,v 1.25 2000-08-04 21:12:08 sandervl Exp $ */
+/* $Id: hmopen32.cpp,v 1.26 2000-09-20 21:32:52 hugh Exp $ */
 
 /*
@@ -12,5 +12,5 @@
  */
 
-//#define DEBUG_LOCAL
+#define DEBUG_LOCAL
 
 #ifdef DEBUG_LOCAL
@@ -31,5 +31,5 @@
 #include "mmap.h"
 
-#define DBG_LOCALLOG	DBG_hmopen32
+#define DBG_LOCALLOG  DBG_hmopen32
 #include "dbglocal.h"
 
@@ -101,5 +101,5 @@
  * Name      : HMDeviceHandler::DuplicateHandle
  * Purpose   : dummy version
- * Parameters: 
+ * Parameters:
  *             various parameters as required
  * Variables :
@@ -115,6 +115,6 @@
                                HANDLE  destprocess,
                                PHANDLE desthandle,
-                       	       DWORD   fdwAccess,
-                       	       BOOL    fInherit,
+                               DWORD   fdwAccess,
+                               BOOL    fInherit,
                                DWORD   fdwOptions,
                                DWORD   fdwOdinOptions)
@@ -130,6 +130,6 @@
 
   if(rc == TRUE) {
-     	pHMHandleData->hHMHandle = *desthandle;
-     	return TRUE;
+      pHMHandleData->hHMHandle = *desthandle;
+      return TRUE;
   }
   else  return FALSE;
@@ -205,13 +205,13 @@
             pHMHandleData->hHMHandle,
             dwTimeout));
- 
+
   if(dwTimeout) {
-  	starttime = O32_GetCurrentTime();
+    starttime = O32_GetCurrentTime();
   }
   rc =  (O32_WaitForSingleObject(pHMHandleData->hHMHandle,
                                  dwTimeout));
   if(dwTimeout) {
-  	endtime = O32_GetCurrentTime();
-  	dprintf(("KERNEL32: HandleManager::WaitForSingleObject %x delta = %x (rc=%x)", pHMHandleData->hHMHandle, endtime - starttime, rc));
+    endtime = O32_GetCurrentTime();
+    dprintf(("KERNEL32: HandleManager::WaitForSingleObject %x delta = %x (rc=%x)", pHMHandleData->hHMHandle, endtime - starttime, rc));
   }
   else dprintf(("KERNEL32: HandleManager::WaitForSingleObject %x rc=%x", pHMHandleData->hHMHandle, rc));
Index: trunk/src/kernel32/oslibdos.cpp
===================================================================
--- trunk/src/kernel32/oslibdos.cpp	(revision 4280)
+++ trunk/src/kernel32/oslibdos.cpp	(revision 4285)
@@ -1,3 +1,3 @@
-/* $Id: oslibdos.cpp,v 1.42 2000-09-13 21:11:00 sandervl Exp $ */
+/* $Id: oslibdos.cpp,v 1.43 2000-09-20 21:32:53 hugh Exp $ */
 /*
  * Wrappers for OS/2 Dos* API
@@ -45,14 +45,14 @@
 
   if(DosQueryModuleHandle("DOSCALLS", &hDoscalls) != NO_ERROR) {
-	return;
+  return;
   }
   if(DosQueryProcAddr(hDoscalls, 989, NULL, (PFN *)&DosSetFileSizeLProc) != NO_ERROR) {
-	return;
+  return;
   }
   if(DosQueryProcAddr(hDoscalls, 988, NULL, (PFN *)&DosSetFilePtrLProc) != NO_ERROR) {
-	return;
+  return;
   }
   if(DosQueryProcAddr(hDoscalls, 986, NULL, (PFN *)&DosSetFileLocksLProc) != NO_ERROR) {
-	return;
+  return;
   }
   f64BitIO = TRUE;
@@ -104,5 +104,5 @@
   {
     case NO_ERROR: //0
-      	return ERROR_SUCCESS_W;
+        return ERROR_SUCCESS_W;
 
     case ERROR_INVALID_FUNCTION: //1
@@ -110,29 +110,29 @@
 
     case ERROR_FILE_NOT_FOUND: //2
-      	return ERROR_FILE_NOT_FOUND_W;
+        return ERROR_FILE_NOT_FOUND_W;
 
     case ERROR_PATH_NOT_FOUND: //3
-      	return ERROR_PATH_NOT_FOUND_W;
+        return ERROR_PATH_NOT_FOUND_W;
 
     case ERROR_TOO_MANY_OPEN_FILES: //4
-      	return ERROR_TOO_MANY_OPEN_FILES_W;
+        return ERROR_TOO_MANY_OPEN_FILES_W;
 
     case ERROR_ACCESS_DENIED: //5
-      	return ERROR_ACCESS_DENIED_W;
+        return ERROR_ACCESS_DENIED_W;
 
     case ERROR_INVALID_HANDLE: //6
-      	return ERROR_INVALID_HANDLE_W;
+        return ERROR_INVALID_HANDLE_W;
 
     case ERROR_NOT_ENOUGH_MEMORY: //8
-      	return ERROR_NOT_ENOUGH_MEMORY_W;
+        return ERROR_NOT_ENOUGH_MEMORY_W;
 
     case ERROR_BAD_FORMAT: //11
-      	return ERROR_BAD_FORMAT_W;
+        return ERROR_BAD_FORMAT_W;
 
     case ERROR_INVALID_ACCESS: //12
-     	return ERROR_INVALID_ACCESS_W;
+      return ERROR_INVALID_ACCESS_W;
 
     case ERROR_NO_MORE_FILES: //18
-      	return ERROR_NO_MORE_FILES_W;
+        return ERROR_NO_MORE_FILES_W;
 
     case ERROR_WRITE_PROTECT: //19
@@ -140,5 +140,5 @@
 
     case ERROR_NOT_DOS_DISK: //26
-      	return ERROR_NOT_DOS_DISK_W;
+        return ERROR_NOT_DOS_DISK_W;
 
     case ERROR_WRITE_FAULT: //29
@@ -146,11 +146,11 @@
 
     case ERROR_SHARING_VIOLATION: //32
-       	return ERROR_SHARING_VIOLATION_W;
+        return ERROR_SHARING_VIOLATION_W;
 
     case ERROR_LOCK_VIOLATION: //32
-       	return ERROR_LOCK_VIOLATION_W;
+        return ERROR_LOCK_VIOLATION_W;
 
     case ERROR_SHARING_BUFFER_EXCEEDED: //36
-       	return ERROR_SHARING_BUFFER_EXCEEDED_W;
+        return ERROR_SHARING_BUFFER_EXCEEDED_W;
 
     case ERROR_CANNOT_MAKE: //82
@@ -158,35 +158,35 @@
 
     case ERROR_OUT_OF_STRUCTURES: //84
-      	return ERROR_OUT_OF_STRUCTURES_W;
+        return ERROR_OUT_OF_STRUCTURES_W;
 
     case ERROR_INVALID_PARAMETER: //87
-      	return ERROR_INVALID_PARAMETER_W;
+        return ERROR_INVALID_PARAMETER_W;
 
     case ERROR_INTERRUPT: //95
-      	return ERROR_INVALID_AT_INTERRUPT_TIME_W; //CB: right???
+        return ERROR_INVALID_AT_INTERRUPT_TIME_W; //CB: right???
 
     case ERROR_DEVICE_IN_USE: //99
-	return ERROR_DEVICE_IN_USE_W;
+  return ERROR_DEVICE_IN_USE_W;
 
     case ERROR_DRIVE_LOCKED: //108
-      	return ERROR_DRIVE_LOCKED_W;
+        return ERROR_DRIVE_LOCKED_W;
 
     case ERROR_BROKEN_PIPE: //109
-      	return ERROR_BROKEN_PIPE_W;
+        return ERROR_BROKEN_PIPE_W;
 
     case ERROR_OPEN_FAILED: //110
-	return ERROR_OPEN_FAILED_W;
+  return ERROR_OPEN_FAILED_W;
 
     case ERROR_BUFFER_OVERFLOW: //111
-      	return ERROR_BUFFER_OVERFLOW_W;
+        return ERROR_BUFFER_OVERFLOW_W;
 
     case ERROR_DISK_FULL: //112
-	return ERROR_DISK_FULL_W;
+  return ERROR_DISK_FULL_W;
 
     case ERROR_NO_MORE_SEARCH_HANDLES: //113
-      	return ERROR_NO_MORE_SEARCH_HANDLES_W;
+        return ERROR_NO_MORE_SEARCH_HANDLES_W;
 
     case ERROR_SEM_TIMEOUT: //121
-      	return ERROR_SEM_TIMEOUT_W;
+        return ERROR_SEM_TIMEOUT_W;
 
     case ERROR_DIRECT_ACCESS_HANDLE: //130
@@ -200,39 +200,39 @@
 
     case ERROR_DISCARDED: //157
-      	return ERROR_DISCARDED_W;
+        return ERROR_DISCARDED_W;
 
     case ERROR_FILENAME_EXCED_RANGE: //206
-      	return ERROR_FILENAME_EXCED_RANGE_W;
+        return ERROR_FILENAME_EXCED_RANGE_W;
 
     case ERROR_META_EXPANSION_TOO_LONG: //208
-      	return ERROR_META_EXPANSION_TOO_LONG_W;
+        return ERROR_META_EXPANSION_TOO_LONG_W;
 
     case ERROR_BAD_PIPE: //230
-      	return ERROR_BAD_PIPE_W;
+        return ERROR_BAD_PIPE_W;
 
     case ERROR_PIPE_BUSY: //231
-      	return ERROR_PIPE_BUSY_W;
+        return ERROR_PIPE_BUSY_W;
 
     case ERROR_NO_DATA: //232
-      	return ERROR_NO_DATA_W;
+        return ERROR_NO_DATA_W;
 
     case ERROR_PIPE_NOT_CONNECTED: //233
-      	return ERROR_PIPE_NOT_CONNECTED_W;
+        return ERROR_PIPE_NOT_CONNECTED_W;
 
     case ERROR_MORE_DATA: //234
-      	return ERROR_MORE_DATA_W;
+        return ERROR_MORE_DATA_W;
 
     case ERROR_INVALID_EA_NAME: //254
-      	return ERROR_INVALID_EA_NAME_W;
+        return ERROR_INVALID_EA_NAME_W;
 
     case ERROR_EA_LIST_INCONSISTENT: //255
-      	return ERROR_EA_LIST_INCONSISTENT_W;
+        return ERROR_EA_LIST_INCONSISTENT_W;
 
     case ERROR_EAS_DIDNT_FIT: //275
-      	return ERROR_EAS_DIDNT_FIT;
+        return ERROR_EAS_DIDNT_FIT;
 
     default:
-    	dprintf(("WARNING: error2WinError: error %d not included!!!!", rc));
-      	return defaultCode;
+      dprintf(("WARNING: error2WinError: error %d not included!!!!", rc));
+        return defaultCode;
   }
 }
@@ -554,6 +554,6 @@
   rc = DosDelete(lpszFileName);
   if(rc) {
-	SetLastError(error2WinError(rc));	
-	return FALSE;
+  SetLastError(error2WinError(rc));
+  return FALSE;
   }
   return TRUE;
@@ -660,5 +660,5 @@
         }
         strncpy(full_name, name, length_fullname);
-	full_name[length_fullname-1] = 0;
+  full_name[length_fullname-1] = 0;
         return strlen(full_name);
   }
@@ -697,9 +697,9 @@
    if(rc == ERROR_TOO_MANY_OPEN_FILES)
    {
-      	LONG  reqCount = 2;
-      	ULONG maxFiles;
-
-      	if(DosSetRelMaxFH(&reqCount, &maxFiles) == NO_ERROR)
-         	rc = DosQueryPathInfo(pszPathName, ulInfoLevel,
+        LONG  reqCount = 2;
+        ULONG maxFiles;
+
+        if(DosSetRelMaxFH(&reqCount, &maxFiles) == NO_ERROR)
+          rc = DosQueryPathInfo(pszPathName, ulInfoLevel,
                                       pInfoBuf, cbInfoBuf );
    }
@@ -727,5 +727,5 @@
 
    if(fuAttrFlags & FILE_ATTRIBUTE_ARCHIVE_W)
-      	fileAttr |= FILE_ARCHIVED;
+        fileAttr |= FILE_ARCHIVED;
    if(fuAttrFlags & FILE_ATTRIBUTE_HIDDEN_W)
         fileAttr |= FILE_HIDDEN;
@@ -739,5 +739,5 @@
    {
    case CREATE_NEW_W:
-	openFlag |= OPEN_ACTION_CREATE_IF_NEW | OPEN_ACTION_FAIL_IF_EXISTS;
+  openFlag |= OPEN_ACTION_CREATE_IF_NEW | OPEN_ACTION_FAIL_IF_EXISTS;
         break;
    case CREATE_ALWAYS_W:
@@ -764,8 +764,8 @@
    //TODO: FILE_SHARE_DELETE
    if((fuShare & (FILE_SHARE_READ_W | FILE_SHARE_WRITE_W)) == 0 )
-	openMode |= OPEN_SHARE_DENYREADWRITE;
+  openMode |= OPEN_SHARE_DENYREADWRITE;
    else
    if((fuShare & (FILE_SHARE_READ_W | FILE_SHARE_WRITE_W)) == (FILE_SHARE_READ_W | FILE_SHARE_WRITE_W))
-      	openMode |= OPEN_SHARE_DENYNONE;
+        openMode |= OPEN_SHARE_DENYNONE;
    else
    if(fuShare & FILE_SHARE_READ_W)
@@ -773,14 +773,14 @@
    else
    if(fuShare & FILE_SHARE_WRITE_W)
- 	openMode |= OPEN_SHARE_DENYREAD;
+  openMode |= OPEN_SHARE_DENYREAD;
 
    if(fuAccess == (GENERIC_READ_W | GENERIC_WRITE_W))
-	openMode |= OPEN_ACCESS_READWRITE;
+  openMode |= OPEN_ACCESS_READWRITE;
    else
    if(fuAccess & GENERIC_READ_W)
-	openMode |= OPEN_ACCESS_READONLY;
+  openMode |= OPEN_ACCESS_READONLY;
    else
    if(fuAccess & GENERIC_WRITE_W)
-       	openMode |= OPEN_ACCESS_WRITEONLY;
+        openMode |= OPEN_ACCESS_WRITEONLY;
 
 #if 0
@@ -799,6 +799,6 @@
 
    if(strlen(lpszFile) == 2 && lpszFile[1] == ':') {
-	//app tries to open physical disk
-	openMode |= OPEN_FLAGS_DASD;
+  //app tries to open physical disk
+  openMode |= OPEN_FLAGS_DASD;
    }
    int retry = 0;
@@ -814,19 +814,19 @@
                       openMode,
                       NULL);
-  	if(rc == ERROR_TOO_MANY_OPEN_FILES)
+    if(rc == ERROR_TOO_MANY_OPEN_FILES)
         {
-   	  ULONG CurMaxFH;
-   	  LONG  ReqCount = 32;
-
-		rc = DosSetRelMaxFH(&ReqCount, &CurMaxFH);
-		if(rc) {
-			dprintf(("DosSetRelMaxFH returned %d", rc));
-			SetLastError(ERROR_TOO_MANY_OPEN_FILES_W);
-			return INVALID_HANDLE_VALUE_W;
-		}
-		dprintf(("DosOpen failed -> increased nr open files to %d", CurMaxFH));
-  	}
-	else	break;
-	retry++;
+      ULONG CurMaxFH;
+      LONG  ReqCount = 32;
+
+    rc = DosSetRelMaxFH(&ReqCount, &CurMaxFH);
+    if(rc) {
+      dprintf(("DosSetRelMaxFH returned %d", rc));
+      SetLastError(ERROR_TOO_MANY_OPEN_FILES_W);
+      return INVALID_HANDLE_VALUE_W;
+    }
+    dprintf(("DosOpen failed -> increased nr open files to %d", CurMaxFH));
+    }
+  else  break;
+  retry++;
    }
 
@@ -853,37 +853,37 @@
    if(!(fuMode & (OF_CREATE_W | OF_READWRITE_W | OF_WRITE_W)))
    {
-      	openMode |= OPEN_ACCESS_READONLY;
-      	openFlag |= OPEN_ACTION_OPEN_IF_EXISTS;
+        openMode |= OPEN_ACCESS_READONLY;
+        openFlag |= OPEN_ACTION_OPEN_IF_EXISTS;
    }
    else
    {
-       	if(fuMode & OF_CREATE_W) {
-          	openFlag |= OPEN_ACTION_CREATE_IF_NEW |
+        if(fuMode & OF_CREATE_W) {
+            openFlag |= OPEN_ACTION_CREATE_IF_NEW |
                             OPEN_ACTION_REPLACE_IF_EXISTS;
-	}
-       	else    openFlag |= OPEN_ACTION_OPEN_IF_EXISTS;                                //180575
-
-       	if(fuMode & OF_READWRITE_W)
-          	openMode |= OPEN_ACCESS_READWRITE;
-       	else
-	if(fuMode & OF_WRITE_W)
-          	openMode |= OPEN_ACCESS_WRITEONLY;
-       	else
-	if(fuMode & OF_CREATE_W)
-          	openMode |= OPEN_ACCESS_READWRITE;
+  }
+        else    openFlag |= OPEN_ACTION_OPEN_IF_EXISTS;                                //180575
+
+        if(fuMode & OF_READWRITE_W)
+            openMode |= OPEN_ACCESS_READWRITE;
+        else
+  if(fuMode & OF_WRITE_W)
+            openMode |= OPEN_ACCESS_WRITEONLY;
+        else
+  if(fuMode & OF_CREATE_W)
+            openMode |= OPEN_ACCESS_READWRITE;
    }
 
    if((fuMode & OF_SHARE_DENY_WRITE_W) ||
       !(fuMode & (OF_SHARE_DENY_READ_W | OF_SHARE_DENY_NONE_W | OF_SHARE_EXCLUSIVE_W)))
-      	openMode |= OPEN_SHARE_DENYWRITE;
+        openMode |= OPEN_SHARE_DENYWRITE;
    else
    if (fuMode & OF_SHARE_DENY_NONE_W)
-      	openMode |= OPEN_SHARE_DENYNONE;
+        openMode |= OPEN_SHARE_DENYNONE;
    else
    if (fuMode & OF_SHARE_DENY_READ_W)
-      	openMode |= OPEN_SHARE_DENYREAD;
+        openMode |= OPEN_SHARE_DENYREAD;
    else
    if (fuMode & OF_SHARE_EXCLUSIVE_W)
-      	openMode |= OPEN_SHARE_DENYREADWRITE;
+        openMode |= OPEN_SHARE_DENYREADWRITE;
 
    rc = DosOpen((PSZ)lpszFile,
@@ -898,19 +898,19 @@
    if(rc != NO_ERROR)
    {
-       	if(fuMode & OF_EXIST_W)
-       	{
-          	if(rc == ERROR_OPEN_FAILED || rc == ERROR_FILE_NOT_FOUND)
-          	{
-             		SetLastError(ERROR_FILE_NOT_FOUND_W);
-             		return HFILE_ERROR_W;
-          	}
-       	}
-      	if((rc == ERROR_OPEN_FAILED) && (openFlag & OPEN_ACTION_OPEN_IF_EXISTS))
-      	{
-          	SetLastError(ERROR_FILE_NOT_FOUND_W);
-      	}
-      	else    SetLastError(error2WinError(rc));
-
-      	return HFILE_ERROR_W;
+        if(fuMode & OF_EXIST_W)
+        {
+            if(rc == ERROR_OPEN_FAILED || rc == ERROR_FILE_NOT_FOUND)
+            {
+                SetLastError(ERROR_FILE_NOT_FOUND_W);
+                return HFILE_ERROR_W;
+            }
+        }
+        if((rc == ERROR_OPEN_FAILED) && (openFlag & OPEN_ACTION_OPEN_IF_EXISTS))
+        {
+            SetLastError(ERROR_FILE_NOT_FOUND_W);
+        }
+        else    SetLastError(error2WinError(rc));
+
+        return HFILE_ERROR_W;
    }
    SetLastError(ERROR_SUCCESS_W);
@@ -930,5 +930,5 @@
 
    if(lpOverlapped) {//TODO:
-	dprintf(("OSLibDosLockFile: overlapped lock not yet implemented!!"));
+  dprintf(("OSLibDosLockFile: overlapped lock not yet implemented!!"));
    }
    //TODO: Locking region crossing end of file is permitted. Works in OS/2??
@@ -937,10 +937,10 @@
     FILELOCKL lockRangeL;
 
- 	lockRangeL.lOffset.ulLo = OffsetLow;
- 	lockRangeL.lOffset.ulHi = OffsetHigh;
- 	lockRangeL.lRange.ulLo  = nNumberOfBytesToLockLow;
- 	lockRangeL.lRange.ulHi  = nNumberOfBytesToLockHigh;
-
-   	rc = OdinDosSetFileLocksL(hFile, NULL, &lockRangeL,
+  lockRangeL.lOffset.ulLo = OffsetLow;
+  lockRangeL.lOffset.ulHi = OffsetHigh;
+  lockRangeL.lRange.ulLo  = nNumberOfBytesToLockLow;
+  lockRangeL.lRange.ulHi  = nNumberOfBytesToLockHigh;
+
+    rc = OdinDosSetFileLocksL(hFile, NULL, &lockRangeL,
                                   (dwFlags & LOCKFILE_FAIL_IMMEDIATELY_W) ? 0 : 5000, 0);
         //SvL: 64 bits values are only supported by JFS
@@ -948,5 +948,5 @@
         //     (TODO: should check the partition type instead)
         if(rc == ERROR_INVALID_PARAMETER && (OffsetHigh || nNumberOfBytesToLockHigh)) {
-		goto oldlock;
+    goto oldlock;
         }
    }
@@ -956,10 +956,10 @@
     FILELOCK lockRange = { OffsetLow, nNumberOfBytesToLockLow };
 
-   	rc = DosSetFileLocks(hFile, NULL, &lockRange,
+    rc = DosSetFileLocks(hFile, NULL, &lockRange,
                              (dwFlags & LOCKFILE_FAIL_IMMEDIATELY_W) ? 0 : 5000, 0);
    }
    if(rc) {
-   	SetLastError(error2WinError(rc));
-	return FALSE;
+    SetLastError(error2WinError(rc));
+  return FALSE;
    }
    SetLastError(ERROR_SUCCESS_W);
@@ -978,5 +978,5 @@
 
    if(lpOverlapped) {//TODO:
-	dprintf(("OSLibDosUnlockFile: overlapped unlock not yet implemented!!"));
+  dprintf(("OSLibDosUnlockFile: overlapped unlock not yet implemented!!"));
    }
    if(f64BitIO)
@@ -984,15 +984,15 @@
     FILELOCKL unlockRangeL;
 
- 	unlockRangeL.lOffset.ulLo = OffsetLow;
- 	unlockRangeL.lOffset.ulHi = OffsetHigh;
- 	unlockRangeL.lRange.ulLo  = nNumberOfBytesToLockLow;
- 	unlockRangeL.lRange.ulHi  = nNumberOfBytesToLockHigh;
-
-   	rc = OdinDosSetFileLocksL(hFile, &unlockRangeL, NULL, 5000, 0);
+  unlockRangeL.lOffset.ulLo = OffsetLow;
+  unlockRangeL.lOffset.ulHi = OffsetHigh;
+  unlockRangeL.lRange.ulLo  = nNumberOfBytesToLockLow;
+  unlockRangeL.lRange.ulHi  = nNumberOfBytesToLockHigh;
+
+    rc = OdinDosSetFileLocksL(hFile, &unlockRangeL, NULL, 5000, 0);
         //SvL: 64 bits values are only supported by JFS
         //     Try the 32 bits DosSetFileLocks if it fails
         //     (TODO: should check the partition type instead)
         if(rc == ERROR_INVALID_PARAMETER && (OffsetHigh || nNumberOfBytesToLockHigh)) {
-		goto oldlock;
+    goto oldlock;
         }
    }
@@ -1005,6 +1005,6 @@
    }
    if(rc) {
-   	SetLastError(error2WinError(rc));
-	return FALSE;
+    SetLastError(error2WinError(rc));
+  return FALSE;
    }
    SetLastError(ERROR_SUCCESS_W);
@@ -1033,9 +1033,9 @@
      ULONG        ulBufSize       = sizeof(FILESTATUS3L);
 
-   	rc = DosQueryFileInfo(hFile, FIL_STANDARDL, &fsts3ConfigInfoL, ulBufSize);
-   	if(lpdwFileSizeHigh) {
-  		*lpdwFileSizeHigh = fsts3ConfigInfoL.cbFile.ulHi;
-	}
-	sizeLow = fsts3ConfigInfoL.cbFile.ulLo;
+    rc = DosQueryFileInfo(hFile, FIL_STANDARDL, &fsts3ConfigInfoL, ulBufSize);
+    if(lpdwFileSizeHigh) {
+      *lpdwFileSizeHigh = fsts3ConfigInfoL.cbFile.ulHi;
+  }
+  sizeLow = fsts3ConfigInfoL.cbFile.ulLo;
    }
    else
@@ -1044,13 +1044,13 @@
      ULONG       ulBufSize       = sizeof(FILESTATUS3);
 
-   	if(lpdwFileSizeHigh) {
-  		*lpdwFileSizeHigh = 0;
-	}
-   	rc = DosQueryFileInfo(hFile, FIL_STANDARD, &fsts3ConfigInfo, ulBufSize);
-	sizeLow = fsts3ConfigInfo.cbFile;
+    if(lpdwFileSizeHigh) {
+      *lpdwFileSizeHigh = 0;
+  }
+    rc = DosQueryFileInfo(hFile, FIL_STANDARD, &fsts3ConfigInfo, ulBufSize);
+  sizeLow = fsts3ConfigInfo.cbFile;
    }
    if(rc) {
-   	SetLastError(error2WinError(rc));
-   	return -1;
+    SetLastError(error2WinError(rc));
+    return -1;
    }
    SetLastError(ERROR_SUCCESS_W);
@@ -1085,11 +1085,11 @@
   if( (f64BitIO) && (OffsetHigh) )
   {
-	offsetL.ulLo = OffsetLow;
-	offsetL.ulHi = (OffsetHigh) ? *OffsetHigh : 0;
-	rc = OdinDosSetFilePtrL(hFile, offsetL, method, &newoffsetL);
-	if(OffsetHigh) {
-		*OffsetHigh = newoffsetL.ulHi;
-	}
-	newoffset = newoffsetL.ulLo;
+  offsetL.ulLo = OffsetLow;
+  offsetL.ulHi = (OffsetHigh) ? *OffsetHigh : 0;
+  rc = OdinDosSetFilePtrL(hFile, offsetL, method, &newoffsetL);
+  if(OffsetHigh) {
+    *OffsetHigh = newoffsetL.ulHi;
+  }
+  newoffset = newoffsetL.ulLo;
    }
   else
@@ -1114,18 +1114,18 @@
 
    if(f64BitIO) {
-	rc = OdinDosSetFilePtrL(hFile, FilePosL, FILE_CURRENT, &newFilePosL);
-	if(rc == 0) {
-        	rc = OdinDosSetFileSizeL(hFile, newFilePosL);
-	}
+  rc = OdinDosSetFilePtrL(hFile, FilePosL, FILE_CURRENT, &newFilePosL);
+  if(rc == 0) {
+          rc = OdinDosSetFileSizeL(hFile, newFilePosL);
+  }
    }
    else {
-   	rc = DosSetFilePtr(hFile, 0, FILE_CURRENT, &newFilePos);
-	if(rc == 0) {
-        	rc = DosSetFileSize(hFile, newFilePos);
-	}
+    rc = DosSetFilePtr(hFile, 0, FILE_CURRENT, &newFilePos);
+  if(rc == 0) {
+          rc = DosSetFileSize(hFile, newFilePos);
+  }
    }
    if(rc) {
-   	SetLastError(error2WinError(rc));
-   	return FALSE;
+    SetLastError(error2WinError(rc));
+    return FALSE;
    }
    SetLastError(ERROR_SUCCESS_W);
@@ -1142,41 +1142,41 @@
      FILESTATUS4L statusL = { 0 };
 
-   	rc = DosQueryFileInfo(hFile,
-        	              FIL_QUERYEASIZEL,
-                	      &statusL,
+    rc = DosQueryFileInfo(hFile,
+                        FIL_QUERYEASIZEL,
+                        &statusL,
                               sizeof(statusL));
-   	if(rc == NO_ERROR)
-   	{
-	  	pInfo->dwFileAttributes = 0;
-		if(!(statusL.attrFile & NOT_NORMAL))
-		  	pInfo->dwFileAttributes |= FILE_ATTRIBUTE_NORMAL_W;
-		if(statusL.attrFile & FILE_READONLY)
-		        pInfo->dwFileAttributes |= FILE_ATTRIBUTE_READONLY_W;
-		if(statusL.attrFile & FILE_HIDDEN)
-		        pInfo->dwFileAttributes |= FILE_ATTRIBUTE_HIDDEN_W;
-		if(statusL.attrFile & FILE_SYSTEM)
-		        pInfo->dwFileAttributes |= FILE_ATTRIBUTE_SYSTEM_W;
-		if(statusL.attrFile & FILE_DIRECTORY)
-		        pInfo->dwFileAttributes |= FILE_ATTRIBUTE_DIRECTORY_W;
-		if(statusL.attrFile & FILE_ARCHIVED)
-		        pInfo->dwFileAttributes |= FILE_ATTRIBUTE_ARCHIVE_W;
-			
-		pmDateTimeToFileTime(&statusL.fdateCreation,
-	                             &statusL.ftimeCreation,
-	                             &pInfo->ftCreationTime);
-		pmDateTimeToFileTime(&statusL.fdateLastAccess,
-	                             &statusL.ftimeLastAccess,
-	                             &pInfo->ftLastAccessTime);
-		pmDateTimeToFileTime(&statusL.fdateLastWrite,
-	                             &statusL.ftimeLastWrite,
-	                             &pInfo->ftLastWriteTime);
-	
-		pInfo->nFileSizeHigh = statusL.cbFile.ulHi;
-		pInfo->nFileSizeLow  = statusL.cbFile.ulLo;
-		pInfo->dwVolumeSerialNumber = 0; //todo
-		pInfo->nNumberOfLinks = 1;
-		pInfo->nFileIndexHigh = 0;
-		pInfo->nFileIndexLow  = 0;
-	   }
+    if(rc == NO_ERROR)
+    {
+      pInfo->dwFileAttributes = 0;
+    if(!(statusL.attrFile & NOT_NORMAL))
+        pInfo->dwFileAttributes |= FILE_ATTRIBUTE_NORMAL_W;
+    if(statusL.attrFile & FILE_READONLY)
+            pInfo->dwFileAttributes |= FILE_ATTRIBUTE_READONLY_W;
+    if(statusL.attrFile & FILE_HIDDEN)
+            pInfo->dwFileAttributes |= FILE_ATTRIBUTE_HIDDEN_W;
+    if(statusL.attrFile & FILE_SYSTEM)
+            pInfo->dwFileAttributes |= FILE_ATTRIBUTE_SYSTEM_W;
+    if(statusL.attrFile & FILE_DIRECTORY)
+            pInfo->dwFileAttributes |= FILE_ATTRIBUTE_DIRECTORY_W;
+    if(statusL.attrFile & FILE_ARCHIVED)
+            pInfo->dwFileAttributes |= FILE_ATTRIBUTE_ARCHIVE_W;
+
+    pmDateTimeToFileTime(&statusL.fdateCreation,
+                               &statusL.ftimeCreation,
+                               &pInfo->ftCreationTime);
+    pmDateTimeToFileTime(&statusL.fdateLastAccess,
+                               &statusL.ftimeLastAccess,
+                               &pInfo->ftLastAccessTime);
+    pmDateTimeToFileTime(&statusL.fdateLastWrite,
+                               &statusL.ftimeLastWrite,
+                               &pInfo->ftLastWriteTime);
+
+    pInfo->nFileSizeHigh = statusL.cbFile.ulHi;
+    pInfo->nFileSizeLow  = statusL.cbFile.ulLo;
+    pInfo->dwVolumeSerialNumber = 0; //todo
+    pInfo->nNumberOfLinks = 1;
+    pInfo->nFileIndexHigh = 0;
+    pInfo->nFileIndexLow  = 0;
+     }
    }
    else
@@ -1184,45 +1184,45 @@
      FILESTATUS4  status  = { 0 };
 
-   	rc = DosQueryFileInfo(hFile,
-        	              FIL_QUERYEASIZE,
-                	      &status,
+    rc = DosQueryFileInfo(hFile,
+                        FIL_QUERYEASIZE,
+                        &status,
                               sizeof(status));
-   	if(rc == NO_ERROR)
-   	{
-	  	pInfo->dwFileAttributes = 0;
-		if(!(status.attrFile & NOT_NORMAL))
-		  	pInfo->dwFileAttributes |= FILE_ATTRIBUTE_NORMAL_W;
-		if(status.attrFile & FILE_READONLY)
-		        pInfo->dwFileAttributes |= FILE_ATTRIBUTE_READONLY_W;
-		if(status.attrFile & FILE_HIDDEN)
-		        pInfo->dwFileAttributes |= FILE_ATTRIBUTE_HIDDEN_W;
-		if(status.attrFile & FILE_SYSTEM)
-		        pInfo->dwFileAttributes |= FILE_ATTRIBUTE_SYSTEM_W;
-		if(status.attrFile & FILE_DIRECTORY)
-		        pInfo->dwFileAttributes |= FILE_ATTRIBUTE_DIRECTORY_W;
-		if(status.attrFile & FILE_ARCHIVED)
-		        pInfo->dwFileAttributes |= FILE_ATTRIBUTE_ARCHIVE_W;
-			
-		pmDateTimeToFileTime(&status.fdateCreation,
-	                             &status.ftimeCreation,
-	                             &pInfo->ftCreationTime);
-		pmDateTimeToFileTime(&status.fdateLastAccess,
-	                             &status.ftimeLastAccess,
-	                             &pInfo->ftLastAccessTime);
-		pmDateTimeToFileTime(&status.fdateLastWrite,
-	                             &status.ftimeLastWrite,
-	                             &pInfo->ftLastWriteTime);
-	
-		pInfo->nFileSizeHigh = 0;
-		pInfo->nFileSizeLow = status.cbFile;
-		pInfo->dwVolumeSerialNumber = 0; //todo
-		pInfo->nNumberOfLinks = 1;
-		pInfo->nFileIndexHigh = 0;
-		pInfo->nFileIndexLow = 0;
-	   }
+    if(rc == NO_ERROR)
+    {
+      pInfo->dwFileAttributes = 0;
+    if(!(status.attrFile & NOT_NORMAL))
+        pInfo->dwFileAttributes |= FILE_ATTRIBUTE_NORMAL_W;
+    if(status.attrFile & FILE_READONLY)
+            pInfo->dwFileAttributes |= FILE_ATTRIBUTE_READONLY_W;
+    if(status.attrFile & FILE_HIDDEN)
+            pInfo->dwFileAttributes |= FILE_ATTRIBUTE_HIDDEN_W;
+    if(status.attrFile & FILE_SYSTEM)
+            pInfo->dwFileAttributes |= FILE_ATTRIBUTE_SYSTEM_W;
+    if(status.attrFile & FILE_DIRECTORY)
+            pInfo->dwFileAttributes |= FILE_ATTRIBUTE_DIRECTORY_W;
+    if(status.attrFile & FILE_ARCHIVED)
+            pInfo->dwFileAttributes |= FILE_ATTRIBUTE_ARCHIVE_W;
+
+    pmDateTimeToFileTime(&status.fdateCreation,
+                               &status.ftimeCreation,
+                               &pInfo->ftCreationTime);
+    pmDateTimeToFileTime(&status.fdateLastAccess,
+                               &status.ftimeLastAccess,
+                               &pInfo->ftLastAccessTime);
+    pmDateTimeToFileTime(&status.fdateLastWrite,
+                               &status.ftimeLastWrite,
+                               &pInfo->ftLastWriteTime);
+
+    pInfo->nFileSizeHigh = 0;
+    pInfo->nFileSizeLow = status.cbFile;
+    pInfo->dwVolumeSerialNumber = 0; //todo
+    pInfo->nNumberOfLinks = 1;
+    pInfo->nFileIndexHigh = 0;
+    pInfo->nFileIndexLow = 0;
+     }
    }
    if(rc) {
-      	SetLastError(error2WinError(rc));
-   	return FALSE;
+        SetLastError(error2WinError(rc));
+    return FALSE;
    }
    SetLastError(ERROR_SUCCESS_W);
@@ -1242,24 +1242,24 @@
   if(rc == NO_ERROR)
   {
-	if(creationdate && creationtime) {
-		fileInfo.fdateCreation   = *(FDATE *)&creationdate;
-        	fileInfo.ftimeCreation   = *(FTIME *)&creationtime;
-	}
-	if(lastaccessdate && lastaccesstime) {
-		fileInfo.fdateLastAccess = *(FDATE *)&lastaccessdate;
-        	fileInfo.ftimeLastAccess = *(FTIME *)&lastaccesstime;
-	}
-	if(lastwritedate && lastwritetime) {
-		fileInfo.fdateLastWrite  = *(FDATE *)&lastwritedate;
-        	fileInfo.ftimeLastWrite  = *(FTIME *)&lastwritetime;
-	}
-
- 	rc = DosSetFileInfo(hFile, FIL_STANDARD, &fileInfo, sizeof(fileInfo));
+  if(creationdate && creationtime) {
+    fileInfo.fdateCreation   = *(FDATE *)&creationdate;
+          fileInfo.ftimeCreation   = *(FTIME *)&creationtime;
+  }
+  if(lastaccessdate && lastaccesstime) {
+    fileInfo.fdateLastAccess = *(FDATE *)&lastaccessdate;
+          fileInfo.ftimeLastAccess = *(FTIME *)&lastaccesstime;
+  }
+  if(lastwritedate && lastwritetime) {
+    fileInfo.fdateLastWrite  = *(FDATE *)&lastwritedate;
+          fileInfo.ftimeLastWrite  = *(FTIME *)&lastwritetime;
+  }
+
+  rc = DosSetFileInfo(hFile, FIL_STANDARD, &fileInfo, sizeof(fileInfo));
   }
 
   if(rc)
   {
-      	SetLastError(error2WinError(rc));
-     	return FALSE;
+        SetLastError(error2WinError(rc));
+      return FALSE;
   }
   SetLastError(ERROR_SUCCESS_W);
@@ -1279,9 +1279,9 @@
   if(rc == NO_ERROR)
   {
-	*creationdate   = *(WORD *)&fileInfo.fdateCreation;
+  *creationdate   = *(WORD *)&fileInfo.fdateCreation;
         *creationtime   = *(WORD *)&fileInfo.ftimeCreation;
-	*lastaccessdate = *(WORD *)&fileInfo.fdateLastAccess;
+  *lastaccessdate = *(WORD *)&fileInfo.fdateLastAccess;
         *lastaccesstime = *(WORD *)&fileInfo.ftimeLastAccess;
-	*lastwritedate  = *(WORD *)&fileInfo.fdateLastWrite;
+  *lastwritedate  = *(WORD *)&fileInfo.fdateLastWrite;
         *lastwritetime  = *(WORD *)&fileInfo.ftimeLastWrite;
   }
@@ -1289,6 +1289,6 @@
   if(rc)
   {
-      	SetLastError(error2WinError(rc));
-     	return FALSE;
+        SetLastError(error2WinError(rc));
+      return FALSE;
   }
   SetLastError(ERROR_SUCCESS_W);
@@ -1305,6 +1305,6 @@
    rc = DosSetFilePtr(hFile, offset, method, &newoffset);
    if(rc) {
-    	dprintf(("DosSetFilePtr Error rc:%d", rc));
-    	return -1;
+      dprintf(("DosSetFilePtr Error rc:%d", rc));
+      return -1;
    }
    else  return newoffset;
@@ -1749,5 +1749,5 @@
         DosFindClose(hDir);
         SetLastError(error2WinError(rc));
-	return INVALID_HANDLE_VALUE_W;
+  return INVALID_HANDLE_VALUE_W;
   }
   translateFindResults(&result,lpFindFileData);
@@ -1853,5 +1853,5 @@
 }
 //******************************************************************************
-#define FSATTACH_SIZE	256
+#define FSATTACH_SIZE 256
 //******************************************************************************
 DWORD OSLibDosQueryVolumeFS(int drive, LPSTR lpFileSystemNameBuffer, DWORD nFileSystemNameSize)
@@ -1864,6 +1864,6 @@
 
    if(lpFileSystemNameBuffer == NULL) {
-	DebugInt3();
-	return ERROR_INVALID_PARAMETER_W;
+  DebugInt3();
+  return ERROR_INVALID_PARAMETER_W;
    }
    drv[0] = (char)('A' + drive - 1);
@@ -1875,11 +1875,11 @@
    switch(rc) {
    case ERROR_INVALID_DRIVE:
-	return ERROR_INVALID_DRIVE_W;
+  return ERROR_INVALID_DRIVE_W;
    case ERROR_NO_VOLUME_LABEL:
-	return ERROR_NO_VOLUME_LABEL_W;
+  return ERROR_NO_VOLUME_LABEL_W;
    case NO_ERROR:
-	break;
+  break;
    default:
- 	return ERROR_NOT_ENOUGH_MEMORY; //whatever
+  return ERROR_NOT_ENOUGH_MEMORY; //whatever
    }
 
@@ -1894,7 +1894,7 @@
   /*
    if(strlen(fsname) < nFileSystemNameSize) {
- 	strcpy(lpFileSystemNameBuffer, fsname);
-   }
-   else	return ERROR_BUFFER_OVERFLOW_W;
+  strcpy(lpFileSystemNameBuffer, fsname);
+   }
+   else return ERROR_BUFFER_OVERFLOW_W;
    */
    return 0;
@@ -1903,6 +1903,6 @@
 typedef struct _FSINFOBUF
 {
-	ULONG 		ulVolser;          /* Volume serial number            */
-	VOLUMELABEL	vol;               /* Volume lable                    */
+  ULONG     ulVolser;          /* Volume serial number            */
+  VOLUMELABEL vol;               /* Volume lable                    */
 } FSINFOBUF;
 //******************************************************************************
@@ -1919,11 +1919,11 @@
    switch(rc) {
    case ERROR_INVALID_DRIVE:
-	return ERROR_INVALID_DRIVE_W;
+  return ERROR_INVALID_DRIVE_W;
    case ERROR_NO_VOLUME_LABEL:
-	return ERROR_NO_VOLUME_LABEL_W;
+  return ERROR_NO_VOLUME_LABEL_W;
    case NO_ERROR:
-	break;
+  break;
    default:
- 	return ERROR_NOT_ENOUGH_MEMORY; //whatever
+  return ERROR_NOT_ENOUGH_MEMORY; //whatever
    }
 
@@ -1933,7 +1933,7 @@
    if(lpVolumeNameBuffer)
    {
-   	if(nVolumeNameSize > fsi.vol.cch) {
+    if(nVolumeNameSize > fsi.vol.cch) {
              strcpy(lpVolumeNameBuffer, (PCHAR)fsi.vol.szVolLabel);
-	}
+  }
         else return ERROR_BUFFER_OVERFLOW_W;
    }
@@ -1972,5 +1972,5 @@
         *lpNumberOfFreeClusters  = fsAlloc.cUnitAvail;
         *lpTotalNumberOfClusters = fsAlloc.cUnit;
-	SetLastError(ERROR_SUCCESS_W);
+  SetLastError(ERROR_SUCCESS_W);
         return TRUE;
    }
@@ -2006,4 +2006,20 @@
   }
   return NO_ERROR;
+}
+//******************************************************************************
+//******************************************************************************
+DWORD OSLibDosDevIOCtl( DWORD hFile, DWORD dwCat, DWORD dwFunc,
+                        PVOID pParm, DWORD dwParmMaxLen, DWORD *pdwParmLen,
+                        PVOID pData, DWORD dwDataMaxLen, DWORD *pdwDataLen)
+{
+  APIRET rc;
+  USHORT sel = RestoreOS2FS();
+
+  rc = DosDevIOCtl( (HFILE)hFile, dwCat, dwFunc,
+                     pParm, dwParmMaxLen, pdwParmLen,
+                     pData, dwDataMaxLen, pdwDataLen);
+  SetFS(sel);
+  SetLastError(error2WinError(rc,ERROR_INVALID_HANDLE));
+  return (DWORD)rc;
 }
 
Index: trunk/src/kernel32/oslibdos.h
===================================================================
--- trunk/src/kernel32/oslibdos.h	(revision 4280)
+++ trunk/src/kernel32/oslibdos.h	(revision 4285)
@@ -1,3 +1,3 @@
-/* $Id: oslibdos.h,v 1.22 2000-09-12 04:27:45 bird Exp $ */
+/* $Id: oslibdos.h,v 1.23 2000-09-20 21:32:55 hugh Exp $ */
 
 /*
@@ -195,4 +195,7 @@
 DWORD OSLibDosQueryVolumeFS(int drive, LPSTR lpFileSystemNameBuffer, DWORD nFileSystemNameSize);
 DWORD OSLibDosQueryVolumeSerialAndName(int drive, LPDWORD lpVolumeSerialNumber, LPSTR lpVolumeNameBuffer, DWORD nVolumeNameSize);
+DWORD OSLibDosDevIOCtl( DWORD hFile, DWORD dwCat, DWORD dwFunc,
+                        PVOID pParm, DWORD dwParmMaxLen, DWORD *pdwParmLen,
+                        PVOID pData, DWORD dwDataMaxLen, DWORD *pdwDataLen);
 
 BOOL OSLibGetDiskFreeSpace(LPSTR lpRootPathName, LPDWORD lpSectorsPerCluster,
Index: trunk/src/kernel32/wintls.cpp
===================================================================
--- trunk/src/kernel32/wintls.cpp	(revision 4280)
+++ trunk/src/kernel32/wintls.cpp	(revision 4285)
@@ -1,3 +1,3 @@
-/* $Id: wintls.cpp,v 1.11 2000-08-09 18:59:03 sandervl Exp $ */
+/* $Id: wintls.cpp,v 1.12 2000-09-20 21:32:54 hugh Exp $ */
 /*
  * Win32 TLS API functions
@@ -17,19 +17,19 @@
 #include "exceptutil.h"
 
-#define DBG_LOCALLOG	DBG_wintls
+#define DBG_LOCALLOG  DBG_wintls
 #include "dbglocal.h"
 
 //******************************************************************************
 //******************************************************************************
-void Win32ImageBase::tlsAlloc()	//Allocate TLS index for this module
-{
-   if(!tlsAddress) 
-	return;
+void Win32ImageBase::tlsAlloc() //Allocate TLS index for this module
+{
+   if(!tlsAddress)
+  return;
 
    tlsIndex = TlsAlloc();
    if(tlsIndex >= TLS_MINIMUM_AVAILABLE) {
-	dprintf(("tlsAttachThread: invalid tlsIndex %x!!!!", tlsIndex));
-	DebugInt3();
-	return;  	
+  dprintf(("tlsAttachThread: invalid tlsIndex %x!!!!", tlsIndex));
+  DebugInt3();
+  return;
    }
    dprintf(("Win32ImageBase::tlsAlloc (%d) for module %x", tlsIndex, hinstance));
@@ -37,13 +37,13 @@
 //******************************************************************************
 //******************************************************************************
-void Win32ImageBase::tlsDelete()	//Free TLS index for this module
-{
-   if(!tlsAddress) 
-	return;
+void Win32ImageBase::tlsDelete()  //Free TLS index for this module
+{
+   if(!tlsAddress)
+  return;
 
    if(tlsIndex >= TLS_MINIMUM_AVAILABLE) {
-	dprintf(("tlsAttachThread: invalid tlsIndex %x!!!!", tlsIndex));
-	DebugInt3();
-	return;  	
+  dprintf(("tlsAttachThread: invalid tlsIndex %x!!!!", tlsIndex));
+  DebugInt3();
+  return;
    }
    dprintf(("Win32ImageBase::tlsDestroy (%d) for module %x", tlsIndex, hinstance));
@@ -53,5 +53,5 @@
 //******************************************************************************
 //******************************************************************************
-void Win32ImageBase::tlsAttachThread()	//setup TLS structures for new thread
+void Win32ImageBase::tlsAttachThread()  //setup TLS structures for new thread
 {
  EXCEPTION_FRAME      exceptFrame;
@@ -59,11 +59,11 @@
  LPVOID               tibmem;
 
-   if(!tlsAddress) 
-	return;
+   if(!tlsAddress)
+  return;
 
    if(tlsIndex >= TLS_MINIMUM_AVAILABLE) {
-	dprintf(("tlsAttachThread: invalid tlsIndex %x!!!!", tlsIndex));
-	DebugInt3();
-	return;  	
+  dprintf(("tlsAttachThread: invalid tlsIndex %x!!!!", tlsIndex));
+  DebugInt3();
+  return;
    }
 
@@ -77,7 +77,7 @@
    tibmem = VirtualAlloc(0, tlsTotalSize, MEM_RESERVE|MEM_COMMIT, PAGE_READWRITE);
    if(tibmem == NULL) {
-	dprintf(("tlsAttachThread: tibmem == NULL!!!!"));
-	DebugInt3();
-	return;
+  dprintf(("tlsAttachThread: tibmem == NULL!!!!"));
+  DebugInt3();
+  return;
    }
    memset(tibmem, 0, tlsTotalSize);
@@ -88,13 +88,13 @@
 
    if(tlsCallBackAddr && (ULONG)*tlsCallBackAddr != 0) {
-	pCallback = tlsCallBackAddr;
-	while(*pCallback) {
-		dprintf(("tlsAttachThread: calling TLS Callback %x", *pCallback));
-
-		(*pCallback)((LPVOID)hinstance, DLL_THREAD_ATTACH, 0);
-
-		dprintf(("tlsAttachThread: finished calling TLS Callback %x", *pCallback));
-		*pCallback++;
-	}
+  pCallback = tlsCallBackAddr;
+  while(*pCallback) {
+    dprintf(("tlsAttachThread: calling TLS Callback %x", *pCallback));
+
+    (*pCallback)((LPVOID)hinstance, DLL_THREAD_ATTACH, 0);
+
+    dprintf(("tlsAttachThread: finished calling TLS Callback %x", *pCallback));
+    *pCallback++;
+  }
    }
    return;
@@ -102,5 +102,5 @@
 //******************************************************************************
 //******************************************************************************
-void Win32ImageBase::tlsDetachThread()	//destroy TLS structures
+void Win32ImageBase::tlsDetachThread()  //destroy TLS structures
 {
  EXCEPTION_FRAME      exceptFrame;
@@ -108,26 +108,26 @@
  LPVOID tlsmem;
 
-   if(!tlsAddress) 
-	return;
+   if(!tlsAddress)
+  return;
 
    dprintf(("Win32ImageBase::tlsDetachThread for module %x, thread id %x", hinstance, GetCurrentThreadId()));
 
    if(tlsCallBackAddr && (ULONG)*tlsCallBackAddr != 0) {
-	pCallback = tlsCallBackAddr;
-	while(*pCallback) {
-		dprintf(("tlsDetachThread: calling TLS Callback %x", *pCallback));
-
-		(*pCallback)((LPVOID)hinstance, DLL_THREAD_DETACH, 0);
-
-		dprintf(("tlsDetachThread: finished calling TLS Callback %x", *pCallback));
-		*pCallback++;
-	}
+  pCallback = tlsCallBackAddr;
+  while(*pCallback) {
+    dprintf(("tlsDetachThread: calling TLS Callback %x", *pCallback));
+
+    (*pCallback)((LPVOID)hinstance, DLL_THREAD_DETACH, 0);
+
+    dprintf(("tlsDetachThread: finished calling TLS Callback %x", *pCallback));
+    *pCallback++;
+  }
    }
    tlsmem = TlsGetValue(tlsIndex);
    if(tlsmem) {
-   	VirtualFree(tlsmem, tlsTotalSize, MEM_RELEASE);
+    VirtualFree(tlsmem, tlsTotalSize, MEM_RELEASE);
    }
    else {
-	dprintf(("ERROR: tlsDetachThread: tlsmem == NULL!!!"));
+  dprintf(("ERROR: tlsDetachThread: tlsmem == NULL!!!"));
    }
    TlsFree(tlsIndex);
@@ -154,18 +154,18 @@
   tibidx = 0;
   if(pdb->tls_bits[0] == 0xFFFFFFFF) {
-  	if(pdb->tls_bits[1] == 0xFFFFFFFF) {
-  		LeaveCriticalSection(&pdb->crit_section);
-  		SetLastError(ERROR_NO_MORE_ITEMS);  //TODO: correct error?
-		return -1;
-	}
-	tibidx = 1;
+    if(pdb->tls_bits[1] == 0xFFFFFFFF) {
+      LeaveCriticalSection(&pdb->crit_section);
+      SetLastError(ERROR_NO_MORE_ITEMS);  //TODO: correct error?
+    return -1;
+  }
+  tibidx = 1;
   }
   for(i=0;i<32;i++) {
-	mask = (1 << i);
-	if((pdb->tls_bits[tibidx] & mask) == 0) {
-		pdb->tls_bits[tibidx] |= mask;
-		index = (tibidx*32) + i;
-		break;
-	}
+  mask = (1 << i);
+  if((pdb->tls_bits[tibidx] & mask) == 0) {
+    pdb->tls_bits[tibidx] |= mask;
+    index = (tibidx*32) + i;
+    break;
+  }
   }
   LeaveCriticalSection(&pdb->crit_section);
@@ -200,13 +200,13 @@
   tlsidx = 0;
   if(index > 32) {
-	tlsidx++;
+  tlsidx++;
   }
   mask = (1 << index);
   if(pdb->tls_bits[tlsidx] & mask) {
         LeaveCriticalSection(&pdb->crit_section);
-	pdb->tls_bits[tlsidx] &= ~mask;
+  pdb->tls_bits[tlsidx] &= ~mask;
         thdb->tls_array[index] = 0;
         SetLastError(ERROR_SUCCESS);
-	return TRUE;
+  return TRUE;
   }
   LeaveCriticalSection(&pdb->crit_section);
