Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(945)

Unified Diff: runtime/bin/directory_win.cc

Issue 2439173002: [windows] Make most file_win.cc functions use malloc for string conversions. (Closed)
Patch Set: Fix typo Created 4 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « build/config/compiler/BUILD.gn ('k') | runtime/bin/file.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: runtime/bin/directory_win.cc
diff --git a/runtime/bin/directory_win.cc b/runtime/bin/directory_win.cc
index efaaaf90a6e7ee6f08e5e94b2f5e6a0157d08900..4ebf512307e34d980015294ca2e015897f88fde3 100644
--- a/runtime/bin/directory_win.cc
+++ b/runtime/bin/directory_win.cc
@@ -50,8 +50,8 @@ const char* PathBuffer::AsScopedString() const {
bool PathBuffer::Add(const char* name) {
- const wchar_t* wide_name = StringUtilsWin::Utf8ToWide(name);
- return AddW(wide_name);
+ Utf8ToWideScope wide_name(name);
+ return AddW(wide_name.wide());
}
@@ -377,8 +377,8 @@ static Directory::ExistsResult ExistsHelper(const wchar_t* dir_name) {
Directory::ExistsResult Directory::Exists(const char* dir_name) {
- const wchar_t* system_name = StringUtilsWin::Utf8ToWide(dir_name);
- return ExistsHelper(system_name);
+ Utf8ToWideScope system_name(dir_name);
+ return ExistsHelper(system_name.wide());
}
@@ -412,19 +412,19 @@ const char* Directory::Current() {
bool Directory::SetCurrent(const char* path) {
- const wchar_t* system_path = StringUtilsWin::Utf8ToWide(path);
- bool result = SetCurrentDirectoryW(system_path) != 0;
+ Utf8ToWideScope system_path(path);
+ bool result = SetCurrentDirectoryW(system_path.wide()) != 0;
return result;
}
bool Directory::Create(const char* dir_name) {
- const wchar_t* system_name = StringUtilsWin::Utf8ToWide(dir_name);
- int create_status = CreateDirectoryW(system_name, NULL);
+ Utf8ToWideScope system_name(dir_name);
+ int create_status = CreateDirectoryW(system_name.wide(), NULL);
// If the directory already existed, treat it as a success.
if ((create_status == 0) &&
(GetLastError() == ERROR_ALREADY_EXISTS) &&
- (ExistsHelper(system_name) == EXISTS)) {
+ (ExistsHelper(system_name.wide()) == EXISTS)) {
return true;
}
return (create_status != 0);
@@ -446,8 +446,8 @@ const char* Directory::CreateTemp(const char* prefix) {
// descriptor inherited from its parent directory.
// The return value is Dart_ScopeAllocated.
PathBuffer path;
- const wchar_t* system_prefix = StringUtilsWin::Utf8ToWide(prefix);
- if (!path.AddW(system_prefix)) {
+ Utf8ToWideScope system_prefix(prefix);
+ if (!path.AddW(system_prefix.wide())) {
return NULL;
}
@@ -481,16 +481,16 @@ const char* Directory::CreateTemp(const char* prefix) {
bool Directory::Delete(const char* dir_name, bool recursive) {
bool result = false;
- const wchar_t* system_dir_name = StringUtilsWin::Utf8ToWide(dir_name);
+ Utf8ToWideScope system_dir_name(dir_name);
if (!recursive) {
if (File::GetType(dir_name, true) == File::kIsDirectory) {
- result = (RemoveDirectoryW(system_dir_name) != 0);
+ result = (RemoveDirectoryW(system_dir_name.wide()) != 0);
} else {
SetLastError(ERROR_FILE_NOT_FOUND);
}
} else {
PathBuffer path;
- if (path.AddW(system_dir_name)) {
+ if (path.AddW(system_dir_name.wide())) {
result = DeleteRecursively(&path);
}
}
@@ -499,13 +499,13 @@ bool Directory::Delete(const char* dir_name, bool recursive) {
bool Directory::Rename(const char* path, const char* new_path) {
- const wchar_t* system_path = StringUtilsWin::Utf8ToWide(path);
- const wchar_t* system_new_path = StringUtilsWin::Utf8ToWide(new_path);
- ExistsResult exists = ExistsHelper(system_path);
+ Utf8ToWideScope system_path(path);
+ Utf8ToWideScope system_new_path(new_path);
+ ExistsResult exists = ExistsHelper(system_path.wide());
if (exists != EXISTS) {
return false;
}
- ExistsResult new_exists = ExistsHelper(system_new_path);
+ ExistsResult new_exists = ExistsHelper(system_new_path.wide());
// MoveFile does not allow replacing exising directories. Therefore,
// if the new_path is currently a directory we need to delete it
// first.
@@ -517,7 +517,7 @@ bool Directory::Rename(const char* path, const char* new_path) {
}
DWORD flags = MOVEFILE_WRITE_THROUGH;
int move_status =
- MoveFileExW(system_path, system_new_path, flags);
+ MoveFileExW(system_path.wide(), system_new_path.wide(), flags);
return (move_status != 0);
}
« no previous file with comments | « build/config/compiler/BUILD.gn ('k') | runtime/bin/file.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698