From: James Turner Date: Fri, 21 Oct 2011 08:36:33 +0000 (+0100) Subject: SGPath rename wrapper. Let's see what Win32 makes of it. X-Git-Url: https://git.mxchange.org/?a=commitdiff_plain;h=c82df0590dd46347e2f1d0dca4cc3712f67f3654;p=simgear.git SGPath rename wrapper. Let's see what Win32 makes of it. --- diff --git a/simgear/misc/sg_path.cxx b/simgear/misc/sg_path.cxx index 53504a20..bff1a61c 100644 --- a/simgear/misc/sg_path.cxx +++ b/simgear/misc/sg_path.cxx @@ -471,3 +471,16 @@ bool SGPath::operator!=(const SGPath& other) const return (path != other.path); } +bool SGPath::rename(const SGPath& newName) +{ + if (::rename(c_str(), newName.c_str()) != 0) { + SG_LOG(SG_IO, SG_WARN, "renamed failed: from " << str() << " to " << newName.str() + << " reason: " << strerror(errno)); + return false; + } + + path = newName.path; + _cached = false; + return true; +} + diff --git a/simgear/misc/sg_path.hxx b/simgear/misc/sg_path.hxx index 27b375d9..e71c5f54 100644 --- a/simgear/misc/sg_path.hxx +++ b/simgear/misc/sg_path.hxx @@ -213,6 +213,13 @@ public: * modification time of the file */ time_t modTime() const; + + /** + * rename the file / directory we point at, to a new name + * this may fail if the new location is on a different volume / share, + * or if the destination already exists, or is not writeable + */ + bool rename(const SGPath& newName); private: void fix();