|
|
init: check setupterm() return value and error return value - sfeed_curses - sfeed curses UI (now part of sfeed, development is in sfeed) |
|
|
 |
git clone git://git.codemadness.org/sfeed_curses (git://git.codemadness.org) |
|
|
 |
Log |
|
|
 |
Files |
|
|
 |
Refs |
|
|
 |
README |
|
|
 |
LICENSE |
|
|
|
--- |
|
|
 |
commit 830e63da7d15879638f082e241ee489b895e7782 |
|
|
 |
parent c94a5e5e01d617d1f1c2f08058df832148c4adc9 |
|
|
 |
Author: Hiltjo Posthuma <hiltjo@codemadness.org> (mailto://) |
application/vnd.lotus-organizer |
|
|
Date: Sat, 20 Mar 2021 12:51:10 +0100 |
|
|
|
|
|
|
|
init: check setupterm() return value and error return value |
|
|
|
|
|
|
|
POSIX specifies: |
|
|
|
"If setupterm() detects an error and errret is a null pointer, setupterm() |
|
|
|
writes a diagnostic message and exits." |
|
|
|
|
|
|
|
Specify errret and cleanup ourselves. minicurses will ignore this pointer, it |
|
|
|
will not use terminfo anyway. Initialize errret to 1 (success). |
|
|
|
|
|
|
|
Make sure to define and check against `OK` or `ERR` for portability, which is |
|
|
|
defined in POSIX. |
|
|
|
|
|
|
|
Reference: |
|
|
|
https://pubs.opengroup.org/onlinepubs/7908799/xcurses/del_curterm.html |
|
|
|
|
|
|
|
Discussed with quinq, thanks! |
|
|
|
|
|
|
|
Diffstat: |
|
|
|
M minicurses.h | 9 +++++++-- |
|
|
|
M sfeed_curses.c | 6 +++++- |
|
|
|
|
|
|
|
2 files changed, 12 insertions(+), 3 deletions(-) |
|
|
|
--- |
|
|
 |
diff --git a/minicurses.h b/minicurses.h |
|
|
|
@@ -1,5 +1,10 @@ |
|
|
|
#include <sys/ioctl.h> |
|
|
|
|
|
|
|
+#undef ERR |
|
|
|
+#define ERR (-1) |
|
|
|
+#undef OK |
|
|
|
+#define OK (0) |
|
|
|
+ |
|
|
|
const char *clr_eol = "\x1b[K"; |
|
|
|
const char *clear_screen = "\x1b[H\x1b[2J"; |
|
|
|
const char *cursor_address = "\x1b[%d;%dH"; |
|
|
|
@@ -23,13 +28,13 @@ setupterm(char *term, int fildes, int *errret) |
|
|
|
struct winsize winsz; |
|
|
|
|
|
|
|
if (ioctl(fildes, TIOCGWINSZ, &winsz) == -1) |
|
|
|
- return -1; /* ERR */ |
|
|
|
+ return ERR; |
|
|
|
if (winsz.ws_col > 0) |
|
|
|
columns = winsz.ws_col; |
|
|
|
if (winsz.ws_row > 0) |
|
|
|
lines = winsz.ws_row; |
|
|
|
|
|
|
|
- return 0; /* OK */ |
|
|
|
+ return OK; |
|
|
|
} |
|
|
|
|
|
|
|
char * |
|
|
 |
diff --git a/sfeed_curses.c b/sfeed_curses.c |
|
|
|
@@ -636,6 +636,7 @@ void |
|
|
|
init(void) |
|
|
|
{ |
|
|
|
struct sigaction sa; |
|
|
|
+ int errret = 1; |
|
|
|
|
|
|
|
tcgetattr(0, &tsave); |
|
|
|
memcpy(&tcur, &tsave, sizeof(tcur)); |
|
|
|
@@ -644,7 +645,10 @@ init(void) |
|
|
|
tcur.c_cc[VTIME] = 0; |
|
|
|
tcsetattr(0, TCSANOW, &tcur); |
|
|
|
|
|
|
|
- setupterm(NULL, 1, NULL); |
|
|
|
+ if (setupterm(NULL, 1, &errret) != OK || errret != 1) { |
|
|
|
+ errno = 0; |
|
|
|
+ die("setupterm: terminfo database or entry for $TERM not found"); |
|
|
|
+ } |
|
|
|
resizewin(); |
|
|
|
|
|
|
|
appmode(1); |
|