aboutsummaryrefslogtreecommitdiff
path: root/sbin/sysctl/sysctl.c
diff options
context:
space:
mode:
authorHajimu UMEMOTO <ume@FreeBSD.org>2006-09-03 15:10:04 +0000
committerHajimu UMEMOTO <ume@FreeBSD.org>2006-09-03 15:10:04 +0000
commitd45564dcfedc3bcc765a8079264be09684c73356 (patch)
tree5b3d8abbdbd3ca7cd673703db30ae0b5ba7c0385 /sbin/sysctl/sysctl.c
parent863ccba5d52911c9c94b2378d802d7ed72138c06 (diff)
downloadsrc-d45564dcfedc3bcc765a8079264be09684c73356.tar.gz
src-d45564dcfedc3bcc765a8079264be09684c73356.zip
Support Celsius (nn.nC), Fahrenheit (nn.nF) and Kelvin (nnnn) to
specify temperature. Reviewed by: njl MFC after: 3 days
Notes
Notes: svn path=/head/; revision=161951
Diffstat (limited to 'sbin/sysctl/sysctl.c')
-rw-r--r--sbin/sysctl/sysctl.c43
1 files changed, 39 insertions, 4 deletions
diff --git a/sbin/sysctl/sysctl.c b/sbin/sysctl/sysctl.c
index 1c5fc9df374e..3b40689ecf68 100644
--- a/sbin/sysctl/sysctl.c
+++ b/sbin/sysctl/sysctl.c
@@ -70,6 +70,7 @@ static int sysctl_all (int *oid, int len);
static int name2oid(char *, int *);
static void set_T_dev_t (char *, void **, size_t *);
+static int set_IK(char *, int *);
static void
usage(void)
@@ -232,10 +233,17 @@ parse(char *string)
switch (kind & CTLTYPE) {
case CTLTYPE_INT:
- intval = (int)strtol(newval, &endptr, 0);
- if (endptr == newval || *endptr != '\0')
- errx(1, "invalid integer '%s'",
- newval);
+ if (strcmp(fmt, "IK") == 0) {
+ if (!set_IK((char*)newval, &intval))
+ errx(1, "invalid value '%s'",
+ newval);
+ } else {
+ intval = (int)strtol(newval, &endptr,
+ 0);
+ if (endptr == newval || *endptr != '\0')
+ errx(1, "invalid integer '%s'",
+ newval);
+ }
newval = &intval;
newsize = sizeof(intval);
break;
@@ -443,6 +451,33 @@ set_T_dev_t (char *path, void **val, size_t *size)
*size = sizeof statb.st_rdev;
}
+static int
+set_IK(char *str, int *val)
+{
+ float temp;
+ int len, kelv;
+ char *p, *endptr;
+
+ if ((len = strlen(str)) == 0)
+ return (0);
+ p = &str[len - 1];
+ if (*p == 'C' || *p == 'F') {
+ *p = '\0';
+ temp = strtof(str, &endptr);
+ if (endptr == str || *endptr != '\0')
+ return (0);
+ if (*p == 'F')
+ temp = (temp - 32) * 5 / 9;
+ kelv = temp * 10 + 2732;
+ } else {
+ kelv = (int)strtol(str, &endptr, 10);
+ if (endptr == str || *endptr != '\0')
+ return (0);
+ }
+ *val = kelv;
+ return (1);
+}
+
/*
* These functions uses a presently undocumented interface to the kernel
* to walk the tree and get the type so it can print the value.