]> xenbits.xen.org Git - xenclient/uclibc.git/commitdiff
add-shm_open-shm_unlink.patch
authorVincent Hanquez <vincent.hanquez@eu.citrix.com>
Mon, 9 Feb 2009 17:21:46 +0000 (17:21 +0000)
committerVincent Hanquez <vincent.hanquez@eu.citrix.com>
Mon, 9 Feb 2009 17:21:46 +0000 (17:21 +0000)
librt/sh_open.c [new file with mode: 0644]
librt/sh_unlink.c [new file with mode: 0644]

diff --git a/librt/sh_open.c b/librt/sh_open.c
new file mode 100644 (file)
index 0000000..cb92c3a
--- /dev/null
@@ -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;
+}
diff --git a/librt/sh_unlink.c b/librt/sh_unlink.c
new file mode 100644 (file)
index 0000000..cf259c6
--- /dev/null
@@ -0,0 +1,28 @@
+/* shm_unlink - remove a shared memory file */
+
+/* Copyright 2002, Red Hat Inc. */
+
+#include <sys/types.h>
+#include <sys/mman.h>
+#include <unistd.h>
+#include <string.h>
+#include <limits.h>
+
+int
+shm_unlink (const char *name)
+{
+  int rc;
+  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);
+
+  rc = unlink (shm_name);
+
+  return rc;
+}