summaryrefslogtreecommitdiff
path: root/src/mman/shm_open.c
blob: d368622d6f297be1f2a6ff4d2f778cf0d0323f82 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
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;
}