From 7f331782d9aa176e63fa1bddf88a0cccbe2096df Mon Sep 17 00:00:00 2001 From: Tim Keller Date: Thu, 21 Nov 2024 21:10:46 -0600 Subject: bump ver and get rid of compiler warnings --- lowbat.c | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) (limited to 'lowbat.c') 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); } } -- cgit v1.2.3