]> git.ipfire.org Git - thirdparty/util-linux.git/commitdiff
include: move get_terminal_width() to ttyutils.h
authorPetr Uzel <petr.uzel@suse.cz>
Tue, 15 May 2012 08:49:03 +0000 (10:49 +0200)
committerKarel Zak <kzak@redhat.com>
Tue, 15 May 2012 09:32:53 +0000 (11:32 +0200)
Signed-off-by: Petr Uzel <petr.uzel@suse.cz>
include/ttyutils.h
lib/tt.c

index f638aa0d9fa46b5575ae32bd0f166b2721ffcc2f..15809e85a4590a200347a96270c6bccc38b48a96 100644 (file)
@@ -1,7 +1,11 @@
 #ifndef UTIL_LINUX_TTYUTILS_H
 #define UTIL_LINUX_TTYUTILS_H
 
+#include <stdlib.h>
 #include <termios.h>
+#ifdef HAVE_SYS_IOCTL_H
+#include <sys/ioctl.h>
+#endif
 
 #define UL_TTY_KEEPCFLAGS      (1 << 1)
 #define UL_TTY_UTF8            (1 << 2)
@@ -74,4 +78,29 @@ static inline void reset_virtual_console(struct termios *tp, int flags)
        tp->c_cc[VEOL2]    = _POSIX_VDISABLE;
 }
 
+static inline int get_terminal_width(void)
+{
+#ifdef TIOCGSIZE
+       struct ttysize  t_win;
+#endif
+#ifdef TIOCGWINSZ
+       struct winsize  w_win;
+#endif
+        const char     *cp;
+
+#ifdef TIOCGSIZE
+       if (ioctl (0, TIOCGSIZE, &t_win) == 0)
+               return t_win.ts_cols;
+#endif
+#ifdef TIOCGWINSZ
+       if (ioctl (0, TIOCGWINSZ, &w_win) == 0)
+               return w_win.ws_col;
+#endif
+        cp = getenv("COLUMNS");
+       if (cp)
+               return strtol(cp, NULL, 10);
+       return 0;
+}
+
+
 #endif /* UTIL_LINUX_TTYUTILS_H */
index 1b5fbaceab69d1a2c3a01f47669a48e3481a2436..fe471d064c4c9b0a4085f8152611b55242c7bf1f 100644 (file)
--- a/lib/tt.c
+++ b/lib/tt.c
 #include <string.h>
 #include <termios.h>
 #include <ctype.h>
-#ifdef HAVE_SYS_IOCTL_H
-#include <sys/ioctl.h>
-#endif
 
 #include "c.h"
 #include "nls.h"
 #include "widechar.h"
 #include "tt.h"
 #include "mbsalign.h"
+#include "ttyutils.h"
 
 struct tt_symbols {
        const char *branch;
@@ -253,30 +251,6 @@ int tt_line_set_data(struct tt_line *ln, int colnum, const char *data)
        return 0;
 }
 
-static int get_terminal_width(void)
-{
-#ifdef TIOCGSIZE
-       struct ttysize  t_win;
-#endif
-#ifdef TIOCGWINSZ
-       struct winsize  w_win;
-#endif
-        const char     *cp;
-
-#ifdef TIOCGSIZE
-       if (ioctl (0, TIOCGSIZE, &t_win) == 0)
-               return t_win.ts_cols;
-#endif
-#ifdef TIOCGWINSZ
-       if (ioctl (0, TIOCGWINSZ, &w_win) == 0)
-               return w_win.ws_col;
-#endif
-        cp = getenv("COLUMNS");
-       if (cp)
-               return strtol(cp, NULL, 10);
-       return 0;
-}
-
 int tt_line_set_userdata(struct tt_line *ln, void *data)
 {
        if (!ln)