aboutsummaryrefslogtreecommitdiff
path: root/lowbat.c
diff options
context:
space:
mode:
authorTim Keller <tjkeller.xyz>2024-11-21 21:10:46 -0600
committerTim Keller <tjkeller.xyz>2024-11-21 21:10:46 -0600
commit7f331782d9aa176e63fa1bddf88a0cccbe2096df (patch)
treebd74a34df71fec2ac6c791a475fef42a5bf4ffdf /lowbat.c
parent3ab85464ff92c57a33945a32a8a00df5a9abb684 (diff)
downloadlowbat-1.2.1.tar.xz
lowbat-1.2.1.zip
bump ver and get rid of compiler warningsHEADv1.2.1master
Diffstat (limited to 'lowbat.c')
-rw-r--r--lowbat.c12
1 files changed, 8 insertions, 4 deletions
diff --git a/lowbat.c b/lowbat.c
index b5fb665..b56f40b 100644
--- a/lowbat.c
+++ b/lowbat.c
@@ -21,7 +21,7 @@ static char batteries[MAX_BATTERIES][MAX_PSU_NAME_LEN];
static unsigned int num_batteries;
static FILE *fp;
static char prop_path[MAX_PROP_PATH_LEN];
-static enum StatusSymbols { UNKNOWN = '?', CHARGING = '+', DISCHARGING = '-', NOT_CHARGING = '=', FULL = '=' };
+enum StatusSymbols { UNKNOWN = '?', CHARGING = '+', DISCHARGING = '-', NOT_CHARGING = '=', FULL = '=' };
// functions
void load_installed_batteries() {
@@ -60,7 +60,8 @@ void load_installed_batteries() {
fprintf(stderr, "maximum number of batteries (8) exceeded\n");
exit(EXIT_FAILURE);
}
- strncpy(batteries[num_batteries], entry->d_name, MAX_PSU_NAME_LEN);
+ memcpy(batteries[num_batteries], entry->d_name, MAX_PSU_NAME_LEN);
+ batteries[num_batteries][MAX_PSU_NAME_LEN-1] = '\0';
num_batteries++;
break;
}
@@ -86,11 +87,14 @@ void read_prop(char *psu, char *prop, char *fmt, void *out) {
snprintf(prop_path, MAX_PROP_PATH_LEN, PSUPATH "/%s/%s", psu, prop);
if ((fp = fopen(prop_path, "r")) != NULL) {
- fscanf(fp, fmt, out);
+ if (fscanf(fp, fmt, out) != 1) {
+ fprintf(stderr, "failed to scan property %s with format '%s'\n", fmt, prop_path);
+ exit(EXIT_FAILURE);
+ }
fclose(fp);
}
else {
- fprintf(stderr, "failed to read fmt '%s' from property %s\n", fmt, prop_path);
+ fprintf(stderr, "failed to open %s\n", prop_path);
exit(EXIT_FAILURE);
}
}