2 * UCW Library -- Mapping of Files
4 * (c) 1999--2002 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.
19 mmap_file(byte *name, unsigned *len, int writeable)
21 int fd = open(name, writeable ? O_RDWR : O_RDONLY);
26 die("open(%s): %m", name);
27 if (fstat(fd, &st) < 0)
28 die("fstat(%s): %m", name);
33 x = mmap(NULL, st.st_size, writeable ? (PROT_READ | PROT_WRITE) : PROT_READ, MAP_SHARED, fd, 0);
35 die("mmap(%s): %m", name);
37 else /* For empty file, we can return any non-zero address */
44 munmap_file(void *start, unsigned len)