Skip to content

Commit

Permalink
istream-mmap: Mark stream eof on error and copy errno
Browse files Browse the repository at this point in the history
  • Loading branch information
cmouse authored and GitLab committed Jan 7, 2017
1 parent 89e0400 commit 90126be
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions src/lib/istream-mmap.c
Expand Up @@ -179,6 +179,7 @@ static int fstat_cached(struct mmap_istream *mstream)
if (fstat(mstream->istream.fd, &mstream->istream.statbuf) < 0) {
i_error("mmap_istream.fstat(%s) failed: %m",
i_stream_get_name(&mstream->istream.istream));
mstream->istream.istream.stream_errno = errno;
return -1;
}

Expand All @@ -205,18 +206,21 @@ struct istream *i_stream_create_mmap(int fd, size_t block_size,
if (mmap_pagemask == 0)
mmap_pagemask = mmap_get_page_size()-1;

mstream = i_new(struct mmap_istream, 1);

if (v_size == 0) {
if (fstat(fd, &st) < 0)
if (fstat(fd, &st) < 0) {
i_error("i_stream_create_mmap(): fstat() failed: %m");
else {
mstream->istream.istream.eof = TRUE;
mstream->istream.istream.stream_errno = errno;
} else {
v_size = st.st_size;
if (start_offset > v_size)
start_offset = v_size;
v_size -= start_offset;
}
}

mstream = i_new(struct mmap_istream, 1);
mstream->autoclose_fd = autoclose_fd;
mstream->v_size = v_size;

Expand Down

0 comments on commit 90126be

Please sign in to comment.