mailing list of musl libc
 help / color / mirror / code / Atom feed
07dbeb9669e8ffa6c250446224f377c32760e83c blob 944 bytes (raw)

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
 
#include <sys/mman.h>
#include <errno.h>
#include <fcntl.h>
#include <unistd.h>
#include <string.h>
#include <limits.h>
#include <pthread.h>

char *__shm_mapname(const char *name, char *buf)
{
	const char *s=name, *e;
	while (*s == '/') s++;
	if (*(e = __strchrnul(s, '/')) || e==s ||
	    (e-s <= 2 && s[0]=='.' && e[-1]=='.')) {
		errno = EINVAL;
		return 0;
	}
	if (e-name > NAME_MAX) {
		errno = ENAMETOOLONG;
		return 0;
	}
	memcpy(buf, "/dev/shm/", 9);
	memcpy(buf+9, s, e-s+1);
	return buf;
}

int shm_open(const char *name, int flag, mode_t mode)
{
	int cs;
	char buf[NAME_MAX+10];
	if (!(name = __shm_mapname(name, buf))) return -1;
	pthread_setcancelstate(PTHREAD_CANCEL_DISABLE, &cs);
	int fd = open(name, flag|O_NOFOLLOW|O_CLOEXEC|O_NONBLOCK, mode);
	pthread_setcancelstate(cs, 0);
	return fd;
}

int shm_unlink(const char *name)
{
	char buf[NAME_MAX+10];
	if (!(name = __shm_mapname(name, buf))) return -1;
	return unlink(name);
}
debug log:

solving 07dbeb96 ...
found 07dbeb96 in https://inbox.vuxu.org/musl/20241105045628.1542264-1-lihua.zhao.cn@windriver.com/
found 79784bd3 in https://git.vuxu.org/mirror/musl/
preparing index
index prepared:
100644 79784bd306e2dac347cea17af92b2b80c8ea1831	src/mman/shm_open.c

applying [1/1] https://inbox.vuxu.org/musl/20241105045628.1542264-1-lihua.zhao.cn@windriver.com/
diff --git a/src/mman/shm_open.c b/src/mman/shm_open.c
index 79784bd3..07dbeb96 100644

Checking patch src/mman/shm_open.c...
Applied patch src/mman/shm_open.c cleanly.

index at:
100644 07dbeb9669e8ffa6c250446224f377c32760e83c	src/mman/shm_open.c

Code repositories for project(s) associated with this public inbox

	https://git.vuxu.org/mirror/musl/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).