From 005f83adf511ab89296639abbef737ad4e5826f9 Mon Sep 17 00:00:00 2001 From: Glenn L McGrath Date: Mon, 1 Sep 2003 08:53:32 +0000 Subject: [PATCH] Fix compile error and reducing size for libbb/get_console.c to previous size. Vodz last_patch106 --- libbb/get_console.c | 72 +++++++++++++++++---------------------------- shell/ash.c | 4 +-- 2 files changed, 29 insertions(+), 47 deletions(-) diff --git a/libbb/get_console.c b/libbb/get_console.c index 9eb4190a9..0dc24cb78 100644 --- a/libbb/get_console.c +++ b/libbb/get_console.c @@ -2,8 +2,8 @@ /* * Utility routines. * - * Copyright (C) many different people. - * If you wrote this, please acknowledge your work. + * Copyright (C) many different people. If you wrote this, please + * acknowledge your work. * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -29,27 +29,15 @@ - - /* From */ static const int KDGKBTYPE = 0x4B33; /* get keyboard type */ -static const int KB_84 = 0x01; -static const int KB_101 = 0x02; /* this is what we always answer */ -static int is_a_console(int fd) -{ - char arg; - arg = 0; - return (ioctl(fd, KDGKBTYPE, &arg) == 0 - && ((arg == KB_101) || (arg == KB_84))); -} - -static int open_a_console(char *fnam) +static int open_a_console(const char *fnam) { int fd; - /* try read-only */ + /* try read-write */ fd = open(fnam, O_RDWR); /* if failed, try read-only */ @@ -60,17 +48,6 @@ static int open_a_console(char *fnam) if (fd < 0 && errno == EACCES) fd = open(fnam, O_WRONLY); - /* if failed, fail */ - if (fd < 0) - return -1; - - /* if not a console, fail */ - if (!is_a_console(fd)) { - close(fd); - return -1; - } - - /* success */ return fd; } @@ -78,32 +55,37 @@ static int open_a_console(char *fnam) * Get an fd for use with kbd/console ioctls. * We try several things because opening /dev/console will fail * if someone else used X (which does a chown on /dev/console). - * - * if tty_name is non-NULL, try this one instead. */ int get_console_fd(void) { int fd; - fd = open_a_console(CURRENT_TTY); - if (fd >= 0) - return fd; - - fd = open_a_console(CURRENT_VC); - if (fd >= 0) - return fd; - - fd = open_a_console(CONSOLE_DEV); - if (fd >= 0) - return fd; - - for (fd = 0; fd < 3; fd++) - if (is_a_console(fd)) - return fd; + static const char * const choise_console_names[] = { + CONSOLE_DEV, CURRENT_VC, CURRENT_TTY + }; + + for (fd = 2; fd >= 0; fd--) { + int fd4name; + int choise_fd; + char arg; + + fd4name = open_a_console(choise_console_names[fd]); + chk_std: + choise_fd = fd4name >= 0 ? fd4name : fd; + + arg = 0; + if (ioctl(choise_fd, KDGKBTYPE, &arg) == 0) + return choise_fd; + if(fd4name >= 0) { + close(fd4name); + fd4name = -1; + goto chk_std; + } + } bb_error_msg("Couldn't get a file descriptor referring to the console"); - return -1; /* total failure */ + return fd; /* total failure */ } diff --git a/shell/ash.c b/shell/ash.c index ec33a106c..521d65ab6 100644 --- a/shell/ash.c +++ b/shell/ash.c @@ -5628,7 +5628,7 @@ expmeta(char *enddir, char *name) char *start; char *endname; int metaflag; - struct stat64 statb; + struct stat statb; DIR *dirp; struct dirent *dp; int atend; @@ -5671,7 +5671,7 @@ out: p++; *enddir++ = *p; } while (*p++); - if (metaflag == 0 || lstat64(expdir, &statb) >= 0) + if (metaflag == 0 || lstat(expdir, &statb) >= 0) addfname(expdir); return; } -- 2.25.1