parlib: Move core_sets to parlib

I converted xopen() -> open() and xstrdup() -> strdup().

I tried putting xlib in parlib, but a bunch of other projects use those
names for the same functions, and we run into conflicts.  This is why we
can't have nice things.

Signed-off-by: Barret Rhoden <brho@cs.berkeley.edu>
diff --git a/tools/dev-util/perf/Makefile b/tools/dev-util/perf/Makefile
index 6e506f6..1a90f49 100644
--- a/tools/dev-util/perf/Makefile
+++ b/tools/dev-util/perf/Makefile
@@ -1,6 +1,6 @@
 include ../../Makefrag
 
-SOURCES = perf.c perfconv.c xlib.c perf_core.c akaros.c symbol-elf.c
+SOURCES = perf.c perfconv.c xlib.c perf_core.c symbol-elf.c
 
 XCC = $(CROSS_COMPILE)gcc
 
diff --git a/tools/dev-util/perf/perf.c b/tools/dev-util/perf/perf.c
index e7227bb..b018f9f 100644
--- a/tools/dev-util/perf/perf.c
+++ b/tools/dev-util/perf/perf.c
@@ -19,8 +19,8 @@
 #include <time.h>
 #include <parlib/parlib.h>
 #include <parlib/timing.h>
+#include <parlib/core_set.h>
 #include "xlib.h"
-#include "akaros.h"
 #include "perfconv.h"
 #include "perf_core.h"
 
diff --git a/tools/dev-util/perf/perf_core.c b/tools/dev-util/perf/perf_core.c
index 17b4811..4143c9c 100644
--- a/tools/dev-util/perf/perf_core.c
+++ b/tools/dev-util/perf/perf_core.c
@@ -20,11 +20,11 @@
 #include <errno.h>
 #include <regex.h>
 #include <parlib/parlib.h>
+#include <parlib/core_set.h>
 #include <perfmon/err.h>
 #include <perfmon/pfmlib.h>
 #include "xlib.h"
 #include "perfconv.h"
-#include "akaros.h"
 #include "perf_core.h"
 #include "elf.h"
 
diff --git a/tools/dev-util/perf/perf_core.h b/tools/dev-util/perf/perf_core.h
index ef67083..42e7419 100644
--- a/tools/dev-util/perf/perf_core.h
+++ b/tools/dev-util/perf/perf_core.h
@@ -12,7 +12,7 @@
 #include <stdint.h>
 #include <stdio.h>
 #include <limits.h>
-#include "akaros.h"
+#include <parlib/core_set.h>
 #include "perfconv.h"
 
 #define MAX_CPU_EVENTS 256
diff --git a/tools/dev-util/perf/perfconv.c b/tools/dev-util/perf/perfconv.c
index f00a222..abc6379 100644
--- a/tools/dev-util/perf/perfconv.c
+++ b/tools/dev-util/perf/perfconv.c
@@ -25,6 +25,7 @@
 #include <string.h>
 #include <errno.h>
 #include <stdarg.h>
+#include <assert.h>
 #include "perf_format.h"
 #include "xlib.h"
 #include "perf_core.h"
diff --git a/tools/dev-util/perf/akaros.c b/user/parlib/core_set.c
similarity index 92%
rename from tools/dev-util/perf/akaros.c
rename to user/parlib/core_set.c
index 5ccbd81..8c41245 100644
--- a/tools/dev-util/perf/akaros.c
+++ b/user/parlib/core_set.c
@@ -6,13 +6,16 @@
 #include <ros/arch/arch.h>
 #include <ros/common.h>
 #include <sys/types.h>
+#include <sys/stat.h>
+#include <fcntl.h>
 #include <stdint.h>
 #include <stdio.h>
+#include <stdlib.h>
 #include <string.h>
 #include <limits.h>
+#include <unistd.h>
 #include <parlib/parlib.h>
-#include "xlib.h"
-#include "akaros.h"
+#include <parlib/core_set.h>
 
 static const unsigned int llcores[] = {
 	0
@@ -40,7 +43,7 @@
 	int fd, ret;
 	char buf[10];
 
-	fd = xopen("#vars/num_cores!dw", O_READ, 0);
+	fd = open("#vars/num_cores!dw", O_READ);
 	if (fd < 0)
 		return -1;
 	if (read(fd, buf, sizeof(buf)) <= 0) {
@@ -71,10 +74,14 @@
 void parlib_parse_cores(const char *str, struct core_set *cores)
 {
 	unsigned int fcpu, ncpu;
-	char *dstr = xstrdup(str);
+	char *dstr = strdup(str);
 	char *sptr = NULL;
 	char *tok, *sptr2;
 
+	if (!dstr) {
+		perror("Duplicating a string");
+		exit(1);
+	}
 	ZERO_DATA(*cores);
 	for (tok = strtok_r(dstr, ",", &sptr); tok;
 		 tok = strtok_r(NULL, ",", &sptr)) {
diff --git a/tools/dev-util/perf/akaros.h b/user/parlib/include/parlib/core_set.h
similarity index 87%
rename from tools/dev-util/perf/akaros.h
rename to user/parlib/include/parlib/core_set.h
index d47deb8..0832931 100644
--- a/tools/dev-util/perf/akaros.h
+++ b/user/parlib/include/parlib/core_set.h
@@ -5,13 +5,6 @@
 
 #pragma once
 
-#include <ros/arch/arch.h>
-#include <ros/common.h>
-#include <sys/types.h>
-#include <stdint.h>
-#include <stdio.h>
-#include <limits.h>
-#include <parlib/parlib.h>
 #include <parlib/bitmask.h>
 
 __BEGIN_DECLS