aboutsummaryrefslogtreecommitdiffstats
path: root/kirc.c
diff options
context:
space:
mode:
authorMichael Czigler <37268479+mcpcpc@users.noreply.github.com>2020-10-02 17:50:42 -0400
committerGitHub <noreply@github.com>2020-10-02 17:50:42 -0400
commitdcff8972dc0e45075e9d80e078737069d30650f8 (patch)
tree14b9b5320453e9c1880e7d055aeb5b3c695448bc /kirc.c
parentmove ioctrl and cmax to minimize resources (diff)
downloadkirc-dcff8972dc0e45075e9d80e078737069d30650f8.tar.gz
kirc-dcff8972dc0e45075e9d80e078737069d30650f8.tar.bz2
kirc-dcff8972dc0e45075e9d80e078737069d30650f8.tar.xz
kirc-dcff8972dc0e45075e9d80e078737069d30650f8.tar.zst
kirc-dcff8972dc0e45075e9d80e078737069d30650f8.zip
add ioctl() error handling (#51)
Co-authored-by: Michael Czigler <mcpcpc@users.noreply.github.com>
Diffstat (limited to 'kirc.c')
-rw-r--r--kirc.c13
1 files changed, 8 insertions, 5 deletions
diff --git a/kirc.c b/kirc.c
index 56fcb0a..adb2e00 100644
--- a/kirc.c
+++ b/kirc.c
@@ -18,7 +18,6 @@
#define MSG_MAX 512 /* max message length */
#define CHA_MAX 200 /* max channel length */
-static unsigned short cmax; /* max printed line chars */
static int conn; /* connection socket */
static char chan_default[MSG_MAX]; /* default PRIVMSG channel */
static int verb = 0; /* verbose output */
@@ -119,6 +118,14 @@ connection_initialize(void) {
static void
message_wrap(char *line, size_t offset) {
+ struct winsize window_dims;
+
+ if (ioctl(0, TIOCGWINSZ, &window_dims) < 0) {
+ perror("ioctrl");
+ exit(EXIT_FAILURE);
+ }
+
+ unsigned short cmax = window_dims.ws_col;
char *tok;
size_t wordwidth, spaceleft = cmax - gutl - offset, spacewidth = 1;
@@ -318,8 +325,6 @@ main(int argc, char **argv) {
if (pass) raw("PASS %s\r\n", pass);
if (inic) raw("%s\r\n", inic);
- struct winsize window_dims;
-
struct pollfd fds[2];
fds[0].fd = STDIN_FILENO;
fds[1].fd = conn;
@@ -333,8 +338,6 @@ main(int argc, char **argv) {
handle_user_input();
}
if (fds[1].revents & POLLIN && (keyboard_hit() < 1)) {
- ioctl(0, TIOCGWINSZ, &window_dims);
- cmax = window_dims.ws_col;
int rc = handle_server_message();
if (rc != 0) {
if (rc == -2) return EXIT_FAILURE;