summaryrefslogtreecommitdiff
path: root/src/util.c
blob: c324a0b5fafd8a20e5a75443fd5cd1045e655241 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
#include <limits.h>
#include <stdio.h>
#include <string.h>
#include <unistd.h>

#include "util.h"

#define SYSFS_CPU	"/sys/devices/system/cpu/cpu"
#define MAXCPUS		1024

unsigned get_ncpus(void)
{
	char		path[cstrlen(SYSFS_CPU "1024") + 1];
	unsigned	n;

	for (n = 0; n < MAXCPUS; n++) {
		snprintf(path, sizeof(path), "%s%u", SYSFS_CPU, n);
		if (access(path, F_OK) == -1)
			break;
	}

	return n == 0 ? 1 : n;
}
© All Rights Reserved