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

Function parse

tools/sysctl/sysctl.c:499–723  ·  view source on GitHub ↗

* Parse a name into a MIB entry. * Lookup and print out the MIB entry if it exists. * Set a new value if requested. */

Source from the content-addressed store, hash-verified

497 * Set a new value if requested.
498 */
499static int
500parse(const char *string, int lineno)
501{
502 int len, i, j, save_errno;
503 const void *newval;
504 char *newvalstr = NULL;
505 void *newbuf;
506 size_t newsize = Bflag;
507 int mib[CTL_MAXNAME];
508 char *cp, *bufp, *buf, fmt[BUFSIZ], line[BUFSIZ];
509 u_int kind;
510
511 if (lineno)
512 snprintf(line, sizeof(line), " at line %d", lineno);
513 else
514 line[0] = '\0';
515
516 /*
517 * Split the string into name and value.
518 *
519 * Either = or : may be used as the delimiter.
520 * Whitespace surrounding the delimiter is trimmed.
521 * Quotes around the value are stripped.
522 */
523 cp = buf = strdup(string);
524 bufp = strsep(&cp, "=:");
525 if (cp != NULL) {
526 /* Tflag just lists tunables, do not allow assignment */
527 if (Tflag || Wflag) {
528 warnx("Can't set variables when using -T or -W");
529 usage();
530 }
531 /* Trim whitespace before the value. */
532 while (isspace(*cp))
533 cp++;
534 /* Strip a pair of " or ' if any. */
535 switch (*cp) {
536 case '\"':
537 case '\'':
538 if (cp[strlen(cp) - 1] == *cp)
539 cp[strlen(cp) - 1] = '\0';
540 cp++;
541 }
542 newvalstr = cp;
543 newsize = strlen(cp);
544 }
545 /* Trim whitespace after the name. */
546 cp = bufp + strlen(bufp) - 1;
547 while (cp >= bufp && isspace((int)*cp)) {
548 *cp = '\0';
549 cp--;
550 }
551
552 /*
553 * Check the name is a useable oid.
554 */
555 len = name2oid(bufp, mib);
556 if (len < 0) {

Callers 2

sysctl.cFile · 0.85
parsefileFunction · 0.85

Calls 15

snprintfFunction · 0.85
strdupFunction · 0.85
strsepFunction · 0.85
isspaceFunction · 0.85
oidfmtFunction · 0.85
ff_ipc_exitFunction · 0.85
show_varFunction · 0.85
putcharFunction · 0.85
sysctl_allFunction · 0.85
parse_numericFunction · 0.85
sysctlFunction · 0.85
usageFunction · 0.70

Tested by

no test coverage detected