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, size_t *len, int writeable)
22 int fd = ucw_open(name, writeable ? O_RDWR : O_RDONLY);
27 die("open(%s): %m", name);
28 if (ucw_fstat(fd, &st) < 0)
29 die("fstat(%s): %m", name);
30 if ((uintmax_t)st.st_size > SIZE_MAX)
31 die("mmap(%s): File too large", name);
36 x = mmap(NULL, st.st_size, writeable ? (PROT_READ | PROT_WRITE) : PROT_READ, MAP_SHARED, fd, 0);
38 die("mmap(%s): %m", name);
40 else /* For empty file, we can return any non-zero address */
47 munmap_file(void *start, size_t len)