]> git.proxmox.com Git - mirror_lxcfs.git/blame - cpuset.c
Fix test_proc on s390x
[mirror_lxcfs.git] / cpuset.c
CommitLineData
fa47bb52
SH
1#include <stdio.h>
2#include <string.h>
3#include <stdbool.h>
4#include <stdlib.h>
5
6/*
7 * Helper functions for cpuset_in-set
8 */
9static char *cpuset_nexttok(const char *c)
10{
11 char *r = strchr(c+1, ',');
12 if (r)
13 return r+1;
14 return NULL;
15}
16
17static int cpuset_getrange(const char *c, int *a, int *b)
18{
19 int ret;
20
21 ret = sscanf(c, "%d-%d", a, b);
22 return ret;
23}
24
25/*
26 * cpusets are in format "1,2-3,4"
27 * iow, comma-delimited ranges
28 */
29bool cpu_in_cpuset(int cpu, const char *cpuset)
30{
31 const char *c;
32
33 for (c = cpuset; c; c = cpuset_nexttok(c)) {
34 int a, b, ret;
35
36 ret = cpuset_getrange(c, &a, &b);
37 if (ret == 1 && cpu == a) // "1" or "1,6"
38 return true;
39 else if (ret == 2 && cpu >= a && cpu <= b) // range match
40 return true;
41 }
42
43 return false;
44}
45