sled

Једноставни уређивач текста
git clone https://git.sr.ht/~strahinja/sled
Дневник | Датотеке | Референце | ПРОЧИТАЈМЕ | ЛИЦЕНЦА

чување 43606883e63b1155070c0e59cd233a005dbcdd0d
родитељ 84ab07ae0427a82775dadcc1c057dd2a0175f7d0
Аутор: Страхиња Радић <sr@strahinja.org>
Датум:   Sat, 24 Jan 2026 11:20:01 +0100

Fix tb_init on OpenBSD - add unveil_terminfo_path; add termbox.h diff

Diffstat:
MTODO.done | 3+++
Msled.c | 5+++++
Atermbox.diff | 168+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Mtermbox.h | 69+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
измењених датотека: 4, додавања: 245(+), брисања: 0(-)

diff --git a/TODO.done b/TODO.done @@ -8,6 +8,9 @@ Done or canceled todos [/] Send patch upstream - No need now? The error seemingly disappeared after updating to termbox.h from upstream + - Nope. Found the real cuplrit though - unveil(2) on the + terminfo path + - Added unveil(2) calls in termbox.h [x] Improve termbox2 error handling - Add ERR_TB_ERROR and handle termbox errors diff --git a/sled.c b/sled.c @@ -3110,6 +3110,11 @@ main_skip_backups: } #ifdef __OpenBSD__ + if (unveil_terminfo_path() < 0) + { + perror(PROGRAM_NAME ": unveil"); + goto main_done; + } if (unveil(NULL, NULL) < 0) { perror(PROGRAM_NAME ": unveil"); diff --git a/termbox.diff b/termbox.diff @@ -0,0 +1,168 @@ +--- /home/strajder/src/termbox2/termbox2.h Sat Jan 24 00:00:44 2026 ++++ termbox.h Sat Jan 24 11:01:39 2026 +@@ -1,4 +1,13 @@ ++/* This program is licensed under the terms of GNU GPL v3 or (at your option) ++ * any later version. Copyright (C) 2022-2026 Страхиња Радић. ++ * See the file LICENSE for exact copyright and license details. */ ++ + /* ++This file is based on the termbox2 TUI library, (c) 2021 termbox developers. ++ ++License notice from the original termbox2.h from the termbox2 repository ++follows: ++ + MIT License + + Copyright (c) 2010-2020 nsf <no.smile.face@gmail.com> +@@ -22,6 +31,7 @@ + OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + SOFTWARE. + */ ++ + #ifndef TERMBOX_H_INCL + #define TERMBOX_H_INCL + +@@ -468,7 +478,7 @@ + int tb_init_file(const char *path); + int tb_init_fd(int ttyfd); + int tb_init_rwfd(int rfd, int wfd); +-int tb_shutdown(void); ++int tb_shutdown(int deallocate); + + /* Return the size of the internal back buffer (which is the same as terminal's + * window size in rows and columns). The internal buffer can be resized after +@@ -2289,9 +2299,10 @@ + static int update_term_size(void); + static int update_term_size_via_esc(void); + static int init_cellbuf(void); +-static int tb_deinit(void); ++static int tb_deinit(int deallocate); + static int load_terminfo(void); + static int load_terminfo_from_path(const char *path, const char *term); ++static int unveil_terminfo_path(void); + static int read_terminfo_path(const char *path); + static int parse_terminfo_caps(void); + static int load_builtin_caps(void); +@@ -2373,14 +2384,15 @@ + global.initialized = 1; + } while (0); + +- if (rv != TB_OK) tb_deinit(); ++ if (rv != TB_OK) tb_deinit(1); + + return rv; + } + +-int tb_shutdown(void) { ++/* Change to the original: add deallocate parameter. [SR] */ ++int tb_shutdown(int deallocate) { + if_not_init_return(); +- tb_deinit(); ++ tb_deinit(deallocate); + return TB_OK; + } + +@@ -3169,7 +3181,8 @@ + return TB_OK; + } + +-static int tb_deinit(void) { ++/* Change to the original: add deallocate parameter. [SR] */ ++static int tb_deinit(int deallocate) { + if (global.caps[0] != NULL && global.wfd >= 0) { + bytebuf_puts(&global.out, global.caps[TB_CAP_SHOW_CURSOR]); + bytebuf_puts(&global.out, global.caps[TB_CAP_SGR0]); +@@ -3196,12 +3209,15 @@ + if (global.resize_pipefd[0] >= 0) close(global.resize_pipefd[0]); + if (global.resize_pipefd[1] >= 0) close(global.resize_pipefd[1]); + +- cellbuf_free(&global.back); +- cellbuf_free(&global.front); +- bytebuf_free(&global.in); +- bytebuf_free(&global.out); ++ if (deallocate) ++ { ++ cellbuf_free(&global.back); ++ cellbuf_free(&global.front); ++ bytebuf_free(&global.in); ++ bytebuf_free(&global.out); + +- if (global.terminfo) tb_free(global.terminfo); ++ if (global.terminfo) tb_free(global.terminfo); ++ } + + cap_trie_deinit(&global.cap_trie); + +@@ -3281,6 +3297,72 @@ + + return TB_ERR; + } ++ ++#ifdef __OpenBSD__ ++static int unveil_single_path(const char* term, const char* path) { ++ int rv; ++ char tmp[TB_PATH_MAX]; ++ snprintf_or_return(rv, tmp, sizeof(tmp), "%s/%c/%s", path, term[0], term); ++ return unveil(tmp, "r"); ++} ++ ++static int unveil_terminfo_path(void) { ++ int rv; ++ char tmp[TB_PATH_MAX]; ++ const char *term = NULL; ++ const char *terminfo = NULL; ++ const char *home = NULL; ++ const char *dirs = NULL; ++ ++ term = getenv("TERM"); ++ if (!term) return TB_ERR; ++ terminfo = getenv("TERMINFO"); ++ if (terminfo) { ++ rv = unveil_single_path(term, terminfo); ++ if (!rv) return rv; ++ } ++ home = getenv("HOME"); ++ if (home) { ++ snprintf_or_return(rv, tmp, sizeof(tmp), "%s/.terminfo", home); ++ rv = unveil_single_path(term, tmp); ++ if (!rv) return rv; ++ } ++ dirs = getenv("TERMINFO_DIRS"); ++ if (dirs) { ++ char *dir = NULL; ++ snprintf_or_return(rv, tmp, sizeof(tmp), "%s", dirs); ++ dir = strtok(tmp, ":"); ++ while (dir) { ++ const char *cdir = dir; ++ if (*cdir != '\0') { ++ rv = unveil_single_path(term, cdir); ++ if (!rv) return rv; ++ } ++ dir = strtok(NULL, ":"); ++ } ++ } ++#ifdef TB_TERMINFO_DIR ++ rv = unveil_single_path(term, TB_TERMINFO_DIR); ++ if (!rv) return rv; ++#endif ++ rv = unveil_single_path(term, "/usr/local/etc/terminfo"); ++ if (!rv) return rv; ++ rv = unveil_single_path(term, "/usr/local/share/terminfo"); ++ if (!rv) return rv; ++ rv = unveil_single_path(term, "/usr/local/lib/terminfo"); ++ if (!rv) return rv; ++ rv = unveil_single_path(term, "/etc/terminfo"); ++ if (!rv) return rv; ++ rv = unveil_single_path(term, "/usr/share/terminfo"); ++ if (!rv) return rv; ++ rv = unveil_single_path(term, "/usr/lib/terminfo"); ++ if (!rv) return rv; ++ rv = unveil_single_path(term, "/usr/share/lib/terminfo"); ++ if (!rv) return rv; ++ rv = unveil_single_path(term, "/lib/terminfo"); ++ if (!rv) return rv; ++} ++#endif + + static int read_terminfo_path(const char *path) { + FILE *fp = fopen(path, "rb"); diff --git a/termbox.h b/termbox.h @@ -2302,6 +2302,7 @@ static int init_cellbuf(void); static int tb_deinit(int deallocate); static int load_terminfo(void); static int load_terminfo_from_path(const char *path, const char *term); +static int unveil_terminfo_path(void); static int read_terminfo_path(const char *path); static int parse_terminfo_caps(void); static int load_builtin_caps(void); @@ -3297,6 +3298,74 @@ static int load_terminfo_from_path(const char *path, const char *term) { return TB_ERR; } +#ifdef __OpenBSD__ +static int unveil_single_path(const char* term, const char* path) { + int rv; + char tmp[TB_PATH_MAX]; + snprintf_or_return(rv, tmp, sizeof(tmp), "%s/%c/%s", path, term[0], term); + return unveil(tmp, "r"); +} + +static int unveil_terminfo_path(void) { + int rv; + char tmp[TB_PATH_MAX]; + const char *term = NULL; + const char *terminfo = NULL; + const char *home = NULL; + const char *dirs = NULL; + + term = getenv("TERM"); + if (!term) return TB_ERR; + terminfo = getenv("TERMINFO"); + if (terminfo) { + rv = unveil_single_path(term, terminfo); + if (!rv) return rv; + } + home = getenv("HOME"); + if (home) { + snprintf_or_return(rv, tmp, sizeof(tmp), "%s/.terminfo", home); + rv = unveil_single_path(term, tmp); + if (!rv) return rv; + } + dirs = getenv("TERMINFO_DIRS"); + if (dirs) { + char *dir = NULL; + snprintf_or_return(rv, tmp, sizeof(tmp), "%s", dirs); + dir = strtok(tmp, ":"); + while (dir) { + const char *cdir = dir; + if (*cdir != '\0') { + rv = unveil_single_path(term, cdir); + if (!rv) return rv; + } + dir = strtok(NULL, ":"); + } + } +#ifdef TB_TERMINFO_DIR + rv = unveil_single_path(term, TB_TERMINFO_DIR); + if (!rv) return rv; +#endif + rv = unveil_single_path(term, "/usr/local/etc/terminfo"); + if (!rv) return rv; + rv = unveil_single_path(term, "/usr/local/share/terminfo"); + if (!rv) return rv; + rv = unveil_single_path(term, "/usr/local/lib/terminfo"); + if (!rv) return rv; + rv = unveil_single_path(term, "/etc/terminfo"); + if (!rv) return rv; + rv = unveil_single_path(term, "/usr/share/terminfo"); + if (!rv) return rv; + rv = unveil_single_path(term, "/usr/lib/terminfo"); + if (!rv) return rv; + rv = unveil_single_path(term, "/usr/share/lib/terminfo"); + if (!rv) return rv; + rv = unveil_single_path(term, "/lib/terminfo"); + if (!rv) return rv; + + return -1; +} +#endif + static int read_terminfo_path(const char *path) { FILE *fp = fopen(path, "rb"); if (!fp) return TB_ERR;