X-Git-Url: https://git.octo.it/?p=collectd.git;a=blobdiff_plain;f=src%2Fbattery.c;h=20ec2612fde76b0f434a6ac6012ab02f0042bb2e;hp=5a0b089f949fa4d942b94a577e309830d3642d25;hb=a59c14adfa86c823efff87ca797c4d6e6ce32913;hpb=1035fba8812893e50d00a871e3399cc1ece3b384 diff --git a/src/battery.c b/src/battery.c index 5a0b089f..20ec2612 100644 --- a/src/battery.c +++ b/src/battery.c @@ -25,8 +25,8 @@ #include "collectd.h" -#include "common.h" #include "plugin.h" +#include "utils/common/common.h" #if HAVE_MACH_MACH_TYPES_H #include @@ -72,9 +72,9 @@ int battery_read_statefs( void); /* defined in battery_statefs; used by StateFS backend */ -static _Bool report_percent = 0; -static _Bool report_degraded = 0; -static _Bool query_statefs = 0; +static bool report_percent; +static bool report_degraded; +static bool query_statefs; static void battery_submit2(char const *plugin_instance, /* {{{ */ char const *type, char const *type_instance, @@ -336,7 +336,7 @@ static int battery_read(void) /* {{{ */ return 0; } /* }}} int battery_read */ -/* #endif HAVE_IOKIT_IOKITLIB_H || HAVE_IOKIT_PS_IOPOWERSOURCES_H */ + /* #endif HAVE_IOKIT_IOKITLIB_H || HAVE_IOKIT_PS_IOPOWERSOURCES_H */ #elif KERNEL_LINUX /* Reads a file which contains only a number (and optionally a trailing @@ -347,8 +347,7 @@ static int sysfs_file_to_buffer(char const *dir, /* {{{ */ char filename[PATH_MAX]; int status; - ssnprintf(filename, sizeof(filename), "%s/%s/%s", dir, power_supply, - basename); + snprintf(filename, sizeof(filename), "%s/%s/%s", dir, power_supply, basename); status = (int)read_file_contents(filename, buffer, buffer_size - 1); if (status < 0) @@ -411,7 +410,7 @@ static int read_sysfs_callback(char const *dir, /* {{{ */ char const *plugin_instance; char buffer[32]; gauge_t v = NAN; - _Bool discharging = 0; + bool discharging = false; int status; /* Ignore non-battery directories, such as AC power. */ @@ -425,7 +424,7 @@ static int read_sysfs_callback(char const *dir, /* {{{ */ (void)sysfs_file_to_buffer(dir, power_supply, "status", buffer, sizeof(buffer)); if (strcasecmp("Discharging", buffer) == 0) - discharging = 1; + discharging = true; /* FIXME: This is a dirty hack for backwards compatibility: The battery * plugin, for a very long time, has had the plugin_instance @@ -479,7 +478,7 @@ static int read_acpi_full_capacity(char const *dir, /* {{{ */ FILE *fh; - ssnprintf(filename, sizeof(filename), "%s/%s/info", dir, power_supply); + snprintf(filename, sizeof(filename), "%s/%s/info", dir, power_supply); fh = fopen(filename, "r"); if (fh == NULL) return errno; @@ -523,8 +522,8 @@ static int read_acpi_callback(char const *dir, /* {{{ */ gauge_t capacity_charged = NAN; gauge_t capacity_full = NAN; gauge_t capacity_design = NAN; - _Bool charging = 0; - _Bool is_current = 0; + bool charging = false; + bool is_current = false; char const *plugin_instance; char filename[PATH_MAX]; @@ -532,7 +531,7 @@ static int read_acpi_callback(char const *dir, /* {{{ */ FILE *fh; - ssnprintf(filename, sizeof(filename), "%s/%s/state", dir, power_supply); + snprintf(filename, sizeof(filename), "%s/%s/state", dir, power_supply); fh = fopen(filename, "r"); if (fh == NULL) { if ((errno == EAGAIN) || (errno == EINTR) || (errno == ENOENT)) @@ -561,9 +560,9 @@ static int read_acpi_callback(char const *dir, /* {{{ */ if ((strcmp(fields[0], "charging") == 0) && (strcmp(fields[1], "state:") == 0)) { if (strcmp(fields[2], "charging") == 0) - charging = 1; + charging = true; else - charging = 0; + charging = false; continue; } @@ -576,7 +575,7 @@ static int read_acpi_callback(char const *dir, /* {{{ */ strtogauge(fields[2], &power); if ((numfields >= 4) && (strcmp("mA", fields[3]) == 0)) - is_current = 1; + is_current = true; } else if ((strcmp(fields[0], "remaining") == 0) && (strcmp(fields[1], "capacity:") == 0)) strtogauge(fields[2], &capacity_charged); @@ -641,11 +640,11 @@ static int read_pmu(void) /* {{{ */ gauge_t voltage = NAN; gauge_t charge = NAN; - ssnprintf(filename, sizeof(filename), PROC_PMU_PATH_FORMAT, i); + snprintf(filename, sizeof(filename), PROC_PMU_PATH_FORMAT, i); if (access(filename, R_OK) != 0) break; - ssnprintf(plugin_instance, sizeof(plugin_instance), "%i", i); + snprintf(plugin_instance, sizeof(plugin_instance), "%i", i); fh = fopen(filename, "r"); if (fh == NULL) {