Commit d218dcd4 authored by Luke Dashjr's avatar Luke Dashjr Committed by Rusty Russell

opt: only use termios if HAVE_SYS_TERMIOS_H is defined

This fixes building for Windows and other platforms which lack <sys/termios.h>
Signed-off-by: default avatarLuke Dashjr <luke-jr+git@utopios.org>
Signed-off-by: default avatarRusty Russell <rusty@rustcorp.com.au>
parent 9273220c
/* Licensed under GPLv3+ - see LICENSE file for details */ /* Licensed under GPLv3+ - see LICENSE file for details */
#include <ccan/opt/opt.h> #include <ccan/opt/opt.h>
#ifdef HAVE_SYS_TERMIOS_H
#include <sys/ioctl.h> #include <sys/ioctl.h>
#include <sys/termios.h> /* Required on Solaris for struct winsize */ #include <sys/termios.h> /* Required on Solaris for struct winsize */
#endif
#include <sys/unistd.h> /* Required on Solaris for ioctl */ #include <sys/unistd.h> /* Required on Solaris for ioctl */
#include <string.h> #include <string.h>
#include <stdlib.h> #include <stdlib.h>
...@@ -17,19 +19,23 @@ const char opt_hidden[1]; ...@@ -17,19 +19,23 @@ const char opt_hidden[1];
static unsigned int get_columns(void) static unsigned int get_columns(void)
{ {
struct winsize w; int ws_col = 0;
const char *env = getenv("COLUMNS"); const char *env = getenv("COLUMNS");
w.ws_col = 0;
if (env) if (env)
w.ws_col = atoi(env); ws_col = atoi(env);
if (!w.ws_col) #ifdef HAVE_SYS_TERMIOS_H
if (ioctl(0, TIOCGWINSZ, &w) == -1) if (!ws_col)
w.ws_col = 0; {
if (!w.ws_col) struct winsize w;
w.ws_col = 80; if (ioctl(0, TIOCGWINSZ, &w) != -1)
ws_col = w.ws_col;
return w.ws_col; }
#endif
if (!ws_col)
ws_col = 80;
return ws_col;
} }
/* Return number of chars of words to put on this line. /* Return number of chars of words to put on this line.
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment