18
18
#define MSG_MAX 512 /* max message length */
19
19
#define CHA_MAX 200 /* max channel length */
20
20
21
- static unsigned short cmax ; /* max printed line chars */
22
21
static int conn ; /* connection socket */
23
22
static char chan_default [MSG_MAX ]; /* default PRIVMSG channel */
24
23
static int verb = 0 ; /* verbose output */
@@ -119,6 +118,14 @@ connection_initialize(void) {
119
118
static void
120
119
message_wrap (char * line , size_t offset ) {
121
120
121
+ struct winsize window_dims ;
122
+
123
+ if (ioctl (0 , TIOCGWINSZ , & window_dims ) < 0 ) {
124
+ perror ("ioctrl" );
125
+ exit (EXIT_FAILURE );
126
+ }
127
+
128
+ unsigned short cmax = window_dims .ws_col ;
122
129
char * tok ;
123
130
size_t wordwidth , spaceleft = cmax - gutl - offset , spacewidth = 1 ;
124
131
@@ -318,8 +325,6 @@ main(int argc, char **argv) {
318
325
if (pass ) raw ("PASS %s\r\n" , pass );
319
326
if (inic ) raw ("%s\r\n" , inic );
320
327
321
- struct winsize window_dims ;
322
-
323
328
struct pollfd fds [2 ];
324
329
fds [0 ].fd = STDIN_FILENO ;
325
330
fds [1 ].fd = conn ;
@@ -333,8 +338,6 @@ main(int argc, char **argv) {
333
338
handle_user_input ();
334
339
}
335
340
if (fds [1 ].revents & POLLIN && (keyboard_hit () < 1 )) {
336
- ioctl (0 , TIOCGWINSZ , & window_dims );
337
- cmax = window_dims .ws_col ;
338
341
int rc = handle_server_message ();
339
342
if (rc != 0 ) {
340
343
if (rc == -2 ) return EXIT_FAILURE ;
0 commit comments