Welcome to mirror list, hosted at ThFree Co, Russian Federation.

cygwin.com/git/newlib-cygwin.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJeff Johnston <jjohnstn@redhat.com>2002-05-23 00:26:28 +0400
committerJeff Johnston <jjohnstn@redhat.com>2002-05-23 00:26:28 +0400
commit7736feb2769e32b669bffcccb89483163116ed5c (patch)
treeae39217ea668958a9f67c4bb5ae1f7ae54bb9f4f /newlib/libc/sys/linux/shm_open.c
parent613251a46db43c02ac3a39352e08b153560b2d4c (diff)
2002-05-22 Jeff Johnston <jjohnstn@redhat.com>
* libc/sys/linux/shm_open.c: New file. * libc/sys/linux/shm_unlink.c: Ditto. * libc/sys/linux/Makefile.am: Add support for shm_open.c and shm_unlink.c. * libc/sys/linux/Makefile.in: Regenerated. * libc/sys/linux/sys/types.h: Add some additional checks to see if clock_t or time_t is already defined.
Diffstat (limited to 'newlib/libc/sys/linux/shm_open.c')
-rw-r--r--newlib/libc/sys/linux/shm_open.c48
1 files changed, 48 insertions, 0 deletions
diff --git a/newlib/libc/sys/linux/shm_open.c b/newlib/libc/sys/linux/shm_open.c
new file mode 100644
index 000000000..cb92c3ae4
--- /dev/null
+++ b/newlib/libc/sys/linux/shm_open.c
@@ -0,0 +1,48 @@
+/* shm_open - open a shared memory file */
+
+/* Copyright 2002, Red Hat Inc. */
+
+#include <sys/types.h>
+#include <sys/mman.h>
+#include <unistd.h>
+#include <string.h>
+#include <fcntl.h>
+#include <limits.h>
+
+int
+shm_open (const char *name, int oflag, mode_t mode)
+{
+ int fd;
+ char shm_name[PATH_MAX+20] = "/dev/shm/";
+
+ /* skip opening slash */
+ if (*name == '/')
+ ++name;
+
+ /* create special shared memory file name and leave enough space to
+ cause a path/name error if name is too long */
+ strlcpy (shm_name + 9, name, PATH_MAX + 10);
+
+ fd = open (shm_name, oflag, mode);
+
+ if (fd != -1)
+ {
+ /* once open we must add FD_CLOEXEC flag to file descriptor */
+ int flags = fcntl (fd, F_GETFD, 0);
+
+ if (flags >= 0)
+ {
+ flags |= FD_CLOEXEC;
+ flags = fcntl (fd, F_SETFD, flags);
+ }
+
+ /* on failure, just close file and give up */
+ if (flags == -1)
+ {
+ close (fd);
+ fd = -1;
+ }
+ }
+
+ return fd;
+}