about summary refs log tree commit diff
diff options
context:
space:
mode:
authorRich Felker <dalias@aerifal.cx>2011-03-03 00:30:31 -0500
committerRich Felker <dalias@aerifal.cx>2011-03-03 00:30:31 -0500
commitebd7af6940bebb3b083a4d9239da27a66d1c32ec (patch)
tree94545088c4e45e9765bd810743d4e8120f219426
parent71df8b2760348c55b1c0d04aeebcae372d9760d3 (diff)
downloadmusl-ebd7af6940bebb3b083a4d9239da27a66d1c32ec.tar.gz
musl-ebd7af6940bebb3b083a4d9239da27a66d1c32ec.tar.xz
musl-ebd7af6940bebb3b083a4d9239da27a66d1c32ec.zip
implement POSIX shared memory
-rw-r--r--src/mman/shm_open.c21
-rw-r--r--src/mman/shm_unlink.c21
2 files changed, 42 insertions, 0 deletions
diff --git a/src/mman/shm_open.c b/src/mman/shm_open.c
new file mode 100644
index 00000000..d368622d
--- /dev/null
+++ b/src/mman/shm_open.c
@@ -0,0 +1,21 @@
+#include <sys/mman.h>
+#include <errno.h>
+#include <fcntl.h>
+#include <unistd.h>
+#include <string.h>
+
+int shm_open(const char *name, int flag, mode_t mode)
+{
+	int fd, dir;
+
+	while (*name == '/') name++;
+	if (strchr(name, '/')) {
+		errno = EINVAL;
+		return -1;
+	}
+
+	if ((dir = open("/dev/shm", O_DIRECTORY|O_RDONLY)) < 0) return -1;
+	fd = openat(dir, name, flag|O_NOFOLLOW|O_CLOEXEC|O_NONBLOCK, mode);
+	close(dir);
+	return fd;
+}
diff --git a/src/mman/shm_unlink.c b/src/mman/shm_unlink.c
new file mode 100644
index 00000000..46e60b3b
--- /dev/null
+++ b/src/mman/shm_unlink.c
@@ -0,0 +1,21 @@
+#include <sys/mman.h>
+#include <errno.h>
+#include <fcntl.h>
+#include <unistd.h>
+#include <string.h>
+
+int shm_unlink(const char *name)
+{
+	int dir, ret;
+
+	while (*name == '/') name++;
+	if (strchr(name, '/')) {
+		errno = EINVAL;
+		return -1;
+	}
+
+	if ((dir = open("/dev/shm", O_DIRECTORY|O_RDONLY)) < 0) return -1;
+	ret = unlinkat(dir, name, 0);
+	close(dir);
+	return ret;
+}