Mercurial > dovecot > original-hg > dovecot-1.2
changeset 1939:4698c121bae3 HEAD
changes
author | Timo Sirainen <tss@iki.fi> |
---|---|
date | Fri, 30 Apr 2004 23:17:15 +0300 |
parents | a2eaa322ca8c |
children | 876bd2849a00 |
files | src/lib-index/mail-index.c |
diffstat | 1 files changed, 13 insertions(+), 29 deletions(-) [+] |
line wrap: on
line diff
--- a/src/lib-index/mail-index.c Thu Apr 29 15:59:16 2004 +0300 +++ b/src/lib-index/mail-index.c Fri Apr 30 23:17:15 2004 +0300 @@ -177,23 +177,20 @@ struct mail_index_map *map) { struct mail_index_header hdr; - void *data; + void *data = NULL; ssize_t ret; size_t pos, records_size; - do { - memset(&hdr, 0, sizeof(hdr)); + memset(&hdr, 0, sizeof(hdr)); - ret = 1; - for (pos = 0; ret > 0 && pos < sizeof(hdr); ) { - ret = pread(index->fd, PTR_OFFSET(&hdr, pos), - sizeof(hdr) - pos, pos); - if (ret > 0) - pos += ret; - } - if (ret < 0 || pos < MAIL_INDEX_HEADER_MIN_SIZE) - break; - + ret = 1; + for (pos = 0; ret > 0 && pos < sizeof(hdr); ) { + ret = pread(index->fd, PTR_OFFSET(&hdr, pos), + sizeof(hdr) - pos, pos); + if (ret > 0) + pos += ret; + } + if (ret >= 0 && pos >= MAIL_INDEX_HEADER_MIN_SIZE) { records_size = hdr.messages_count * sizeof(struct mail_index_record); @@ -209,7 +206,7 @@ ret = pread_full(index->fd, data, records_size, hdr.header_size); - } while (0); + } if (ret < 0) { if (errno == ESTALE) @@ -265,25 +262,12 @@ int mail_index_map(struct mail_index *index, int force) { struct mail_index_map *map; - size_t used_size; int ret; - if (index->map != NULL && MAIL_INDEX_MAP_IS_IN_MEMORY(index->map)) { - /* FIXME: can we avoid reading it? */ - map = index->map; - } else if (index->map != NULL) { + if (index->map != NULL) { map = index->map; - - /* see if re-mmaping is needed (file has grown) */ - used_size = map->hdr->header_size + - map->hdr->messages_count * - sizeof(struct mail_index_record); - if (map->mmap_size >= used_size && !force) { - /* update log file position in case it has changed */ - map->log_file_seq = map->hdr->log_file_seq; - map->log_file_offset = map->hdr->log_file_offset; + if (map != NULL && !force) return 1; - } if (map->mmap_base != NULL) { if (munmap(map->mmap_base, map->mmap_size) < 0)