From 97a859c5bd8201911d4492e2440af1227527352d Mon Sep 17 00:00:00 2001 From: nia Date: Tue, 27 Jul 2021 10:40:49 +0200 Subject: netbsd: Use newer proplib API. Create aliases so it works on 9.x. This way we avoid deprecation warnings on the development branch of NetBSD while keeping the code functioning on the stable branch. --- netbsd/Platform.c | 46 ++++++++++++++++++++++++++-------------------- 1 file changed, 26 insertions(+), 20 deletions(-) diff --git a/netbsd/Platform.c b/netbsd/Platform.c index b34a6607..d99ea6e3 100644 --- a/netbsd/Platform.c +++ b/netbsd/Platform.c @@ -24,6 +24,7 @@ in the source distribution for its full text. #include #include #include +#include #include #include #include @@ -49,6 +50,16 @@ in the source distribution for its full text. #include "netbsd/NetBSDProcess.h" #include "netbsd/NetBSDProcessList.h" +/* + * The older proplib APIs will be deprecated in NetBSD 10, but we still + * want to support the 9.x stable branch. + * + * Create aliases for the newer functions that are missing from 9.x. + */ +#if !__NetBSD_Prereq__(9,99,65) +#define prop_string_equals_string prop_string_equals_cstring +#define prop_number_signed_value prop_number_integer_value +#endif const ProcessField Platform_defaultFields[] = { PID, USER, PRIORITY, NICE, M_VIRT, M_RESIDENT, STATE, PERCENT_CPU, PERCENT_MEM, TIME, COMM, 0 }; @@ -333,8 +344,8 @@ void Platform_getBattery(double* percent, ACPresence* isOnAC) { prop_dictionary_t dict, fields, props; prop_object_t device, class; - int64_t totalCharge = 0; - int64_t totalCapacity = 0; + intmax_t totalCharge = 0; + intmax_t totalCapacity = 0; *percent = NAN; *isOnAC = AC_ERROR; @@ -363,24 +374,19 @@ void Platform_getBattery(double* percent, ACPresence* isOnAC) { bool isBattery = false; /* only assume battery is not present if explicitly stated */ - int64_t isPresent = 1; - int64_t isConnected = 0; - int64_t curCharge = 0; - int64_t maxCharge = 0; + intmax_t isPresent = 1; + intmax_t isConnected = 0; + intmax_t curCharge = 0; + intmax_t maxCharge = 0; while ((fields = prop_object_iterator_next(fieldsIter)) != NULL) { props = prop_dictionary_get(fields, "device-properties"); if (props != NULL) { class = prop_dictionary_get(props, "device-class"); - /* - * After NetBSD 11's release NetBSD 9 will no longer be supported - * and these should be converted to prop_string_equals_string. - */ - - if (prop_string_equals_cstring(class, "ac-adapter")) { + if (prop_string_equals_string(class, "ac-adapter")) { isACAdapter = true; - } else if (prop_string_equals_cstring(class, "battery")) { + } else if (prop_string_equals_string(class, "battery")) { isBattery = true; } continue; @@ -393,15 +399,15 @@ void Platform_getBattery(double* percent, ACPresence* isOnAC) { if (descField == NULL || curValue == NULL) continue; - if (prop_string_equals_cstring(descField, "connected")) { - isConnected = prop_number_integer_value(curValue); - } else if (prop_string_equals_cstring(descField, "present")) { - isPresent = prop_number_integer_value(curValue); - } else if (prop_string_equals_cstring(descField, "charge")) { + if (prop_string_equals_string(descField, "connected")) { + isConnected = prop_number_signed_value(curValue); + } else if (prop_string_equals_string(descField, "present")) { + isPresent = prop_number_signed_value(curValue); + } else if (prop_string_equals_string(descField, "charge")) { if (maxValue == NULL) continue; - curCharge = prop_number_integer_value(curValue); - maxCharge = prop_number_integer_value(maxValue); + curCharge = prop_number_signed_value(curValue); + maxCharge = prop_number_signed_value(maxValue); } } -- cgit v1.2.3