Permalink
Browse files

sysctl - Allow integers to use hex

* Allow integers to be specified in hex using a 0x or 0X prefix.
  • Loading branch information...
1 parent 1f8639a commit 2f7967fd5c2b75e910350499a195a6258096e79a Matthew Dillon committed Sep 21, 2012
Showing with 9 additions and 1 deletion.
  1. +9 −1 sbin/sysctl/sysctl.c
View
@@ -552,7 +552,15 @@ set_IK(const char *str, int *val)
temp = (temp - 32) * 5 / 9;
kelv = temp * 10 + 2732;
} else {
- kelv = (int)strtol(str, &endptr, 10);
+ /*
+ * I would like to just use, 0 but it would make numbers
+ * like '023' which were interpreted as decimal before
+ * suddenly interpreted as octal.
+ */
+ if (str[0] == '0' && (str[1] == 'x' || str[1] == 'X'))
+ kelv = (int)strtol(str, &endptr, 0);
+ else
+ kelv = (int)strtol(str, &endptr, 10);
if (endptr == str || *endptr != '\0')
return 0;
}

0 comments on commit 2f7967f

Please sign in to comment.