MCPcopy Create free account
hub / github.com/F-Stack/f-stack / parse_numeric

Function parse_numeric

tools/sysctl/sysctl.c:388–492  ·  view source on GitHub ↗

* Parse a single numeric value, append it to 'newbuf', and update * 'newsize'. Returns true if the value was parsed and false if the * value was invalid. Non-numeric types (strings) are handled * directly in parse(). */

Source from the content-addressed store, hash-verified

386 * directly in parse().
387 */
388static bool
389parse_numeric(const char *newvalstr, const char *fmt, u_int kind,
390 void **newbufp, size_t *newsizep)
391{
392 void *newbuf;
393 const void *newval;
394 int8_t i8val;
395 uint8_t u8val;
396 int16_t i16val;
397 uint16_t u16val;
398 int32_t i32val;
399 uint32_t u32val;
400 int intval;
401 unsigned int uintval;
402 long longval;
403 unsigned long ulongval;
404 int64_t i64val;
405 uint64_t u64val;
406 size_t valsize;
407 char *endptr = NULL;
408
409 errno = 0;
410
411 switch (kind & CTLTYPE) {
412 case CTLTYPE_INT:
413 if (strncmp(fmt, "IK", 2) == 0)
414 intval = strIKtoi(newvalstr, &endptr, fmt);
415 else
416 intval = (int)strtol(newvalstr, &endptr, 0);
417 newval = &intval;
418 valsize = sizeof(intval);
419 break;
420 case CTLTYPE_UINT:
421 uintval = (int) strtoul(newvalstr, &endptr, 0);
422 newval = &uintval;
423 valsize = sizeof(uintval);
424 break;
425 case CTLTYPE_LONG:
426 longval = strtol(newvalstr, &endptr, 0);
427 newval = &longval;
428 valsize = sizeof(longval);
429 break;
430 case CTLTYPE_ULONG:
431 ulongval = strtoul(newvalstr, &endptr, 0);
432 newval = &ulongval;
433 valsize = sizeof(ulongval);
434 break;
435 case CTLTYPE_S8:
436 i8val = (int8_t)strtol(newvalstr, &endptr, 0);
437 newval = &i8val;
438 valsize = sizeof(i8val);
439 break;
440 case CTLTYPE_S16:
441 i16val = (int16_t)strtol(newvalstr, &endptr, 0);
442 newval = &i16val;
443 valsize = sizeof(i16val);
444 break;
445 case CTLTYPE_S32:

Callers 1

parseFunction · 0.85

Calls 7

strncmpFunction · 0.85
strIKtoiFunction · 0.85
strtolFunction · 0.85
strtoulFunction · 0.85
abortClass · 0.85
reallocFunction · 0.50
memcpyFunction · 0.50

Tested by

no test coverage detected