Mercurial > hg > octave-lyh
diff src/dirfns.cc @ 7970:b6d4c644b4b6
Fmkdir: improve compatibility
author | John W. Eaton <jwe@octave.org> |
---|---|
date | Thu, 24 Jul 2008 13:03:36 -0400 |
parents | 05ee52d7fad6 |
children | a2ab20ba78f7 |
line wrap: on
line diff
--- a/src/dirfns.cc +++ b/src/dirfns.cc @@ -257,16 +257,31 @@ { std::string msg; - int status = file_ops::mkdir (file_ops::tilde_expand (dirname), - 0777, msg); + dirname = file_ops::tilde_expand (dirname); + + file_stat fs (dirname); - if (status < 0) + if (fs && fs.is_dir ()) { + // For compatibility with Matlab, we return true when the + // directory already exists. + retval(2) = "mkdir"; - retval(1) = msg; + retval(1) = "directory exists"; + retval(0) = true; } else - retval(0) = true; + { + int status = file_ops::mkdir (dirname, 0777, msg); + + if (status < 0) + { + retval(2) = "mkdir"; + retval(1) = msg; + } + else + retval(0) = true; + } } else print_usage ();