diff options
author | James Booth <boothj5@gmail.com> | 2015-02-04 01:04:56 +0000 |
---|---|---|
committer | James Booth <boothj5@gmail.com> | 2015-02-04 01:04:56 +0000 |
commit | b2536e91c0a9eac16aee999aa6550b2fc3de6b87 (patch) | |
tree | 0a4a0a6b87de0d5f8e350a09b587d2199afd2a29 /src | |
parent | 7ab301869f919ef815c7dbb024a7b19ceaec671f (diff) | |
download | profani-tty-b2536e91c0a9eac16aee999aa6550b2fc3de6b87.tar.gz |
Fixed input timout returning EINVAL on OSX
Diffstat (limited to 'src')
-rw-r--r-- | src/ui/inputwin.c | 23 |
1 files changed, 18 insertions, 5 deletions
diff --git a/src/ui/inputwin.c b/src/ui/inputwin.c index 0ee1d721..f29b5318 100644 --- a/src/ui/inputwin.c +++ b/src/ui/inputwin.c @@ -39,6 +39,7 @@ #include <string.h> #include <wchar.h> #include <sys/time.h> +#include <errno.h> #include <readline/readline.h> #include <readline/history.h> @@ -111,8 +112,13 @@ create_input_window(void) #else ESCDELAY = 25; #endif - p_rl_timeout.tv_sec = 0; - p_rl_timeout.tv_usec = inp_timeout * 1000; + if (inp_timeout == 1000) { + p_rl_timeout.tv_sec = 1; + p_rl_timeout.tv_usec = 0; + } else { + p_rl_timeout.tv_sec = 0; + p_rl_timeout.tv_usec = inp_timeout * 1000; + } rl_readline_name = "profanity"; rl_getc_function = _inp_rl_getc; @@ -134,9 +140,11 @@ inp_readline(void) { FD_ZERO(&fds); FD_SET(fileno(rl_instream), &fds); + errno = 0; r = select(FD_SETSIZE, &fds, NULL, NULL, &p_rl_timeout); if (r < 0) { - log_error("Readline failed."); + char *err_msg = strerror(errno); + log_error("Readline failed: %s", err_msg); return TRUE; } @@ -155,8 +163,13 @@ inp_readline(void) prof_handle_idle(); } - p_rl_timeout.tv_sec = 0; - p_rl_timeout.tv_usec = inp_timeout * 1000; + if (inp_timeout == 1000) { + p_rl_timeout.tv_sec = 1; + p_rl_timeout.tv_usec = 0; + } else { + p_rl_timeout.tv_sec = 0; + p_rl_timeout.tv_usec = inp_timeout * 1000; + } return cmd_result; } |