diff options
author | Daniel Lange <DLange@git.local> | 2020-08-27 07:48:11 +0200 |
---|---|---|
committer | Daniel Lange <DLange@git.local> | 2020-08-27 07:48:11 +0200 |
commit | 7a637ff1dea1a02a42e55aa79f03a9e85a576207 (patch) | |
tree | 3d12e9808eb554ad8017fcd9059864f92d51d104 /linux/Battery.c | |
parent | dfb05211d32675faebac6fd76ef58d9e303a90e7 (diff) | |
parent | f3147ea2d1598914c2db53e8cfb34c8ff81e2ff4 (diff) | |
download | debian_htop-7a637ff1dea1a02a42e55aa79f03a9e85a576207.tar.gz debian_htop-7a637ff1dea1a02a42e55aa79f03a9e85a576207.tar.bz2 debian_htop-7a637ff1dea1a02a42e55aa79f03a9e85a576207.zip |
Update upstream source from tag 'upstream/3.0.0'
Update to upstream version '3.0.0'
with Debian dir 8c9e99b342a3fc4208a5abe239b39578f8563a2c
Diffstat (limited to 'linux/Battery.c')
-rw-r--r-- | linux/Battery.c | 38 |
1 files changed, 24 insertions, 14 deletions
diff --git a/linux/Battery.c b/linux/Battery.c index aedacab..4014a50 100644 --- a/linux/Battery.c +++ b/linux/Battery.c @@ -64,7 +64,7 @@ static unsigned long int parseBatInfo(const char *fileName, const unsigned short } char* line = NULL; - for (unsigned short int i = 0; i < lineNum; i++) { + for (unsigned short int j = 0; j < lineNum; j++) { free(line); line = String_readLine(file); if (!line) break; @@ -78,7 +78,7 @@ static unsigned long int parseBatInfo(const char *fileName, const unsigned short const unsigned long int foundNum = atoi(foundNumStr); free(foundNumStr); free(line); - + total += foundNum; } @@ -175,7 +175,7 @@ static inline ssize_t xread(int fd, void *buf, size_t count) { } static void Battery_getSysData(double* level, ACPresence* isOnAC) { - + *level = 0; *isOnAC = AC_ERROR; @@ -193,17 +193,27 @@ static void Battery_getSysData(double* level, ACPresence* isOnAC) { char* entryName = (char *) dirEntry->d_name; const char filePath[50]; - if (entryName[0] == 'B' && entryName[1] == 'A' && entryName[2] == 'T') { - + xSnprintf((char *) filePath, sizeof filePath, SYS_POWERSUPPLY_DIR "/%s/type", entryName); + int fd1 = open(filePath, O_RDONLY); + if (fd1 == -1) + continue; + + char type[8]; + ssize_t typelen = xread(fd1, type, 7); + close(fd1); + if (typelen < 1) + continue; + + if (type[0] == 'B' && type[1] == 'a' && type[2] == 't') { xSnprintf((char *) filePath, sizeof filePath, SYS_POWERSUPPLY_DIR "/%s/uevent", entryName); - int fd = open(filePath, O_RDONLY); - if (fd == -1) { + int fd2 = open(filePath, O_RDONLY); + if (fd2 == -1) { closedir(dir); return; } char buffer[1024]; - ssize_t buflen = xread(fd, buffer, 1023); - close(fd); + ssize_t buflen = xread(fd2, buffer, 1023); + close(fd2); if (buflen < 1) { closedir(dir); return; @@ -247,20 +257,20 @@ static void Battery_getSysData(double* level, ACPresence* isOnAC) { if (*isOnAC != AC_ERROR) { continue; } - + xSnprintf((char *) filePath, sizeof filePath, SYS_POWERSUPPLY_DIR "/%s/online", entryName); - int fd = open(filePath, O_RDONLY); - if (fd == -1) { + int fd3 = open(filePath, O_RDONLY); + if (fd3 == -1) { closedir(dir); return; } char buffer[2] = ""; for(;;) { - ssize_t res = read(fd, buffer, 1); + ssize_t res = read(fd3, buffer, 1); if (res == -1 && errno == EINTR) continue; break; } - close(fd); + close(fd3); if (buffer[0] == '0') { *isOnAC = AC_ABSENT; } else if (buffer[0] == '1') { |