From c414d49e4816add61e92b16e502662b93c3a34a1 Mon Sep 17 00:00:00 2001 From: Nicholas Hughart Date: Mon, 22 Sep 2008 14:23:15 +0000 Subject: [PATCH] That's what I get for applying patches without looking at them well enough. Fix up a few bugs in the patch received, let me know if there are issues with it. SVN revision: 36169 --- src/modules/battery/batget.c | 29 ++++++++++++++++++----------- 1 file changed, 18 insertions(+), 11 deletions(-) diff --git a/src/modules/battery/batget.c b/src/modules/battery/batget.c index 308304902..cc9da8225 100644 --- a/src/modules/battery/batget.c +++ b/src/modules/battery/batget.c @@ -607,18 +607,25 @@ static int linux_sys_class_power_supply_is_battery(char *name) { int fd; - char buf[255]; - char tmp[255]; + int ret = 0; + char buf[256]; - memset(tmp, 0, 255); - snprintf(buf, 255, "/sys/class/power_supply/%s/type", name); - if (!(fd = open(buf, O_RDONLY))) - return 0; - if (read(fd, tmp, 255) < 1) - return 0; - if (!strncmp(tmp, "Battery", 7)) - return 1; - return 0; + snprintf(buf, sizeof(buf), "/sys/class/power_supply/%s/type", name); + fd = open(buf, O_RDONLY); + if (fd < 0) + { + ret = 0; + goto NO_OPEN; + } + else if (read(fd, buf, sizeof(buf)) < 1) + ret = 0; + else if (!strncmp(buf, "Battery", 7)) + ret = 1; + + close(fd); + + NO_OPEN: + return ret; } static void