aboutsummaryrefslogtreecommitdiffstats
path: root/BatteryMeter.c
diff options
context:
space:
mode:
authorEugene V. Lyubimkin <jackyf@debian.org>2012-02-19 10:24:46 +0200
committerDaniel Lange <DLange@git.local>2016-04-11 13:00:30 +0200
commit283008ba7667dcbd771707c7245e6d42acd72478 (patch)
treee3e2447339bd70fbeb1c211886f95e6292a6d491 /BatteryMeter.c
parentc65eb8be811f59b55d64d9e7654c33708de79ad9 (diff)
parente2b58f0ab81b2aafeb8c29a69abad7829fa21ab3 (diff)
downloaddebian_htop-283008ba7667dcbd771707c7245e6d42acd72478.tar.gz
debian_htop-283008ba7667dcbd771707c7245e6d42acd72478.tar.bz2
debian_htop-283008ba7667dcbd771707c7245e6d42acd72478.zip
Imported Debian patch 1.0.1-1debian/1.0.1-1
Diffstat (limited to 'BatteryMeter.c')
-rw-r--r--BatteryMeter.c52
1 files changed, 21 insertions, 31 deletions
diff --git a/BatteryMeter.c b/BatteryMeter.c
index f7323aa..071efd5 100644
--- a/BatteryMeter.c
+++ b/BatteryMeter.c
@@ -1,20 +1,25 @@
/*
- htop
- (C) 2004-2011 Hisham H. Muhammad
- Released under the GNU GPL, see the COPYING file
- in the source distribution for its full text.
+htop - BatteryMeter.c
+(C) 2004-2011 Hisham H. Muhammad
+Released under the GNU GPL, see the COPYING file
+in the source distribution for its full text.
- This "Meter" written by Ian P. Hands (iphands@gmail.com, ihands@redhat.com).
+This meter written by Ian P. Hands (iphands@gmail.com, ihands@redhat.com).
*/
#include "BatteryMeter.h"
-#include "Meter.h"
+
#include "ProcessList.h"
#include "CRT.h"
#include "String.h"
-#include "debug.h"
+
+#include <string.h>
+#include <stdlib.h>
+#include <dirent.h>
+#include <unistd.h>
/*{
+#include "Meter.h"
typedef enum ACPresence_ {
AC_ABSENT,
@@ -45,17 +50,11 @@ static unsigned long int parseUevent(FILE * file, const char *key) {
}
static unsigned long int parseBatInfo(const char *fileName, const unsigned short int lineNum, const unsigned short int wordNum) {
- DIR* batteryDir;
- const struct dirent *dirEntries;
-
const char batteryPath[] = PROCDIR "/acpi/battery/";
- batteryDir = opendir(batteryPath);
-
- if (batteryDir == NULL) {
+ DIR* batteryDir = opendir(batteryPath);
+ if (!batteryDir)
return 0;
- }
- char *entryName;
typedef struct listLbl {
char *content;
struct listLbl *next;
@@ -68,8 +67,8 @@ static unsigned long int parseBatInfo(const char *fileName, const unsigned short
Some of this is based off of code found in kismet (they claim it came from gkrellm).
Written for multi battery use...
*/
- for (dirEntries = readdir((DIR *) batteryDir); dirEntries; dirEntries = readdir((DIR *) batteryDir)) {
- entryName = (char *) dirEntries->d_name;
+ for (const struct dirent* dirEntries = readdir((DIR *) batteryDir); dirEntries; dirEntries = readdir((DIR *) batteryDir)) {
+ char* entryName = (char *) dirEntries->d_name;
if (strncmp(entryName, "BAT", 3))
continue;
@@ -117,22 +116,16 @@ static ACPresence chkIsOnline() {
ACPresence isOn = AC_ERROR;
if (access(PROCDIR "/acpi/ac_adapter", F_OK) == 0) {
- const struct dirent *dirEntries;
const char *power_supplyPath = PROCDIR "/acpi/ac_adapter";
DIR *power_supplyDir = opendir(power_supplyPath);
- char *entryName;
-
- if (!power_supplyDir) {
+ if (!power_supplyDir)
return AC_ERROR;
- }
- for (dirEntries = readdir((DIR *) power_supplyDir); dirEntries; dirEntries = readdir((DIR *) power_supplyDir)) {
- entryName = (char *) dirEntries->d_name;
+ for (const struct dirent *dirEntries = readdir((DIR *) power_supplyDir); dirEntries; dirEntries = readdir((DIR *) power_supplyDir)) {
+ char* entryName = (char *) dirEntries->d_name;
- if (strncmp(entryName, "A", 1)) {
+ if (entryName[0] != 'A')
continue;
- }
-
char statePath[50];
snprintf((char *) statePath, sizeof statePath, "%s/%s/state", power_supplyPath, entryName);
@@ -242,11 +235,8 @@ static double getSysBatData() {
const struct dirent *dirEntries;
const char *power_supplyPath = "/sys/class/power_supply/";
DIR *power_supplyDir = opendir(power_supplyPath);
-
-
- if (!power_supplyDir) {
+ if (!power_supplyDir)
return 0;
- }
char *entryName;

© 2014-2024 Faster IT GmbH | imprint | privacy policy