MCPcopy Index your code
hub / github.com/F-Stack/f-stack / show_var

Function show_var

tools/sysctl/sysctl.c:1130–1247  ·  view source on GitHub ↗

* This formats and outputs the value of one variable * * Returns zero if anything was actually output. * Returns one if didn't know what to do with this. * Return minus one if we had errors. */

Source from the content-addressed store, hash-verified

1128 * Return minus one if we had errors.
1129 */
1130static int
1131show_var(int *oid, int nlen, bool honor_skip)
1132{
1133 static int skip_len = 0, skip_oid[CTL_MAXNAME];
1134 u_char buf[BUFSIZ], *val, *oval, *p;
1135 char name[BUFSIZ], fmt[BUFSIZ];
1136 const char *sep, *sep1, *prntype;
1137 int qoid[CTL_MAXNAME+2];
1138 uintmax_t umv;
1139 intmax_t mv;
1140 int i, hexlen, sign, ctltype;
1141 size_t intlen;
1142 size_t j, len;
1143 u_int kind;
1144 float base;
1145 int (*func)(size_t, void *);
1146 int prec;
1147
1148 /* Silence GCC. */
1149 umv = mv = intlen = 0;
1150
1151 bzero(buf, BUFSIZ);
1152 bzero(fmt, BUFSIZ);
1153 bzero(name, BUFSIZ);
1154 qoid[0] = CTL_SYSCTL;
1155 memcpy(qoid + 2, oid, nlen * sizeof(int));
1156
1157 qoid[1] = CTL_SYSCTL_NAME;
1158 j = sizeof(name);
1159 i = sysctl(qoid, nlen + 2, name, &j, 0, 0);
1160 if (i || !j)
1161 err(1, "sysctl name %d %zu %d", i, j, errno);
1162
1163 oidfmt(oid, nlen, fmt, &kind);
1164 /* if Wflag then only list sysctls that are writeable and not stats. */
1165 if (Wflag && ((kind & CTLFLAG_WR) == 0 || (kind & CTLFLAG_STATS) != 0))
1166 return (1);
1167
1168 /* if Tflag then only list sysctls that are tuneables. */
1169 if (Tflag && (kind & CTLFLAG_TUN) == 0)
1170 return (1);
1171
1172 if (Nflag) {
1173 printf("%s", name);
1174 return (0);
1175 }
1176
1177 if (eflag)
1178 sep = "=";
1179 else
1180 sep = ": ";
1181
1182 ctltype = (kind & CTLTYPE);
1183 if (tflag || dflag) {
1184 if (!nflag)
1185 printf("%s%s", name, sep);
1186 if (ctl_typename[ctltype] != NULL)
1187 prntype = ctl_typename[ctltype];

Callers 2

parseFunction · 0.85
sysctl_allFunction · 0.85

Calls 6

bzeroFunction · 0.85
sysctlFunction · 0.85
oidfmtFunction · 0.85
strcmpFunction · 0.85
memcpyFunction · 0.50
printfFunction · 0.50

Tested by

no test coverage detected