X-Git-Url: http://mj.ucw.cz/gitweb/?a=blobdiff_plain;f=ucw%2Fio-mmap.c;h=1a3f1438102f2371da3ec2ecfde5ef9626159c78;hb=959566090f98dd31eaa67d3d5959b641e5fe902b;hp=30000b004e6b2f02b96bb52765ab1dd00edb42ac;hpb=6e1e67a5221c1c31c8dffe8705e6a450f302ba8b;p=libucw.git diff --git a/ucw/io-mmap.c b/ucw/io-mmap.c index 30000b00..1a3f1438 100644 --- a/ucw/io-mmap.c +++ b/ucw/io-mmap.c @@ -7,8 +7,8 @@ * of the GNU Lesser General Public License. */ -#include "ucw/lib.h" -#include "ucw/io.h" +#include +#include #include #include @@ -17,16 +17,18 @@ #include void * -mmap_file(const char *name, unsigned *len, int writeable) +mmap_file(const char *name, size_t *len, int writeable) { - int fd = open(name, writeable ? O_RDWR : O_RDONLY); - struct stat st; + int fd = ucw_open(name, writeable ? O_RDWR : O_RDONLY); + ucw_stat_t st; void *x; if (fd < 0) die("open(%s): %m", name); - if (fstat(fd, &st) < 0) + if (ucw_fstat(fd, &st) < 0) die("fstat(%s): %m", name); + if ((uintmax_t)st.st_size > SIZE_MAX) + die("mmap(%s): File too large", name); if (len) *len = st.st_size; if (st.st_size) @@ -42,7 +44,7 @@ mmap_file(const char *name, unsigned *len, int writeable) } void -munmap_file(void *start, unsigned len) +munmap_file(void *start, size_t len) { munmap(start, len); }