keyboard_control GETCH better err handling

GETCH - return always -1 on error, not -1 when read returned 0 and -2
if -1 - the actual value doesn't seem to be checked by any of caller.

CID 472180 should be perhaps fixed
This commit is contained in:
Martin Pulec
2025-04-15 15:44:42 +02:00
parent 2e555c7949
commit afe2c2df3e

View File

@@ -87,6 +87,7 @@
#include "module.h"
#include "types.h" // for video_desc
#include "utils/color_out.h"
#include "utils/misc.h" // for ug_strerror
#include "utils/thread.h"
#include "video.h"
@@ -310,7 +311,15 @@ GETCH()
{
unsigned char ch = 0;
const ssize_t ret = read(0, &ch, sizeof ch);
return ret <= 0 ? (int) ret - 1 : ch;
if (ret > 0) {
return ch;
}
if (ret == 0) {
MSG(WARNING, "read returned 0!\n");
} else {
MSG(WARNING, "read error: %s\n", ug_strerror(errno));
}
return -1;
}
#else
#define GETCH getch