Mercurial > octave
changeset 31832:c82c5f7a1579
use octave::sys::rename for consistency (bug #63803)
* load-save.cc (load_save_system::save): Use octave::sys::rename for
consistency with other functions in Octave that rename files.
author | John W. Eaton <jwe@octave.org> |
---|---|
date | Wed, 15 Feb 2023 20:02:04 -0500 |
parents | 45ac4c5272e9 |
children | 4d8c66b8ea3e |
files | libinterp/corefcn/load-save.cc |
diffstat | 1 files changed, 10 insertions(+), 14 deletions(-) [+] |
line wrap: on
line diff
--- a/libinterp/corefcn/load-save.cc Wed Feb 15 19:32:12 2023 -0500 +++ b/libinterp/corefcn/load-save.cc Wed Feb 15 20:02:04 2023 -0500 @@ -28,7 +28,6 @@ #endif #include <cstring> -#include <cstdio> #include <fstream> #include <iomanip> @@ -1551,19 +1550,16 @@ } } - // If we are all the way here without Octave crashing or running out of - // memory etc, then we can say that writing to the temporary file - // was successful. So now we try to rename it to the actual file - // that was specified. - try - { - rename (fname.c_str (), desiredname.c_str ()); - } - catch (std::exception& e) - { - error ("save: unable to save to %s %s", - desiredname.c_str (), e.what ()); - } + // If we are all the way here without Octave crashing or running + // out of memory etc, then we can say that writing to the + // temporary file was successful. So now we try to rename it to + // the actual file that was specified. + + std::string msg; + + if (octave::sys::rename (fname, desiredname, msg) < 0) + error ("save: unable to save to %s %s", + desiredname.c_str (), msg.c_str ()); } return retval;