]> git.ipfire.org Git - thirdparty/util-linux.git/commitdiff
lib/ttyutils: create .c file
authorKarel Zak <kzak@redhat.com>
Thu, 22 Nov 2012 13:26:41 +0000 (14:26 +0100)
committerKarel Zak <kzak@redhat.com>
Thu, 22 Nov 2012 13:26:41 +0000 (14:26 +0100)
Well, now all tty stuff are incline functions in include/ttyutils.h.
It's seems more elegant to create regular lib/ttyutils.c for libcommon
and write test program.

Signed-off-by: Karel Zak <kzak@redhat.com>
include/ttyutils.h
lib/Makemodule.am
lib/ttyutils.c [new file with mode: 0644]

index 3c40d72a40de556398717e598111ffe994fff684..0bcae1493b97079ebe17d91b48ee701e90c3aa10 100644 (file)
@@ -8,6 +8,9 @@
 #include <sys/ioctl.h>
 #endif
 
+extern int get_terminal_width(void);
+
+
 #define UL_TTY_KEEPCFLAGS      (1 << 1)
 #define UL_TTY_UTF8            (1 << 2)
 
@@ -79,38 +82,6 @@ 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) {
-               char *end = NULL;
-               long c;
-
-               errno = 0;
-               c = strtol(cp, &end, 10);
-
-               if (errno == 0 && end && *end == '\0' && end > cp &&
-                   c > 0 && c <= INT_MAX)
-                       return c;
-       }
-       return 0;
-}
 
 
 #endif /* UTIL_LINUX_TTYUTILS_H */
index bfe6471b2d0301d3ccff88c0f37aeb8ef8c838cf..59f89e93e4798895ea0dc7d996510504f550137c 100644 (file)
@@ -23,6 +23,7 @@ libcommon_la_SOURCES = \
        lib/sysfs.c \
        lib/tt.c \
        lib/wholedisk.c \
+       lib/ttyutils.c \
        lib/xgetpass.c
 
 if LINUX
diff --git a/lib/ttyutils.c b/lib/ttyutils.c
new file mode 100644 (file)
index 0000000..d37c168
--- /dev/null
@@ -0,0 +1,39 @@
+
+#include <ctype.h>
+
+#include "c.h"
+#include "ttyutils.h"
+
+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) {
+               char *end = NULL;
+               long c;
+
+               errno = 0;
+               c = strtol(cp, &end, 10);
+
+               if (errno == 0 && end && *end == '\0' && end > cp &&
+                   c > 0 && c <= INT_MAX)
+                       return c;
+       }
+       return 0;
+}
+