* sim/ucsim/cmd.src/cmdutil.cc: NUL device is detected as CG_FILE type
[fw/sdcc] / sim / ucsim / cmd.src / cmdutil.cc
index 067a3afcd53df6ec693528643b2cb653a67d2358..955c51e87d155f5ff04ea19ce68a68684420c036 100644 (file)
@@ -152,12 +152,25 @@ get_handle_type(HANDLE handle)
     {
     case FILE_TYPE_CHAR:
       {
-              DWORD err;
+        DWORD err;
 
         if (!ClearCommError(handle, &err, NULL))
-          { 
-            if (ERROR_INVALID_HANDLE == GetLastError())
-              return CH_CONSOLE;
+          {
+            switch (GetLastError())
+              {
+              case ERROR_INVALID_HANDLE:
+                return CH_CONSOLE;
+
+              case ERROR_INVALID_FUNCTION:
+                /*
+                 * In case of NUL device return type CH_FILE.
+                 * Is this the correct way to test it?
+                 */
+                return CH_FILE;
+
+              default:
+                assert(false);
+              }
           }
       }
       return CH_SERIAL;
@@ -218,13 +231,12 @@ input_avail(HANDLE handle, e_handle_type type)
           !GetNumberOfConsoleInputEvents(handle, &NumPending) ||
           NumPending == 0 ||
           NULL == (pIRBuf = (PINPUT_RECORD)_alloca(NumPending * sizeof(INPUT_RECORD))))
-          return FALSE;
+          return false;
 
         if (PeekConsoleInput(handle, pIRBuf, NumPending, &NumPeeked) &&
           NumPeeked != 0L &&
           NumPeeked <= NumPending)
           {
-
             /*
              * Scan all of the peeked events to determine if any is a key event
              * which should be recognized.