From 6d5b9ba5843cbe250ad9fdcc5022374c92ef4a34 Mon Sep 17 00:00:00 2001 From: Rom Walton Date: Sun, 4 Apr 2004 08:25:26 +0000 Subject: [PATCH] *** empty log message *** svn path=/trunk/boinc/; revision=3220 --- client/hostinfo_unix.C | 25 +++++++++++++++++-------- 1 file changed, 17 insertions(+), 8 deletions(-) diff --git a/client/hostinfo_unix.C b/client/hostinfo_unix.C index 08b3b9ad92..974df61945 100644 --- a/client/hostinfo_unix.C +++ b/client/hostinfo_unix.C @@ -108,26 +108,35 @@ int get_timezone() { // bool HOST_INFO::host_is_running_on_batteries() { #ifdef linux - float x1, x2; - int i1, i2; - bool on_batteries = false; + bool retval = false; + char apm_driver_version[10]; + int apm_major_version; + int apm_minor_version; + int apm_flags; + int apm_ac_line_status=1; FILE* fapm = fopen("/proc/apm", "r"); FILE* facpi = fopen("/proc/acpi/ac_adapter/ACAD/state", "r"); if (fapm) { // Then we're using APM! Yay. - // Supposedly we're on batteries if the 4th entry is zero. + // Supposedly we're on batteries if the 5th entry is zero. // - fscanf(fapm, "%f %f %x %x", &x1, &x2, &i1, &i2); + fscanf(f, "%10s %d.%d %x %x", + apm_driver_version, + &apm_major_version, + &apm_minor_version, + &apm_flags, + &apm_ac_line_status + ); fclose(fapm); - if (i2 == 0) on_batteries = true; + retval = (apm_ac_line_status == 0); } else if (facpi) { // The 27th letter is f if they're on AC and n if they're on battery fseek(facpi, 26, 0); - if (fgetc(facpi) == 'n') on_batteries = true; + if (fgetc(facpi) == 'n') retval = true; fclose(facpi); } - return on_batteries; + return retval; #else return false; #endif