Mercurial > hg > octave-terminal
changeset 7730:b68e44c90afe
file-io.cc (do_stream_open): return -1 for directories
author | John W. Eaton <jwe@octave.org> |
---|---|
date | Thu, 24 Apr 2008 02:51:49 -0400 |
parents | 6f2b2cc4b957 |
children | 2d2a969c731c |
files | src/ChangeLog src/file-io.cc |
diffstat | 2 files changed, 40 insertions(+), 33 deletions(-) [+] |
line wrap: on
line diff
--- a/src/ChangeLog +++ b/src/ChangeLog @@ -1,3 +1,7 @@ +2008-04-24 John W. Eaton <jwe@octave.org> + + * file-io.cc (do_stream_open): Return -1 for directories. + 2008-04-23 John W. Eaton <jwe@octave.org> * DLD-FUNCTIONS/__qp__.cc (qp): Avoid bounds error when removing
--- a/src/file-io.cc +++ b/src/file-io.cc @@ -415,12 +415,12 @@ { std::string fname = file_ops::tilde_expand (name); + file_stat fs (fname); + if (! (md & std::ios::out || octave_env::absolute_pathname (fname) || octave_env::rooted_relative_pathname (fname))) { - file_stat fs (fname); - if (! fs.exists ()) { std::string tmp = octave_env::make_absolute @@ -434,49 +434,52 @@ } } } - - std::string tmode = mode; - - // Use binary mode if 't' is not specified, but don't add - // 'b' if it is already present. + + if (! fs.is_dir ()) + { + std::string tmode = mode; - size_t bpos = tmode.find ('b'); - size_t tpos = tmode.find ('t'); + // Use binary mode if 't' is not specified, but don't add + // 'b' if it is already present. - if (bpos == NPOS && tpos == NPOS) - tmode += 'b'; + size_t bpos = tmode.find ('b'); + size_t tpos = tmode.find ('t'); + + if (bpos == NPOS && tpos == NPOS) + tmode += 'b'; #if defined (HAVE_ZLIB) - size_t pos = tmode.find ('z'); + size_t pos = tmode.find ('z'); - if (pos != NPOS) - { - tmode.erase (pos, 1); + if (pos != NPOS) + { + tmode.erase (pos, 1); + + gzFile fptr = ::gzopen (fname.c_str (), tmode.c_str ()); - gzFile fptr = ::gzopen (fname.c_str (), tmode.c_str ()); - - if (fptr) - retval = octave_zstdiostream::create (fname, fptr, md, flt_fmt); - else - { - using namespace std; - retval.error (::strerror (errno)); + if (fptr) + retval = octave_zstdiostream::create (fname, fptr, md, flt_fmt); + else + { + using namespace std; + retval.error (::strerror (errno)); + } } - } - else + else #endif - { - FILE *fptr = ::fopen (fname.c_str (), tmode.c_str ()); + { + FILE *fptr = ::fopen (fname.c_str (), tmode.c_str ()); - retval = octave_stdiostream::create (fname, fptr, md, flt_fmt); + retval = octave_stdiostream::create (fname, fptr, md, flt_fmt); - if (! fptr) - { - using namespace std; - retval.error (::strerror (errno)); + if (! fptr) + { + using namespace std; + retval.error (::strerror (errno)); + } } + } - } }