Browse code

uxnemu: use read() in stdin thread and close(0) at shutdown for the thread to exit

Sigrid Solveig Haflínudóttir authored on 28/03/2022 15:49:54
Showing 1 changed files
... ...
@@ -1,5 +1,6 @@
1 1
 #include <stdio.h>
2 2
 #include <time.h>
3
+#include <unistd.h>
3 4
 
4 5
 #include "uxn.h"
5 6
 
... ...
@@ -81,7 +82,7 @@ stdin_handler(void *p)
81 82
 {
82 83
 	SDL_Event event;
83 84
 	event.type = stdin_event;
84
-	while(fread(&event.cbutton.button, 1, 1, stdin) > 0 && SDL_PushEvent(&event) >= 0)
85
+	while(read(0, &event.cbutton.button, 1) > 0 && SDL_PushEvent(&event) >= 0)
85 86
 		;
86 87
 	return 0;
87 88
 	(void)p;
... ...
@@ -514,6 +515,7 @@ main(int argc, char **argv)
514 515
 	if(!loaded && !start(&u, "launcher.rom"))
515 516
 		return error("usage", "uxnemu [-s scale] file.rom");
516 517
 	run(&u);
518
+	close(0); /* make stdin thread exit */
517 519
 	SDL_Quit();
518 520
 	return 0;
519 521
 }