diff options
Diffstat (limited to 'src/interface-curses')
| -rw-r--r-- | src/interface-curses/interface.c | 39 |
1 files changed, 17 insertions, 22 deletions
diff --git a/src/interface-curses/interface.c b/src/interface-curses/interface.c index fbac2cb..b304e12 100644 --- a/src/interface-curses/interface.c +++ b/src/interface-curses/interface.c @@ -43,10 +43,6 @@ #include <glib/gprintf.h> #include <glib/gstdio.h> -#ifdef G_OS_UNIX -#include <sys/wait.h> -#endif - #include <curses.h> #ifdef HAVE_TIGETSTR @@ -70,6 +66,7 @@ #include "error.h" #include "view.h" #include "memory.h" +#include "spawn.h" #include "interface.h" #include "curses-utils.h" #include "curses-info-popup.h" @@ -1544,25 +1541,24 @@ teco_interface_set_clipboard(const gchar *name, const gchar *str, gsize str_len, *sel = get_selection_by_name(name); } + errno = ENOMEM; FILE *pipe = popen(command.data, "w"); if (!pipe) { g_set_error(error, TECO_ERROR, TECO_ERROR_FAILED, - "Cannot spawn process from %s", reg_name); + "Cannot spawn process from %s: %s", reg_name, g_strerror(errno)); return FALSE; } size_t len = fwrite(str, 1, str_len, pipe); - int status = pclose(pipe); - if (status < 0 || !WIFEXITED(status)) { + gint status = pclose(pipe); + if (status < 0) { g_set_error(error, TECO_ERROR, TECO_ERROR_FAILED, - "Error reaping process from %s", reg_name); + "Error running process from %s: %s", reg_name, g_strerror(errno)); return FALSE; } - if (WEXITSTATUS(status) != 0) { - g_set_error(error, TECO_ERROR, TECO_ERROR_FAILED, - "Process from %s returned with exit code %d", - reg_name, WEXITSTATUS(status)); + if (!teco_spawn_check_wait_status(status, error)) { + g_prefix_error(error, "Error running process from %s: ", reg_name); return FALSE; } @@ -1600,10 +1596,11 @@ teco_interface_get_clipboard(const gchar *name, gchar **str, gsize *len, GError *sel = get_selection_by_name(name); } + errno = ENOMEM; FILE *pipe = popen(command.data, "r"); if (!pipe) { g_set_error(error, TECO_ERROR, TECO_ERROR_FAILED, - "Cannot spawn process from %s", reg_name); + "Cannot spawn process from %s: %s", reg_name, g_strerror(errno)); return FALSE; } @@ -1617,20 +1614,18 @@ teco_interface_get_clipboard(const gchar *name, gchar **str, gsize *len, GError teco_string_append(&ret, buffer, read_len); } while (read_len == sizeof(buffer)); - int status = pclose(pipe); - if (status < 0 || !WIFEXITED(status)) { + gint status = pclose(pipe); + if (status < 0) { g_set_error(error, TECO_ERROR, TECO_ERROR_FAILED, - "Error reaping process from %s", reg_name); + "Error running process from %s: %s", reg_name, g_strerror(errno)); return FALSE; } /* * You may have to add a `|| true` for instance to xclip if it * could fail for empty selections. */ - if (WEXITSTATUS(status) != 0) { - g_set_error(error, TECO_ERROR, TECO_ERROR_FAILED, - "Process from %s returned with exit code %d", - reg_name, WEXITSTATUS(status)); + if (!teco_spawn_check_wait_status(status, error)) { + g_prefix_error(error, "Error running process from %s: ", reg_name); return FALSE; } @@ -1962,7 +1957,7 @@ teco_interface_process_mevent(MEVENT *event, GError **error) * Furthermore due to ncurses bugs the order * of events is arbitrary. * Therefore we ignore BUTTON2_PRESSED and synthesize - * PRESSED and RELEASED evnts on BUTTON2_RELEASED: + * PRESSED and RELEASED events on BUTTON2_RELEASED: */ if (teco_mouse.button == 2) { if (teco_mouse.type == TECO_MOUSE_PRESSED) @@ -2023,7 +2018,7 @@ teco_interface_blocking_getch(void) * If we would reset the mouse mask with every wgetch(), which resets * the internal button state, we would receive bogus BUTTON3_PRESSED events * repeatedly. - * An upstream ncurses patch will probably be merged soon. + * An upstream ncurses patch has been merged since NCURSES_VERSION_PATCH >= 20250913. */ static gboolean old_mousekey = FALSE; gboolean new_mousekey = (teco_ed & TECO_ED_MOUSEKEY) != 0; |
