2 * UCW Library -- Mapping of Files
4 * (c) 1999--2012 Martin Mares <mj@ucw.cz>
6 * This software may be freely distributed and used according to the terms
7 * of the GNU Lesser General Public License.
20 mmap_file(const char *name, unsigned *len, int writeable)
22 int fd = open(name, writeable ? O_RDWR : O_RDONLY);
27 die("open(%s): %m", name);
28 if (fstat(fd, &st) < 0)
29 die("fstat(%s): %m", name);
34 x = mmap(NULL, st.st_size, writeable ? (PROT_READ | PROT_WRITE) : PROT_READ, MAP_SHARED, fd, 0);
36 die("mmap(%s): %m", name);
38 else /* For empty file, we can return any non-zero address */
45 munmap_file(void *start, unsigned len)