Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1)

Unified Diff: fusl/src/mman/shm_open.c

Issue 1573973002: Add a "fork" of musl as //fusl. (Closed) Base URL: https://github.com/domokit/mojo.git@master
Patch Set: Created 4 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « fusl/src/mman/posix_madvise.c ('k') | fusl/src/mq/mq_close.c » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: fusl/src/mman/shm_open.c
diff --git a/fusl/src/mman/shm_open.c b/fusl/src/mman/shm_open.c
new file mode 100644
index 0000000000000000000000000000000000000000..d042a5a882bd347dd937bceb8f851bb98cb418b8
--- /dev/null
+++ b/fusl/src/mman/shm_open.c
@@ -0,0 +1,45 @@
+#include <sys/mman.h>
+#include <errno.h>
+#include <fcntl.h>
+#include <unistd.h>
+#include <string.h>
+#include <limits.h>
+#include <pthread.h>
+
+char *__strchrnul(const char *, int);
+
+char *__shm_mapname(const char *name, char *buf)
+{
+ char *p;
+ while (*name == '/') name++;
+ if (*(p = __strchrnul(name, '/')) || p==name ||
+ (p-name <= 2 && name[0]=='.' && p[-1]=='.')) {
+ errno = EINVAL;
+ return 0;
+ }
+ if (p-name > NAME_MAX) {
+ errno = ENAMETOOLONG;
+ return 0;
+ }
+ memcpy(buf, "/dev/shm/", 9);
+ memcpy(buf+9, name, p-name+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);
+}
« no previous file with comments | « fusl/src/mman/posix_madvise.c ('k') | fusl/src/mq/mq_close.c » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698