shithub: MicroHs

Download patch

ref: 7846a20f2318b751789c7a6c86e7f5999292fb76
parent: 6e9ed9942e4649caf93e387cf216b6bfc9d0a036
author: Lennart Augustsson <lennart.augustsson@epicgames.com>
date: Sat Nov 25 10:06:20 EST 2023

Better error messages in getraw().

--- a/src/runtime/config-unix-64.h
+++ b/src/runtime/config-unix-64.h
@@ -51,6 +51,11 @@
 #include <string.h>
 #include <stdlib.h>
 #include <fcntl.h>
+#include <fcntl.h>
+#include <errno.h>
+#if WANT_STDIO
+#include <stdio.h>
+#endif  /* WANT_STDIO */
 
 /*
  * Set the terminal in raw mode and read a single character.
@@ -63,17 +68,34 @@
   char c;
   int r;
   
-  if (tcgetattr(0, &old))
+  if (tcgetattr(0, &old)) {
+#if WANT_STDIO
+    fprintf(stderr, "tcgetattr failed: errno=%d\n", errno);
+#endif  /* WANT_STDIO */
     return -1;
+  }
   cfmakeraw(&new);
-  if (tcsetattr(0, TCSANOW, &new))
+  if (tcsetattr(0, TCSANOW, &new)) {
+#if WANT_STDIO
+    fprintf(stderr, "tcsetattr 1 failed: errno=%d\n", errno);
+#endif  /* WANT_STDIO */
     return -1;
+  }
   r = read(0, &c, 1);
-  (void)tcsetattr(0, TCSANOW, &old);
+  if (tcsetattr(0, TCSANOW, &old)) {
+#if WANT_STDIO
+    fprintf(stderr, "tcsetattr 2 failed: errno=%d\n", errno);
+#endif  /* WANT_STDIO */
+    return -1;
+  }
   if (r == 1)
     return c;
-  else
+  else {
+#if WANT_STDIO
+    fprintf(stderr, "read failed: errno=%d\n", errno);
+#endif  /* WANT_STDIO */
     return -1;
+  }
 }
 /*
  * Get a raw input character.
--