- *ret = (uint8_t*) d + (offset - woffset);
- return 1;
-}
-
-static int fd_cmp(const void *_a, const void *_b) {
- const FileDescriptor *a = _a, *b = _b;
-
- if (a->fd < b->fd)
- return -1;
- if (a->fd > b->fd)
- return 1;
-
- return 0;
-}
-
-static int mmap_cache_get_fd_index(MMapCache *m, int fd, unsigned *fd_index) {
- FileDescriptor *j;
-
- assert(m);
- assert(fd >= 0);
- assert(fd_index);
-
- j = bsearch(&fd, m->by_fd, m->n_fds, sizeof(m->by_fd[0]), fd_cmp);
- if (!j) {
- if (m->n_fds >= m->fds_max)
- return -E2BIG;
-
- j = m->by_fd + m->n_fds ++;
- j->fd = fd;
- j->windows = (unsigned) -1;
-
- qsort(m->by_fd, m->n_fds, sizeof(m->by_fd[0]), fd_cmp);
- j = bsearch(&fd, m->by_fd, m->n_fds, sizeof(m->by_fd[0]), fd_cmp);
- }
-
- *fd_index = (unsigned) (j - m->by_fd);
- return 0;
-}
-
-static bool mmap_cache_test_window(
- MMapCache *m,
- unsigned w,
- uint64_t offset,
- uint64_t size) {
- Window *v;