Mercurial > dovecot > core-2.2
changeset 11986:faac0d16d141
i_stream_create_fd(): If opening a directory, set stream_errno=EISDIR
author | Timo Sirainen <tss@iki.fi> |
---|---|
date | Thu, 12 Aug 2010 16:29:15 +0100 |
parents | 25f401276f9b |
children | 651e51de34b7 |
files | src/lib/istream-file.c |
diffstat | 1 files changed, 16 insertions(+), 1 deletions(-) [+] |
line wrap: on
line diff
--- a/src/lib/istream-file.c Thu Aug 12 16:15:13 2010 +0100 +++ b/src/lib/istream-file.c Thu Aug 12 16:29:15 2010 +0100 @@ -172,6 +172,7 @@ { struct file_istream *fstream; struct stat st; + bool is_file; fstream = i_new(struct file_istream, 1); fstream->autoclose_fd = autoclose_fd; @@ -184,7 +185,21 @@ fstream->istream.stat = i_stream_file_stat; /* if it's a file, set the flags properly */ - if (fd == -1 || (fstat(fd, &st) == 0 && S_ISREG(st.st_mode))) { + if (fd == -1) + is_file = TRUE; + else if (fstat(fd, &st) < 0) + is_file = FALSE; + else if (S_ISREG(st.st_mode)) + is_file = TRUE; + else if (!S_ISDIR(st.st_mode)) + is_file = FALSE; + else { + /* we're trying to open a directory. + we're not designed for it. */ + fstream->istream.istream.stream_errno = EISDIR; + is_file = FALSE; + } + if (is_file) { fstream->file = TRUE; fstream->istream.istream.blocking = TRUE; fstream->istream.istream.seekable = TRUE;