--- numactl-0.9.8/libnuma.c	2006-04-04 05:52:26.000000000 +0200
+++ numactl/libnuma.c	2006-06-08 11:50:19.000000000 +0200
@@ -118,58 +118,26 @@
 static int maxnode = -1; 
 static int maxcpus = -1; 
 
-static int number_of_cpus(void)
+static int number_of_configured_cpus(void)
 { 
-	char *line = NULL;
-	size_t len = 0;
-	char *s;
-	FILE *f;
-	int cpu;
+	int len = 16; 
+	int n;
 	
 	if (maxcpus >= 0) 
 		return maxcpus + 1;
 
-	f = fopen("/proc/cpuinfo","r"); 
-	if (!f) {
-		int n;
-		int len = 8192; 
-		for (;;) { 
-			unsigned long buffer[CPU_LONGS(len)];
-			memset(buffer, 0, sizeof(buffer));
-			n = numa_sched_getaffinity_int(0, CPU_BYTES(len), 
-						       buffer);
-			if (n < 0 && errno == EINVAL && len < 1024*1024) {
-				len *= 2;
-				continue;
-			}
-			if (n >= 0) { 
-				int i, k;
-				for (i = 0; i < n / sizeof(long); i++) {
-					if (!buffer[i])
-						continue;
-					for (k = 0; k< 8; k++) 
-						if (buffer[i] & (1<<k))
-							maxcpus = i*sizeof(long)+k;
-				}
-				return maxcpus;
-			}
-			break;
-		}
-		numa_warn(W_noproc, "/proc not mounted. Assuming zero nodes: %s", 
-			  strerror(errno)); 
-		return 0;
-	}
-	maxcpus = 0;
-	while (getdelim(&line, &len, '\n', f) > 0) { 
-		if (strncmp(line,"processor",9))
+	do { 
+		unsigned long buffer[CPU_LONGS(len)];
+		memset(buffer, 0, sizeof(buffer));
+		n = numa_sched_getaffinity_int(0, CPU_BYTES(len), buffer);
+		if (n < 0 && errno == EINVAL) {
+			if (len >= 1024*1024) 
+				break;
+			len *= 2;
 			continue;
-		s = line + strcspn(line, "0123456789"); 
-		if (sscanf(s, "%d", &cpu) == 1 && cpu > maxcpus) 
-			maxcpus = cpu;
-	} 
-	free(line);
-	fclose(f); 
-	return maxcpus + 1;
+		}
+	} while (n < 0);
+	return len;
 } 
 
 static int fallback_max_node(void)
@@ -440,7 +408,7 @@
 	int n;
 	int buflen_needed;
 	unsigned long *mask, prev;
-	int ncpus = number_of_cpus();
+	int ncpus = number_of_configured_cpus();
 	int i;
 	int mask_words;
 	int bits_in_mask_0;
@@ -528,7 +496,7 @@
 
 int numa_run_on_node_mask(const nodemask_t *mask)
 { 	
-	int ncpus = number_of_cpus();
+	int ncpus = number_of_configured_cpus();
 	int i, k, err;
 	unsigned long cpus[CPU_LONGS(ncpus)], nodecpus[CPU_LONGS(ncpus)];
 	memset(cpus, 0, CPU_BYTES(ncpus));
@@ -582,7 +550,7 @@
 
 nodemask_t numa_get_run_node_mask(void)
 { 
-	int ncpus = number_of_cpus();
+	int ncpus = number_of_configured_cpus();
 	nodemask_t mask;
 	int i, k;
 	int max = numa_max_node_int();
@@ -612,7 +580,7 @@
 
 int numa_run_on_node(int node)
 { 
-	int ncpus = number_of_cpus();
+	int ncpus = number_of_configured_cpus();
 	unsigned long cpus[CPU_LONGS(ncpus)];
 
 	if (node == -1)
