Support/FileSystem: Add rename implementation.

llvm-svn: 120818
This commit is contained in:
Michael J. Spencer 2010-12-03 17:53:55 +00:00
parent 6e74e11c85
commit 409f556a2f
2 changed files with 32 additions and 0 deletions

View File

@ -200,6 +200,19 @@ error_code remove(const Twine &path, bool &existed) {
return make_error_code(errc::success);
}
error_code rename(const Twine &from, const Twine &to) {
// Get arguments.
SmallString<128> from_storage;
SmallString<128> to_storage;
StringRef f = from.toNullTerminatedStringRef(from_storage);
StringRef t = to.toNullTerminatedStringRef(to_storage);
if (::rename(f.begin(), t.begin()) == -1)
return error_code(errno, system_category());
return make_error_code(errc::success);
}
error_code exists(const Twine &path, bool &result) {
SmallString<128> path_storage;
StringRef p = path.toNullTerminatedStringRef(path_storage);

View File

@ -271,6 +271,25 @@ error_code remove(const Twine &path, bool &existed) {
return make_error_code(errc::success);
}
error_code rename(const Twine &from, const Twine &to) {
// Get arguments.
SmallString<128> from_storage;
SmallString<128> to_storage;
StringRef f = from.toStringRef(from_storage);
StringRef t = to.toStringRef(to_storage);
// Convert to utf-16.
SmallVector<wchar_t, 128> wide_from;
SmallVector<wchar_t, 128> wide_to;
if (error_code ec = UTF8ToUTF16(f, wide_from)) return ec;
if (error_code ec = UTF8ToUTF16(t, wide_to)) return ec;
if (!::MoveFileW(wide_from.begin(), wide_to.begin()))
return make_error_code(windows_error(::GetLastError()));
return make_error_code(errc::success);
}
error_code exists(const Twine &path, bool &result) {
SmallString<128> path_storage;
SmallVector<wchar_t, 128> path_utf16;