diff options
Diffstat (limited to 'src/getfd.c')
-rw-r--r-- | src/getfd.c | 28 |
1 files changed, 21 insertions, 7 deletions
diff --git a/src/getfd.c b/src/getfd.c index 2ddcf01..69c37a3 100644 --- a/src/getfd.c +++ b/src/getfd.c @@ -1,15 +1,21 @@ /* - * Copied from kbd-1.12 + * Adapted from kbd-1.12 * License: GPL * */ +#include "config.h" + #include <stdio.h> #include <fcntl.h> #include <errno.h> #include <linux/kd.h> #include <sys/ioctl.h> +#ifdef HAVE_PATHS_H +#include <paths.h> +#endif /* HAVE_PATHS_H */ + /* * getfd.c * @@ -24,7 +30,7 @@ is_a_console (int fd) char arg; arg = 0; - return (ioctl(fd, KDGKBTYPE, &arg) == 0 + return (ioctl (fd, KDGKBTYPE, &arg) == 0 && ((arg == KB_101) || (arg == KB_84))); } @@ -33,10 +39,10 @@ open_a_console (char *fnam) { int fd; - fd = open(fnam, O_RDONLY); + fd = open (fnam, O_RDONLY); if (fd < 0 && errno == EACCES) fd = open(fnam, O_WRONLY); - if (fd < 0 || ! is_a_console(fd)) + if (fd < 0 || ! is_a_console (fd)) return -1; return fd; } @@ -45,16 +51,24 @@ int getfd (void) { int fd; - fd = open_a_console("/dev/tty"); + fd = open_a_console (_PATH_TTY); + if (fd >= 0) + return fd; + + fd = open_a_console ("/dev/tty"); + if (fd >= 0) + return fd; + + fd = open_a_console (_PATH_CONSOLE); if (fd >= 0) return fd; - fd = open_a_console("/dev/console"); + fd = open_a_console ("/dev/console"); if (fd >= 0) return fd; for (fd = 0; fd < 3; fd++) - if (is_a_console(fd)) + if (is_a_console (fd)) return fd; return -1; |