Commits

Thomas Dahms  committed e221551

be consistent; have path static

  • Participants
  • Parent commits ddf6ba1

Comments (0)

Files changed (1)

 void
 readfile(char *str, char *base, char *file)
 {
-	char *path = malloc(strlen(base) + strlen(file) + 1);
+	char path[256];
 	char line[513];
 	FILE *fd;
 
 	sprintf(path, "%s/%s", base, file);
 	fd = fopen(path, "r");
 	if (fd == NULL) {
-		free(path);
 		str = "";
 		return;
 	}
-	free(path);
 
 	if (fgets(line, sizeof(line)-1, fd) == NULL) {
 		str = "";
  * according to a random scheme. So just check for both possibilities.
  */
 void
-getbattery(char *bttry, char *base)
+getbattery(char *str, char *base)
 {
 	char *co = malloc(256);
 	int descap, remcap;
 	readfile(co, base, "present");
 	if (co[0] != '1') {
 		free(co);
-		sprintf(bttry, "not present");
+		sprintf(str, "not present");
 		return;
 	}
 
 		readfile(co, base, "energy_full_design");
 		if (strlen(co) == 0) {
 			free(co);
-			bttry = "";
+			str = "";
 			return;
 		}
 	}
 		readfile(co, base, "energy_now");
 		if (strlen(co) == 0) {
 			free(co);
-			bttry = "";
+			str = "";
 			return;
 		}
 	}
 	free(co);
 
 	if (remcap < 0 || descap < 0) {
-		sprintf(bttry, "invalid");
+		sprintf(str, "invalid");
 		return;
 	}
 
-	sprintf(bttry, "%.0f", ((float)remcap / (float)descap) * 100);
+	sprintf(str, "%.0f", ((float)remcap / (float)descap) * 100);
 }
 
 int