lib/memfd: shm_unlink or unlink anonymous file
https://man7.org/linux/man-pages/man2/memfd_create.2.html: The name supplied in name is used as a filename and will be displayed as the target of the corresponding symbolic link in the directory /proc/self/fd/. The displayed name is always prefixed with memfd: and serves only for debugging purposes. Names do not affect the behavior of the file descriptor, and as such multiple files can have the same name without any side effects. Signed-off-by: Xiang Xiao <xiaoxiang@xiaomi.com>
This commit is contained in:
parent
1b843633e6
commit
aa0b3fcdf9
|
@ -52,13 +52,24 @@ int memfd_create(FAR const char *name, unsigned int flags)
|
|||
return -1;
|
||||
#else
|
||||
char path[PATH_MAX];
|
||||
int ret;
|
||||
|
||||
snprintf(path, sizeof(path), LIBC_MEM_FD_VFS_PATH_FMT, name);
|
||||
# ifdef CONFIG_LIBC_MEMFD_SHMFS
|
||||
return shm_open(path, O_RDWR | flags, 0660);
|
||||
ret = shm_open(path, O_RDWR | flags, 0660);
|
||||
if (ret >= 0)
|
||||
{
|
||||
shm_unlink(path);
|
||||
}
|
||||
# else
|
||||
mkdir(LIBC_MEM_FD_VFS_PATH, 0666);
|
||||
return open(path, O_RDWR | flags, 0660);
|
||||
ret = open(path, O_RDWR | flags, 0660);
|
||||
if (ret >= 0)
|
||||
{
|
||||
unlink(path);
|
||||
}
|
||||
# endif
|
||||
|
||||
return ret;
|
||||
#endif
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue