From: Mikko Rasa Date: Thu, 10 Feb 2011 21:45:57 +0000 (+0000) Subject: Add rename function X-Git-Url: http://git.tdb.fi/?a=commitdiff_plain;h=aa31c2bbb399ded6493f7edc419b1a500ed25895;p=libs%2Fcore.git Add rename function --- diff --git a/source/utils.cpp b/source/utils.cpp index 22fe1ac..8f06757 100644 --- a/source/utils.cpp +++ b/source/utils.cpp @@ -6,6 +6,7 @@ Distributed under the LGPL */ #include +#include #include #ifndef WIN32 #include @@ -137,6 +138,12 @@ Path realpath(const Path &path) #endif } +void rename(const Path &from, const Path &to) +{ + if(::rename(from.str().c_str(), to.str().c_str())==-1) + throw SystemError("rename failed", errno); +} + void unlink(const Path &path) { if(::unlink(path.str().c_str())==-1) diff --git a/source/utils.h b/source/utils.h index 9b4a1e0..c582c22 100644 --- a/source/utils.h +++ b/source/utils.h @@ -46,6 +46,9 @@ Path realpath(const Path &path); /// Removes a file void unlink(const Path &path); +/// Renames a file. Existing file, if any, is overwritten. +void rename(const Path &from, const Path &to); + /// Makes a path relative to some base path. That is, base/result==path. Path relative(const Path &path, const Path &base);