__u16 temperature = smart->temperature[1] << 8 | smart->temperature[0];
int i;
bool human = stdout_print_ops.flags & VERBOSE;
- bool fahrenheit = !!(stdout_print_ops.flags & FAHRENHEIT);
printf("Smart Log for NVME device:%s namespace-id:%x\n", devname, nsid);
printf("critical_warning : %#x\n", smart->critical_warning);
}
printf("temperature : %s (%u K)\n",
- nvme_degrees_string(temperature, fahrenheit), temperature);
+ nvme_degrees_string(temperature), temperature);
printf("available_spare : %u%%\n", smart->avail_spare);
printf("available_spare_threshold : %u%%\n", smart->spare_thresh);
printf("percentage_used : %u%%\n", smart->percent_used);
if (!temperature)
continue;
printf("Temperature Sensor %d : %s (%u K)\n", i + 1,
- nvme_degrees_string(temperature, fahrenheit), temperature);
+ nvme_degrees_string(temperature), temperature);
}
printf("Thermal Management T1 Trans Count : %u\n",
#include <stdlib.h>
#include <time.h>
#include <sys/stat.h>
+#include <locale.h>
#include "nvme.h"
#include "libnvme.h"
nvme_print(endurance_log, flags, endurance_log, group_id, devname);
}
-const char *nvme_degrees_string(long t, bool fahrenheit)
+static bool is_fahrenheit_country(const char *country)
+{
+ static const char * const countries[] = {
+ "AQ", "AS", "BS", "BZ", "CY", "FM", "GU", "KN", "KY", "LR",
+ "MH", "MP", "MS", "PR", "PW", "TC", "US", "VG", "VI"
+ };
+ int i;
+
+ for (i = 0; i < ARRAY_SIZE(countries); i++) {
+ if (!strcmp(country, countries[i]))
+ return true;
+ }
+
+ return false;
+}
+
+static bool is_temperature_fahrenheit(void)
+{
+ const char *locale, *underscore;
+ char country[3] = { 0 };
+
+ setlocale(LC_ALL, "");
+ locale = setlocale(LC_ALL, NULL);
+
+ if (!locale || strlen(locale) < 2)
+ return false;
+
+ underscore = strchr(locale, '_');
+ if (underscore && strlen(underscore) >= 3)
+ locale = underscore + 1;
+
+ memcpy(country, locale, 2);
+
+ return is_fahrenheit_country(country);
+}
+
+const char *nvme_degrees_string(long t)
{
static char str[STR_LEN];
long val = kelvin_to_celsius(t);
+ bool fahrenheit = is_temperature_fahrenheit();
if (fahrenheit)
val = kelvin_to_fahrenheit(t);
bool nvme_is_fabrics_reg(int offset);
bool nvme_registers_cmbloc_support(__u32 cmbsz);
bool nvme_registers_pmrctl_ready(__u32 pmrctl);
-const char *nvme_degrees_string(long t, bool fahrenheit);
+const char *nvme_degrees_string(long t);
#endif /* NVME_PRINT_H */