diff --git a/bmon.c b/bmon.c index 6487856..ddd9d0f 100644 --- a/bmon.c +++ b/bmon.c @@ -103,8 +103,9 @@ int main (int argc, char *argv[]) fprintf(stderr, "currently not discharging, cannot read power draw\n"); dead = 1; } + fclose(tmf); free(tmp); - strcat(path, "/energy_now"); + strcat(path, "/power_now"); } else strcat(path, "/capacity"); if ((fp = fopen(path, "r"))) { @@ -135,6 +136,7 @@ int main (int argc, char *argv[]) } long int elapsed_time = 0; + long val; char buf[64]; for (; !dead ; sleep(wait_time)) { for (int i = 0; i < fp_num; i++) { @@ -144,8 +146,8 @@ int main (int argc, char *argv[]) } if (!fgets(buf, 64, fp_list[i])) dead = 1; - buf[strcspn(buf, "\r\n")] = 0; - fprintf(ofile_ptr, "%s\t", buf); + val = atol(buf); + fprintf(ofile_ptr, "%ld\t", wflag ? (long)(val / 1E3) : val); } fprintf(ofile_ptr, "%ld\n", uflag ? time(NULL) : elapsed_time); if (fflush(ofile_ptr)) {