summaryrefslogtreecommitdiff
path: root/src/mman/shm_unlink.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/mman/shm_unlink.c')
-rw-r--r--src/mman/shm_unlink.c21
1 files changed, 21 insertions, 0 deletions
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;
+}