Skip to content

Commit a84671a

Browse files
committed
FIX: warning: ignoring return value of ‘read’, declared with attribute warn_unused_result
1 parent a38e2a5 commit a84671a

File tree

1 file changed

+28
-10
lines changed

1 file changed

+28
-10
lines changed

src/os/posix/dev-stdio.c

+28-10
Original file line numberDiff line numberDiff line change
@@ -362,12 +362,13 @@ static void Close_StdIO_Local(void)
362362
if (c[0] == '\e') {
363363
evt.type = EVT_CONTROL;
364364
// Escape sequences... is there really some system in it?!
365+
// This may be helpful: https://stackoverflow.com/a/71659748
365366
if (poll(&poller, 1, 0) <= 0) {
366367
// no any other char
367368
evt.data = EVK_ESCAPE;
368369
goto throw_event;
369370
}
370-
read(Std_Inp, &c, 2);
371+
if (2 != read(Std_Inp, &c, 2)) break;
371372
//printf(" %s ", c);
372373
if (c[0] == '[') {
373374
switch(c[1]){
@@ -379,9 +380,10 @@ static void Close_StdIO_Local(void)
379380
case 'H': evt.data = EVK_HOME; goto throw_event;
380381
}
381382
if (c[1] == '1') {
382-
read(Std_Inp, &c[2], 2);
383+
if (2 != read(Std_Inp, &c[2], 2)) break;
383384
//printf("%s ", c);
384-
if(c[3] == '~') {
385+
if(c[3] == '~' || c[3] == '^') {
386+
if (c[3] == '^') SET_FLAG(evt.flags, EVF_CONTROL);
385387
switch(c[2]){
386388
case '1': evt.data = EVK_F1; goto throw_event; //== "\e[11~"
387389
case '2': evt.data = EVK_F2; goto throw_event; //== "\e[12~"
@@ -395,20 +397,20 @@ static void Close_StdIO_Local(void)
395397
}
396398
else if(c[2] == ';' && c[3] == '2') {
397399
SET_FLAG(evt.flags, EVF_SHIFT);
398-
read(Std_Inp, &c[4], 1);
400+
if (1 != read(Std_Inp, &c[4], 1)) break;
399401
switch(c[4]){
400402
case 'C': evt.data = EVK_RIGHT; goto throw_event; //== "\e[1;2C"
401403
case 'D': evt.data = EVK_LEFT; goto throw_event; //== "\e[1;2D"
402404
}
403405
}
404406
}
405407
else if (c[1] == '2') {
406-
read(Std_Inp, &c[2], 1);
408+
if (1 != read(Std_Inp, &c[2], 1)) break;
407409
//printf("%s ", c);
408410
if (c[2] == '~') {
409411
evt.data = EVK_INSERT; goto throw_event; //== "\e[2~"
410412
}
411-
read(Std_Inp, &c[3], 1);
413+
if (1 != read(Std_Inp, &c[3], 1)) break;
412414
//printf("%s ", c);
413415
if (c[3] == '~') {
414416
switch(c[2]){
@@ -425,8 +427,24 @@ static void Close_StdIO_Local(void)
425427
case '9': evt.data = EVK_F8; goto throw_event;
426428
}
427429
}
430+
if (c[3] == '^') {
431+
SET_FLAG(evt.flags, EVF_CONTROL);
432+
switch(c[2]){
433+
case '0': evt.data = EVK_F9; goto throw_event; //== "\e[20^"
434+
case '1': evt.data = EVK_F10; goto throw_event;
435+
case '3': evt.data = EVK_F11; goto throw_event;
436+
case '4': evt.data = EVK_F12; goto throw_event;
437+
}
438+
SET_FLAG(evt.flags, EVF_SHIFT);
439+
switch(c[2]){
440+
case '5': evt.data = EVK_F5; goto throw_event; //== "\e[25^"
441+
case '6': evt.data = EVK_F6; goto throw_event;
442+
case '8': evt.data = EVK_F7; goto throw_event;
443+
case '9': evt.data = EVK_F8; goto throw_event;
444+
}
445+
}
428446
else {
429-
read(Std_Inp, &c[4], 1);
447+
if (1 != read(Std_Inp, &c[4], 1)) break;
430448
if (c[4] == '~' && c[2] == '0') {
431449
switch(c[3]){
432450
case '0': evt.data = EVK_PASTE_START; goto throw_event; //== "\e[200~"
@@ -436,7 +454,7 @@ static void Close_StdIO_Local(void)
436454
}
437455
}
438456
else if (c[1] > '2' && c[1] <= '8') {
439-
read(Std_Inp, &c[2], 1);
457+
if (1 != read(Std_Inp, &c[2], 1)) break;
440458
//printf("%s ", c);
441459
if (c[2] == '~') {
442460
switch(c[1]){
@@ -449,7 +467,7 @@ static void Close_StdIO_Local(void)
449467
}
450468
}
451469
else if (c[1] == '3') {
452-
read(Std_Inp, &c[3], 1);
470+
if (1 != read(Std_Inp, &c[3], 1)) break;
453471
//printf("%s ", c);
454472
if (c[3] == '~') {
455473
SET_FLAG(evt.flags, EVF_SHIFT);
@@ -483,7 +501,7 @@ static void Close_StdIO_Local(void)
483501
if ((c[0] & 0xE0) == 0xC0) len = 1; // `len` as a number of missing bytes!
484502
else if ((c[0] & 0xF0) == 0xE0) len = 2;
485503
else if ((c[0] & 0xF8) == 0xF0) len = 3;
486-
read(Std_Inp, &c[1], len);
504+
if (len != read(Std_Inp, &c[1], len)) break;
487505
evt.data = RL_Decode_UTF8_Char(c, &len);
488506
}
489507
throw_event:

0 commit comments

Comments
 (0)