提交 ebd7af69 编写于 作者: R Rich Felker

implement POSIX shared memory

上级 71df8b27
#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;
}
#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;
}
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册