diff options
Diffstat (limited to 'lib/ttyutils.c')
-rw-r--r-- | lib/ttyutils.c | 15 |
1 files changed, 13 insertions, 2 deletions
diff --git a/lib/ttyutils.c b/lib/ttyutils.c index 4e62c20d6..06dd800f7 100644 --- a/lib/ttyutils.c +++ b/lib/ttyutils.c @@ -5,6 +5,7 @@ * Written by Karel Zak <kzak@redhat.com> */ #include <ctype.h> +#include <unistd.h> #include "c.h" #include "ttyutils.h" @@ -42,13 +43,14 @@ int get_terminal_width(int default_width) return width > 0 ? width : default_width; } -int get_terminal_name(int fd, - const char **path, +int get_terminal_name(const char **path, const char **name, const char **number) { const char *tty; const char *p; + int fd; + if (name) *name = NULL; @@ -57,6 +59,15 @@ int get_terminal_name(int fd, if (number) *number = NULL; + if (isatty(STDIN_FILENO)) + fd = STDIN_FILENO; + else if (isatty(STDOUT_FILENO)) + fd = STDOUT_FILENO; + else if (isatty(STDERR_FILENO)) + fd = STDERR_FILENO; + else + return -1; + tty = ttyname(fd); if (!tty) return -1; |