You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

36 lines
1.1 KiB

diff -up ./top/top.c.ori ./top/top.c
--- ./top/top.c.ori 2018-01-15 14:04:42.403457405 +0100
+++ ./top/top.c 2018-01-15 14:07:59.663713707 +0100
@@ -1260,15 +1260,25 @@ static char *ioline (const char *prompt)
/*
- * Make locale aware float (but maybe restrict to whole numbers). */
+ * Make locale unaware float (but maybe restrict to whole numbers). */
static int mkfloat (const char *str, float *num, int whole) {
- char *ep;
+ char tmp[SMLBUFSIZ], *ep;
- if (whole)
+ if (whole) {
*num = (float)strtol(str, &ep, 0);
- else
- *num = strtof(str, &ep);
- if (ep != str && *ep == '\0' && *num < INT_MAX)
+ if (ep != str && *ep == '\0' && *num < INT_MAX)
+ return 1;
+ return 0;
+ }
+ snprintf(tmp, sizeof(tmp), "%s", str);
+ *num = strtof(tmp, &ep);
+ if (*ep != '\0') {
+ // fallback - try to swap the floating point separator
+ if (*ep == '.') *ep = ',';
+ else if (*ep == ',') *ep = '.';
+ *num = strtof(tmp, &ep);
+ }
+ if (ep != tmp && *ep == '\0' && *num < INT_MAX)
return 1;
return 0;
} // end: mkfloat