select: overhaul for time64
[musl.git] / src / time / __map_file.c
blob9d376222fdd5ebd7ee674a5c65e833be82deb6ef
1 #include <sys/mman.h>
2 #include <fcntl.h>
3 #include <sys/stat.h>
4 #include "syscall.h"
6 const char unsigned *__map_file(const char *pathname, size_t *size)
8 struct stat st;
9 const unsigned char *map = MAP_FAILED;
10 int fd = sys_open(pathname, O_RDONLY|O_CLOEXEC|O_NONBLOCK);
11 if (fd < 0) return 0;
12 if (!syscall(SYS_fstat, fd, &st)) {
13 map = __mmap(0, st.st_size, PROT_READ, MAP_SHARED, fd, 0);
14 *size = st.st_size;
16 __syscall(SYS_close, fd);
17 return map == MAP_FAILED ? 0 : map;