From 4189824ffb6b8090f36e40b1d7939764ea834540 Mon Sep 17 00:00:00 2001 From: Tommie Gannert Date: Mon, 1 Aug 2016 11:29:18 +0100 Subject: Define IW_ESSID_MAX_SIZE for OpenBSD. Also fixes a signedness warning. --- src/print_wireless_info.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/print_wireless_info.c b/src/print_wireless_info.c index 25e167f..70dbdb4 100644 --- a/src/print_wireless_info.c +++ b/src/print_wireless_info.c @@ -54,6 +54,7 @@ #include #include #include +#define IW_ESSID_MAX_SIZE IEEE80211_NWID_LEN #endif #include "i3status.h" @@ -423,7 +424,7 @@ error1: else len = IEEE80211_NWID_LEN + 1; - strncpy(&info->essid[0], nwid.i_nwid, len); + strncpy(&info->essid[0], (char *)nwid.i_nwid, len); info->essid[IW_ESSID_MAX_SIZE] = '\0'; info->flags |= WIRELESS_INFO_FLAG_HAS_ESSID; } -- cgit v1.2.3 From 185d70ecbb2470468ab34229e6c461094a4cceb8 Mon Sep 17 00:00:00 2001 From: Tommie Gannert Date: Mon, 1 Aug 2016 11:37:47 +0100 Subject: Remove warnings about unused variables in slurp_battery_info on OpenBSD. --- src/print_battery_info.c | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/src/print_battery_info.c b/src/print_battery_info.c index f548dfa..c18c725 100644 --- a/src/print_battery_info.c +++ b/src/print_battery_info.c @@ -40,6 +40,7 @@ struct battery_info { * * Assumes a constant (dis)charge rate. */ +#if defined(LINUX) || defined(__NetBSD__) static int seconds_remaining_from_rate(charging_status_t status, float full_design, float remaining, float present_rate) { if (status == CS_CHARGING) return 3600.0 * (full_design - remaining) / present_rate; @@ -48,17 +49,18 @@ static int seconds_remaining_from_rate(charging_status_t status, float full_desi else return 0; } +#endif static bool slurp_battery_info(struct battery_info *batt_info, yajl_gen json_gen, char *buffer, int number, const char *path, const char *format_down, bool last_full_capacity) { + char *outwalk = buffer; + +#if defined(LINUX) char buf[1024]; const char *walk, *last; - char *outwalk = buffer; bool watt_as_unit = false; int full_design = -1, remaining = -1, voltage = -1; - -#if defined(LINUX) char batpath[512]; sprintf(batpath, path, number); INSTANCE(batpath); @@ -177,8 +179,6 @@ static bool slurp_battery_info(struct battery_info *batt_info, yajl_gen json_gen batt_info->status = CS_CHARGING; else batt_info->status = CS_DISCHARGING; - - full_design = sysctl_rslt; #elif defined(__OpenBSD__) /* * We're using apm(4) here, which is the interface to acpi(4) on amd64/i386 and @@ -228,6 +228,10 @@ static bool slurp_battery_info(struct battery_info *batt_info, yajl_gen json_gen /* * Using envsys(4) via sysmon(4). */ + bool watt_as_unit = false; + int full_design = -1, + remaining = -1, + voltage = -1; int fd, rval, last_full_cap; bool is_found = false; char *sensor_desc; -- cgit v1.2.3 From 7728cff37044943b05c4f9de5e9c6ef3d9e14a12 Mon Sep 17 00:00:00 2001 From: Tommie Gannert Date: Mon, 1 Aug 2016 14:34:39 +0100 Subject: Make print_disk_info, print_eth_info and print_wireless_info compile on NetBSD without warnings. --- src/print_disk_info.c | 6 ++++++ src/print_eth_info.c | 2 +- src/print_wireless_info.c | 6 ++++++ 3 files changed, 13 insertions(+), 1 deletion(-) diff --git a/src/print_disk_info.c b/src/print_disk_info.c index 629e05b..edc69ac 100644 --- a/src/print_disk_info.c +++ b/src/print_disk_info.c @@ -10,6 +10,7 @@ #if defined(__FreeBSD__) || defined(__FreeBSD_kernel__) || (__OpenBSD__) || defined(__DragonFly__) || defined(__APPLE__) #include #include +#elif defined(__NetBSD__) #else #include #endif @@ -121,6 +122,11 @@ void print_disk_info(yajl_gen json_gen, char *buffer, const char *path, const ch if (statfs(path, &buf) == -1) return; +#elif defined(__NetBSD__) + struct statvfs buf; + + if (statvfs(path, &buf) == -1) + return; #else struct statvfs buf; diff --git a/src/print_eth_info.c b/src/print_eth_info.c index 34ffa36..e4bf15e 100644 --- a/src/print_eth_info.c +++ b/src/print_eth_info.c @@ -79,7 +79,7 @@ static int print_eth_speed(char *outwalk, const char *interface) { ethspeed = (desc->ifmt_string != NULL ? desc->ifmt_string : "?"); return sprintf(outwalk, "%s", ethspeed); #elif defined(__OpenBSD__) || defined(__NetBSD__) - char *ethspeed; + const char *ethspeed; struct ifmediareq ifmr; (void)memset(&ifmr, 0, sizeof(ifmr)); diff --git a/src/print_wireless_info.c b/src/print_wireless_info.c index 70dbdb4..14879eb 100644 --- a/src/print_wireless_info.c +++ b/src/print_wireless_info.c @@ -57,6 +57,12 @@ #define IW_ESSID_MAX_SIZE IEEE80211_NWID_LEN #endif +#ifdef __NetBSD__ +#include +#include +#define IW_ESSID_MAX_SIZE IEEE80211_NWID_LEN +#endif + #include "i3status.h" #define WIRELESS_INFO_FLAG_HAS_ESSID (1 << 0) -- cgit v1.2.3 From a937693cefd664b7f259713ed1fdddc4cc7ad188 Mon Sep 17 00:00:00 2001 From: Tommie Gannert Date: Mon, 1 Aug 2016 20:28:16 +0100 Subject: Simplify string comparisons in slurp_battery_info for NetBSD. Doing strlen(a) == strlen(b) && strncmp(a, b, N) seems to have no benefits compared to just strcmp(a, b). The NetBSD cstring properties come from the kernel, not the user. The test for units did a prefix match, but that looked like a bug, the unit is "Watt hour" in my Virtual box. --- src/print_battery_info.c | 58 +++++++++--------------------------------------- 1 file changed, 11 insertions(+), 47 deletions(-) diff --git a/src/print_battery_info.c b/src/print_battery_info.c index c18c725..3e97528 100644 --- a/src/print_battery_info.c +++ b/src/print_battery_info.c @@ -272,10 +272,8 @@ static bool slurp_battery_info(struct battery_info *batt_info, yajl_gen json_gen /* iterate over the dictionary returned by the kernel */ while ((obj = prop_object_iterator_next(iter)) != NULL) { /* skip this dict if it's not what we're looking for */ - if ((strlen(prop_dictionary_keysym_cstring_nocopy(obj)) == strlen(sensor_desc)) && - (strncmp(sensor_desc, - prop_dictionary_keysym_cstring_nocopy(obj), - strlen(sensor_desc)) != 0)) + if (strcmp(sensor_desc, + prop_dictionary_keysym_cstring_nocopy(obj)) != 0) continue; is_found = true; @@ -300,26 +298,17 @@ static bool slurp_battery_info(struct battery_info *batt_info, yajl_gen json_gen while ((obj2 = prop_object_iterator_next(iter2)) != NULL) { obj3 = prop_dictionary_get(obj2, "description"); - if (obj3 && - strlen(prop_string_cstring_nocopy(obj3)) == 8 && - strncmp("charging", - prop_string_cstring_nocopy(obj3), - 8) == 0) { + if (obj3 == NULL) + continue; + + if (strcmp("charging", prop_string_cstring_nocopy(obj3)) == 0) { obj3 = prop_dictionary_get(obj2, "cur-value"); if (prop_number_integer_value(obj3)) batt_info->status = CS_CHARGING; else batt_info->status = CS_DISCHARGING; - - continue; - } - - if (obj3 && - strlen(prop_string_cstring_nocopy(obj3)) == 6 && - strncmp("charge", - prop_string_cstring_nocopy(obj3), - 6) == 0) { + } else if (strcmp("charge", prop_string_cstring_nocopy(obj3)) == 0) { obj3 = prop_dictionary_get(obj2, "cur-value"); obj4 = prop_dictionary_get(obj2, "max-value"); obj5 = prop_dictionary_get(obj2, "type"); @@ -330,44 +319,19 @@ static bool slurp_battery_info(struct battery_info *batt_info, yajl_gen json_gen if (remaining == full_design) is_full = true; - if (strncmp("Ampere hour", - prop_string_cstring_nocopy(obj5), - 11) == 0) + if (strcmp("Ampere hour", prop_string_cstring_nocopy(obj5)) == 0) watt_as_unit = false; else watt_as_unit = true; - - continue; - } - - if (obj3 && - strlen(prop_string_cstring_nocopy(obj3)) == 14 && - strncmp("discharge rate", - prop_string_cstring_nocopy(obj3), - 14) == 0) { + } else if (strcmp("discharge rate", prop_string_cstring_nocopy(obj3)) == 0) { obj3 = prop_dictionary_get(obj2, "cur-value"); batt_info->present_rate = prop_number_integer_value(obj3); - continue; - } - - if (obj3 && - strlen(prop_string_cstring_nocopy(obj3)) == 13 && - strncmp("last full cap", - prop_string_cstring_nocopy(obj3), - 13) == 0) { + } else if (strcmp("last full cap", prop_string_cstring_nocopy(obj3)) == 0) { obj3 = prop_dictionary_get(obj2, "cur-value"); last_full_cap = prop_number_integer_value(obj3); - continue; - } - - if (obj3 && - strlen(prop_string_cstring_nocopy(obj3)) == 7 && - strncmp("voltage", - prop_string_cstring_nocopy(obj3), - 7) == 0) { + } else if (strcmp("voltage", prop_string_cstring_nocopy(obj3)) == 0) { obj3 = prop_dictionary_get(obj2, "cur-value"); voltage = prop_number_integer_value(obj3); - continue; } } prop_object_iterator_release(iter2); -- cgit v1.2.3 From eb0b6412af16fe00ce38faa31bd50c238f4e7098 Mon Sep 17 00:00:00 2001 From: Tommie Gannert Date: Sun, 14 Aug 2016 12:35:52 +0100 Subject: Fix warnings about using a char array index on NetBSD. The isspace macro is just a table lookup. --- src/print_battery_info.c | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/src/print_battery_info.c b/src/print_battery_info.c index 3e97528..a97bdea 100644 --- a/src/print_battery_info.c +++ b/src/print_battery_info.c @@ -404,14 +404,14 @@ void print_battery_info(yajl_gen json_gen, char *buffer, int number, const char } } -#define EAT_SPACE_FROM_OUTPUT_IF_NO_OUTPUT() \ - do { \ - if (outwalk == prevoutwalk) { \ - if (outwalk > buffer && isspace(outwalk[-1])) \ - outwalk--; \ - else if (isspace(*(walk + 1))) \ - walk++; \ - } \ +#define EAT_SPACE_FROM_OUTPUT_IF_NO_OUTPUT() \ + do { \ + if (outwalk == prevoutwalk) { \ + if (outwalk > buffer && isspace((int)outwalk[-1])) \ + outwalk--; \ + else if (isspace((int)*(walk + 1))) \ + walk++; \ + } \ } while (0) for (walk = format; *walk != '\0'; walk++) { -- cgit v1.2.3