mirror of
https://sourceware.org/git/glibc.git
synced 2025-07-29 11:41:21 +03:00
Refactor shm_{open,unlink} code to separate Linux-specific directory choice from POSIX-generic code.
This commit is contained in:
@ -24,37 +24,20 @@
|
||||
#else
|
||||
|
||||
#include <errno.h>
|
||||
#include <sys/mman.h>
|
||||
#include <string.h>
|
||||
#include <stdlib.h>
|
||||
#include <paths.h>
|
||||
#include "shm-directory.h"
|
||||
|
||||
#define SHMDIR (_PATH_DEV "shm/")
|
||||
|
||||
/* Remove shared memory object. */
|
||||
int
|
||||
shm_unlink (const char *name)
|
||||
{
|
||||
size_t namelen;
|
||||
char *fname;
|
||||
SHM_GET_NAME (ENOENT, -1);
|
||||
|
||||
/* Construct the filename. */
|
||||
while (name[0] == '/')
|
||||
++name;
|
||||
|
||||
if (name[0] == '\0')
|
||||
{
|
||||
/* The name "/" is not supported. */
|
||||
__set_errno (EINVAL);
|
||||
return -1;
|
||||
}
|
||||
|
||||
namelen = strlen (name);
|
||||
fname = (char *) __alloca (sizeof SHMDIR - 1 + namelen + 1);
|
||||
__mempcpy (__mempcpy (fname, SHMDIR, sizeof SHMDIR - 1),
|
||||
name, namelen + 1);
|
||||
|
||||
return unlink (name);
|
||||
int result = unlink (shm_name);
|
||||
if (result < 0 && errno == EPERM)
|
||||
__set_errno (EACCES);
|
||||
return result;
|
||||
}
|
||||
|
||||
#endif
|
||||
|
Reference in New Issue
Block a user