Fixed cast that caused infinite loop on x86_64 platforms (issue #1).

git-svn-id: https://logkeys.googlecode.com/svn/trunk@25 c501e62c-e7d1-11de-a198-37193048d1ed
This commit is contained in:
kernc 2010-02-25 04:05:10 +00:00
parent c54667d376
commit fad35522a9

View File

@ -17,7 +17,9 @@
#include <sys/file.h> #include <sys/file.h>
#include <linux/input.h> #include <linux/input.h>
#include <config.h> // config produced from ./configure #ifdef HAVE_CONFIG_H
# include <config.h> // include config produced from ./configure
#endif
#define DEFAULT_LOG_FILE "/var/log/logkeys.log" #define DEFAULT_LOG_FILE "/var/log/logkeys.log"
#define TMP_PID_FILE "/tmp/logkeys.pid.lock" #define TMP_PID_FILE "/tmp/logkeys.pid.lock"
@ -33,6 +35,10 @@
// better yet, use ./configure --enable-evdev=DEV to specify INPUT_EVENT_DEVICE ! // better yet, use ./configure --enable-evdev=DEV to specify INPUT_EVENT_DEVICE !
#endif//INPUT_EVENT_DEVICE #endif//INPUT_EVENT_DEVICE
#ifndef PACKAGE_VERSION
# define PACKAGE_VERSION "0.1.0" // if PACKAGE_VERSION wasn't defined in <config.h>
#endif
void usage() { void usage() {
fprintf(stderr, fprintf(stderr,
"Usage: logkeys [OPTION]...\n" "Usage: logkeys [OPTION]...\n"
@ -305,7 +311,7 @@ int main(int argc, char **argv) {
// replace any U+#### with 0x#### for easier parsing // replace any U+#### with 0x#### for easier parsing
index = line.find("U+", 0); index = line.find("U+", 0);
while ((unsigned int) index != std::string::npos) { while (static_cast<std::string::size_type>(index) != std::string::npos) {
line[index] = '0'; line[index + 1] = 'x'; line[index] = '0'; line[index + 1] = 'x';
index = line.find("U+", index); index = line.find("U+", index);
} }
@ -388,11 +394,11 @@ int main(int argc, char **argv) {
} //\ if (flag_export) } //\ if (flag_export)
} }
#ifndef INPUT_EVENT_DEVICE // sometimes X in /dev/input/eventX is different from one reboot to another #ifndef INPUT_EVENT_DEVICE // sometimes X in /dev/input/eventX is different from one reboot to another, in that case, determine it dynamically
char *INPUT_EVENT_DEVICE; char *INPUT_EVENT_DEVICE;
if (device_filename == NULL) { // no device given with -d switch, determine it automatically if (device_filename == NULL) { // no device given with -d switch
// extract input number from /proc/bus/input/devices (I don't know how to do it better. If you have an idea, please let me know.) // extract input number from /proc/bus/input/devices (I don't know how to do it better. If you have an idea, please let me know.)
std::string output = exec("grep Name /proc/bus/input/devices | grep -nE '[Kk]eyboard|kbd'"); std::string output = exec("grep Name /proc/bus/input/devices | grep -nE '[Kk]eyboard|kbd'");
if (output == "ERR") { // if pipe errors, exit if (output == "ERR") { // if pipe errors, exit