[PATCH 4/4] [kernel] Support opening of console for read

Christian Costa titan.costa at gmail.com
Mon Nov 19 15:32:46 CST 2012


+ * write_console_input
+ *
+ * Helper function for bare_console_fetch_input calling WriteConsoleInput
+ * The handle passed to ReadConsole etc may not have been opened for write,
+ * and hence the calls to WriteConsoleInput may fail. This routine handles such
+ * a failure, and retries the write by opening the console for write, using
+ * it and then closing it again.
+ *
+ * Returns as per WriteConsoleInputW (TRUE on success)
+ */
+BOOL WINAPI write_console_input( HANDLE handle, const INPUT_RECORD *buffer,
+                                 DWORD count, LPDWORD written )
+{
+  BOOL result = WriteConsoleInputW(handle, buffer, count, written);
+
+  /* If this fails with access denied */
+  if (!result && GetLastError() == ERROR_ACCESS_DENIED) {
+    HANDLE hConRW = CreateFileW(coninW, GENERIC_READ | GENERIC_WRITE,
+                                FILE_SHARE_READ, NULL, OPEN_EXISTING,
+                                FILE_ATTRIBUTE_NORMAL, 0);
+    if (hConRW != INVALID_HANDLE_VALUE) {
+      result = WriteConsoleInputW(hConRW, buffer, count, written);
+      CloseHandle(hConRW);
+    }
+  }
+
+  return result;
+}

Hi Jason,

That would be better to use 4 spaces identation as the rest of the file.

Christian




More information about the wine-devel mailing list