Follow-up to r290475: Add sysctl(8) support for added types
Sponsored by: EMC / Isilon Storage Division
This commit is contained in:
parent
65f14c5699
commit
82ece5aa34
@ -86,29 +86,40 @@ static int strIKtoi(const char *, char **, const char *);
|
||||
static int ctl_sign[CTLTYPE+1] = {
|
||||
[CTLTYPE_INT] = 1,
|
||||
[CTLTYPE_LONG] = 1,
|
||||
[CTLTYPE_S8] = 1,
|
||||
[CTLTYPE_S16] = 1,
|
||||
[CTLTYPE_S32] = 1,
|
||||
[CTLTYPE_S64] = 1,
|
||||
};
|
||||
|
||||
static int ctl_size[CTLTYPE+1] = {
|
||||
[CTLTYPE_U8] = sizeof(uint8_t),
|
||||
[CTLTYPE_U16] = sizeof(uint16_t),
|
||||
[CTLTYPE_INT] = sizeof(int),
|
||||
[CTLTYPE_UINT] = sizeof(u_int),
|
||||
[CTLTYPE_LONG] = sizeof(long),
|
||||
[CTLTYPE_ULONG] = sizeof(u_long),
|
||||
[CTLTYPE_S8] = sizeof(int8_t),
|
||||
[CTLTYPE_S16] = sizeof(int16_t),
|
||||
[CTLTYPE_S32] = sizeof(int32_t),
|
||||
[CTLTYPE_S64] = sizeof(int64_t),
|
||||
[CTLTYPE_U8] = sizeof(uint8_t),
|
||||
[CTLTYPE_U16] = sizeof(uint16_t),
|
||||
[CTLTYPE_U32] = sizeof(uint32_t),
|
||||
[CTLTYPE_U64] = sizeof(uint64_t),
|
||||
};
|
||||
|
||||
static const char *ctl_typename[CTLTYPE+1] = {
|
||||
[CTLTYPE_U8] = "uint8_t",
|
||||
[CTLTYPE_U16] = "uint16_t",
|
||||
[CTLTYPE_INT] = "integer",
|
||||
[CTLTYPE_UINT] = "unsigned integer",
|
||||
[CTLTYPE_LONG] = "long integer",
|
||||
[CTLTYPE_ULONG] = "unsigned long",
|
||||
[CTLTYPE_S64] = "int64_t",
|
||||
[CTLTYPE_U8] = "uint8_t",
|
||||
[CTLTYPE_U16] = "uint16_t",
|
||||
[CTLTYPE_U32] = "uint16_t",
|
||||
[CTLTYPE_U64] = "uint64_t",
|
||||
[CTLTYPE_S8] = "int8_t",
|
||||
[CTLTYPE_S16] = "int16_t",
|
||||
[CTLTYPE_S32] = "int32_t",
|
||||
[CTLTYPE_S64] = "int64_t",
|
||||
};
|
||||
|
||||
static void
|
||||
@ -225,8 +236,12 @@ parse(const char *string, int lineno)
|
||||
int len, i, j;
|
||||
const void *newval;
|
||||
const char *newvalstr = NULL;
|
||||
int8_t i8val;
|
||||
uint8_t u8val;
|
||||
int16_t i16val;
|
||||
uint16_t u16val;
|
||||
int32_t i32val;
|
||||
uint32_t u32val;
|
||||
int intval;
|
||||
unsigned int uintval;
|
||||
long longval;
|
||||
@ -328,13 +343,17 @@ parse(const char *string, int lineno)
|
||||
}
|
||||
|
||||
switch (kind & CTLTYPE) {
|
||||
case CTLTYPE_U8:
|
||||
case CTLTYPE_U16:
|
||||
case CTLTYPE_INT:
|
||||
case CTLTYPE_UINT:
|
||||
case CTLTYPE_LONG:
|
||||
case CTLTYPE_ULONG:
|
||||
case CTLTYPE_S8:
|
||||
case CTLTYPE_S16:
|
||||
case CTLTYPE_S32:
|
||||
case CTLTYPE_S64:
|
||||
case CTLTYPE_U8:
|
||||
case CTLTYPE_U16:
|
||||
case CTLTYPE_U32:
|
||||
case CTLTYPE_U64:
|
||||
if (strlen(newvalstr) == 0) {
|
||||
warnx("empty numeric value");
|
||||
@ -353,17 +372,6 @@ parse(const char *string, int lineno)
|
||||
errno = 0;
|
||||
|
||||
switch (kind & CTLTYPE) {
|
||||
case CTLTYPE_U8:
|
||||
u8val = (uint8_t)strtoul(newvalstr, &endptr, 0);
|
||||
newval = &u8val;
|
||||
newsize = sizeof(u8val);
|
||||
break;
|
||||
case CTLTYPE_U16:
|
||||
u16val = (uint16_t)strtoul(newvalstr, &endptr,
|
||||
0);
|
||||
newval = &u16val;
|
||||
newsize = sizeof(u16val);
|
||||
break;
|
||||
case CTLTYPE_INT:
|
||||
if (strncmp(fmt, "IK", 2) == 0)
|
||||
intval = strIKtoi(newvalstr, &endptr, fmt);
|
||||
@ -391,11 +399,45 @@ parse(const char *string, int lineno)
|
||||
case CTLTYPE_STRING:
|
||||
newval = newvalstr;
|
||||
break;
|
||||
case CTLTYPE_S8:
|
||||
i8val = (int8_t)strtol(newvalstr, &endptr, 0);
|
||||
newval = &i8val;
|
||||
newsize = sizeof(i8val);
|
||||
break;
|
||||
case CTLTYPE_S16:
|
||||
i16val = (int16_t)strtol(newvalstr, &endptr,
|
||||
0);
|
||||
newval = &i16val;
|
||||
newsize = sizeof(i16val);
|
||||
break;
|
||||
case CTLTYPE_S32:
|
||||
i32val = (int32_t)strtol(newvalstr, &endptr,
|
||||
0);
|
||||
newval = &i32val;
|
||||
newsize = sizeof(i32val);
|
||||
break;
|
||||
case CTLTYPE_S64:
|
||||
i64val = strtoimax(newvalstr, &endptr, 0);
|
||||
newval = &i64val;
|
||||
newsize = sizeof(i64val);
|
||||
break;
|
||||
case CTLTYPE_U8:
|
||||
u8val = (uint8_t)strtoul(newvalstr, &endptr, 0);
|
||||
newval = &u8val;
|
||||
newsize = sizeof(u8val);
|
||||
break;
|
||||
case CTLTYPE_U16:
|
||||
u16val = (uint16_t)strtoul(newvalstr, &endptr,
|
||||
0);
|
||||
newval = &u16val;
|
||||
newsize = sizeof(u16val);
|
||||
break;
|
||||
case CTLTYPE_U32:
|
||||
u32val = (uint32_t)strtoul(newvalstr, &endptr,
|
||||
0);
|
||||
newval = &u32val;
|
||||
newsize = sizeof(u32val);
|
||||
break;
|
||||
case CTLTYPE_U64:
|
||||
u64val = strtoumax(newvalstr, &endptr, 0);
|
||||
newval = &u64val;
|
||||
@ -909,13 +951,17 @@ show_var(int *oid, int nlen)
|
||||
free(oval);
|
||||
return (0);
|
||||
|
||||
case CTLTYPE_U8:
|
||||
case CTLTYPE_U16:
|
||||
case CTLTYPE_INT:
|
||||
case CTLTYPE_UINT:
|
||||
case CTLTYPE_LONG:
|
||||
case CTLTYPE_ULONG:
|
||||
case CTLTYPE_S8:
|
||||
case CTLTYPE_S16:
|
||||
case CTLTYPE_S32:
|
||||
case CTLTYPE_S64:
|
||||
case CTLTYPE_U8:
|
||||
case CTLTYPE_U16:
|
||||
case CTLTYPE_U32:
|
||||
case CTLTYPE_U64:
|
||||
if (!nflag)
|
||||
printf("%s%s", name, sep);
|
||||
@ -923,14 +969,6 @@ show_var(int *oid, int nlen)
|
||||
sep1 = "";
|
||||
while (len >= intlen) {
|
||||
switch (kind & CTLTYPE) {
|
||||
case CTLTYPE_U8:
|
||||
umv = *(uint8_t *)p;
|
||||
mv = *(int8_t *)p;
|
||||
break;
|
||||
case CTLTYPE_U16:
|
||||
umv = *(uint16_t *)p;
|
||||
mv = *(int16_t *)p;
|
||||
break;
|
||||
case CTLTYPE_INT:
|
||||
case CTLTYPE_UINT:
|
||||
umv = *(u_int *)p;
|
||||
@ -941,6 +979,21 @@ show_var(int *oid, int nlen)
|
||||
umv = *(u_long *)p;
|
||||
mv = *(long *)p;
|
||||
break;
|
||||
case CTLTYPE_S8:
|
||||
case CTLTYPE_U8:
|
||||
umv = *(uint8_t *)p;
|
||||
mv = *(int8_t *)p;
|
||||
break;
|
||||
case CTLTYPE_S16:
|
||||
case CTLTYPE_U16:
|
||||
umv = *(uint16_t *)p;
|
||||
mv = *(int16_t *)p;
|
||||
break;
|
||||
case CTLTYPE_S32:
|
||||
case CTLTYPE_U32:
|
||||
umv = *(uint32_t *)p;
|
||||
mv = *(int32_t *)p;
|
||||
break;
|
||||
case CTLTYPE_S64:
|
||||
case CTLTYPE_U64:
|
||||
umv = *(uint64_t *)p;
|
||||
|
Loading…
Reference in New Issue
Block a user