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

Function list2cpuset

tools/libutil/login_class.c:250–318  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

248
249
250static int
251list2cpuset(const char *list, cpuset_t *mask)
252{
253 enum { NONE, NUM, DASH } state;
254 int lastnum;
255 int curnum;
256 const char *l;
257
258 state = NONE;
259 curnum = lastnum = 0;
260 for (l = list; *l != '\0';) {
261 if (isdigit(*l)) {
262 curnum = atoi(l);
263 if (curnum > CPU_SETSIZE)
264 errx(EXIT_FAILURE,
265 "Only %d cpus supported", CPU_SETSIZE);
266 while (isdigit(*l))
267 l++;
268 switch (state) {
269 case NONE:
270 lastnum = curnum;
271 state = NUM;
272 break;
273 case DASH:
274 for (; lastnum <= curnum; lastnum++)
275 CPU_SET(lastnum, mask);
276 state = NONE;
277 break;
278 case NUM:
279 default:
280 return (0);
281 }
282 continue;
283 }
284 switch (*l) {
285 case ',':
286 switch (state) {
287 case NONE:
288 break;
289 case NUM:
290 CPU_SET(curnum, mask);
291 state = NONE;
292 break;
293 case DASH:
294 return (0);
295 break;
296 }
297 break;
298 case '-':
299 if (state != NUM)
300 return (0);
301 state = DASH;
302 break;
303 default:
304 return (0);
305 }
306 l++;
307 }

Callers 1

setclasscpumaskFunction · 0.85

Calls 1

isdigitFunction · 0.85

Tested by

no test coverage detected