diff options
author | William Jon McCann <mccann@jhu.edu> | 2007-03-06 16:07:24 -0500 |
---|---|---|
committer | William Jon McCann <mccann@jhu.edu> | 2007-03-06 16:07:24 -0500 |
commit | dc5e9585215f34ec78b68fbb6da990a90d8f3a1b (patch) | |
tree | ed64be3c15a74a9f98083d2ad0bdf6bcc973caf7 /src | |
parent | ce4ee7b54d40faf13e005285e5b85a061f21e256 (diff) |
use paths.h if available
Diffstat (limited to 'src')
-rw-r--r-- | src/ck-seat.c | 11 | ||||
-rw-r--r-- | src/getfd.c | 28 | ||||
-rw-r--r-- | src/proc-linux.c | 10 |
3 files changed, 37 insertions, 12 deletions
diff --git a/src/ck-seat.c b/src/ck-seat.c index 033dc2d..c980ad5 100644 --- a/src/ck-seat.c +++ b/src/ck-seat.c @@ -25,6 +25,13 @@ #include <fcntl.h> #include <unistd.h> #include <string.h> +#ifdef HAVE_PATHS_H +#include <paths.h> +#endif /* HAVE_PATHS_H */ + +#ifndef _PATH_TTY +#define _PATH_TTY "/dev/tty" +#endif #include <glib.h> #include <glib/gi18n.h> @@ -196,7 +203,7 @@ _seat_activate_session (CkSeat *seat, ck_session_get_display_device (session, &device, NULL); - if (device == NULL || (sscanf (device, "/dev/tty%u", &num) != 1)) { + if (device == NULL || (sscanf (device, _PATH_TTY "%u", &num) != 1)) { GError *error; error = g_error_new (CK_SEAT_ERROR, CK_SEAT_ERROR_GENERAL, @@ -480,7 +487,7 @@ update_active_vt (CkSeat *seat, CkSession *session; char *device; - device = g_strdup_printf ("/dev/tty%u", num); + device = g_strdup_printf (_PATH_TTY "%u", num); ck_debug ("Active device: %s", device); 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; diff --git a/src/proc-linux.c b/src/proc-linux.c index 30e7d22..a247e75 100644 --- a/src/proc-linux.c +++ b/src/proc-linux.c @@ -28,6 +28,10 @@ #include <sys/types.h> #include <sys/stat.h> +#ifdef HAVE_PATHS_H +#include <paths.h> +#endif /* HAVE_PATHS_H */ + #include "proc.h" /* adapted from procps */ @@ -107,7 +111,7 @@ load_drivers (void) buf[bytes] = '\0'; p = buf; - while ((p = strstr (p, " /dev/"))){ + while ((p = strstr (p, " " _PATH_DEV))){ tty_map_node *tmn; int len; char *end; @@ -188,7 +192,7 @@ driver_name (guint maj, tmn = tmn->next; } - tty = g_strdup_printf ("/dev/%s%d", tmn->name, min); /* like "/dev/ttyZZ255" */ + tty = g_strdup_printf (_PATH_DEV "%s%d", tmn->name, min); /* like "/dev/ttyZZ255" */ if (stat (tty, &sbuf) < 0){ g_free (tty); @@ -196,7 +200,7 @@ driver_name (guint maj, return NULL; } - tty = g_strdup_printf ("/dev/%s", tmn->name); /* like "/dev/ttyZZ255" */ + tty = g_strdup_printf (_PATH_DEV "%s", tmn->name); /* like "/dev/ttyZZ255" */ if (stat (tty, &sbuf) < 0) { g_free (tty); |