summaryrefslogtreecommitdiffstats
path: root/src/libutil/util.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/libutil/util.c')
-rw-r--r--src/libutil/util.c41
1 files changed, 41 insertions, 0 deletions
diff --git a/src/libutil/util.c b/src/libutil/util.c
index cf6101e4d..f3effe5cf 100644
--- a/src/libutil/util.c
+++ b/src/libutil/util.c
@@ -2276,3 +2276,44 @@ rspamd_file_xmap (const char *fname, guint mode,
return map;
}
+
+
+gpointer
+rspamd_shmem_xmap (const char *fname, guint mode,
+ gsize *size)
+{
+ gint fd;
+ struct stat sb;
+ gpointer map;
+
+ g_assert (fname != NULL);
+ g_assert (size != NULL);
+
+ if (mode & PROT_WRITE) {
+ fd = shm_open (fname, O_RDWR, 0);
+ }
+ else {
+ fd = shm_open (fname, O_RDONLY, 0);
+ }
+
+ if (fd == -1) {
+ return NULL;
+ }
+
+ if (fstat (fd, &sb) == -1) {
+ close (fd);
+
+ return NULL;
+ }
+
+ map = mmap (NULL, sb.st_size, mode, MAP_SHARED, fd, 0);
+ close (fd);
+
+ if (map == MAP_FAILED) {
+ return NULL;
+ }
+
+ *size = sb.st_size;
+
+ return map;
+}