Make WvStreams compile with gcc 4.4.
[wvstreams.git] / utils / wvshmzone.cc
blobf704447ec443d3dc6c234100e399dc9b03b3b1e8
1 /*
2 * Worldvisions Weaver Software:
3 * Copyright (C) 1997-2002 Net Integration Technologies, Inc.
5 * A shared-memory zone via mmap(). See wvshmzone.h.
6 */
7 #include "wvshmzone.h"
8 #include <sys/mman.h>
9 #include <sys/types.h>
10 #include <sys/stat.h>
11 #include <fcntl.h>
12 #include <assert.h>
13 #include <errno.h>
14 #include <unistd.h>
16 WvShmZone::WvShmZone(size_t _size)
18 size = (int)_size;
19 assert(size > 0);
21 buf = NULL;
23 fd = open("/dev/zero", O_RDWR);
24 if (fd < 0)
26 seterr(errno);
27 return;
30 buf = mmap(0, size, PROT_READ|PROT_WRITE, MAP_SHARED, fd, 0);
32 if (!buf)
34 seterr(errno);
35 return;
40 WvShmZone::~WvShmZone()
42 if (buf)
43 munmap(buf, size);
44 if (fd >= 0)
45 close(fd);