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

Side by Side Diff: webrtc/base/win32filesystem.cc

Issue 2685783014: Replace NULL with nullptr in all C++ files. (Closed)
Patch Set: Fixing android. Created 3 years, 10 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 unified diff | Download patch
OLDNEW
1 /* 1 /*
2 * Copyright 2004 The WebRTC Project Authors. All rights reserved. 2 * Copyright 2004 The WebRTC Project Authors. All rights reserved.
3 * 3 *
4 * Use of this source code is governed by a BSD-style license 4 * Use of this source code is governed by a BSD-style license
5 * that can be found in the LICENSE file in the root of the source 5 * that can be found in the LICENSE file in the root of the source
6 * tree. An additional intellectual property rights grant can be found 6 * tree. An additional intellectual property rights grant can be found
7 * in the file PATENTS. All contributing project authors may 7 * in the file PATENTS. All contributing project authors may
8 * be found in the AUTHORS file in the root of the source tree. 8 * be found in the AUTHORS file in the root of the source tree.
9 */ 9 */
10 10
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
53 53
54 // Directory doesn't exist, look up one directory level 54 // Directory doesn't exist, look up one directory level
55 if (!pathname.parent_folder().empty()) { 55 if (!pathname.parent_folder().empty()) {
56 Pathname parent(pathname); 56 Pathname parent(pathname);
57 parent.SetFolder(pathname.parent_folder()); 57 parent.SetFolder(pathname.parent_folder());
58 if (!CreateFolder(parent)) { 58 if (!CreateFolder(parent)) {
59 return false; 59 return false;
60 } 60 }
61 } 61 }
62 62
63 return (::CreateDirectory(path16.c_str(), NULL) != 0); 63 return (::CreateDirectory(path16.c_str(), nullptr) != 0);
64 } 64 }
65 65
66 FileStream *Win32Filesystem::OpenFile(const Pathname &filename, 66 FileStream *Win32Filesystem::OpenFile(const Pathname &filename,
67 const std::string &mode) { 67 const std::string &mode) {
68 FileStream *fs = new FileStream(); 68 FileStream *fs = new FileStream();
69 if (fs && !fs->Open(filename.pathname().c_str(), mode.c_str(), NULL)) { 69 if (fs && !fs->Open(filename.pathname().c_str(), mode.c_str(), nullptr)) {
70 delete fs; 70 delete fs;
71 fs = NULL; 71 fs = nullptr;
72 } 72 }
73 return fs; 73 return fs;
74 } 74 }
75 75
76 bool Win32Filesystem::DeleteFile(const Pathname &filename) { 76 bool Win32Filesystem::DeleteFile(const Pathname &filename) {
77 LOG(LS_INFO) << "Deleting file " << filename.pathname(); 77 LOG(LS_INFO) << "Deleting file " << filename.pathname();
78 if (!IsFile(filename)) { 78 if (!IsFile(filename)) {
79 RTC_DCHECK(IsFile(filename)); 79 RTC_DCHECK(IsFile(filename));
80 return false; 80 return false;
81 } 81 }
(...skipping 16 matching lines...) Expand all
98 !::GetLongPathName(buffer, buffer, arraysize(buffer))) 98 !::GetLongPathName(buffer, buffer, arraysize(buffer)))
99 return false; 99 return false;
100 size_t len = strlen(buffer); 100 size_t len = strlen(buffer);
101 if ((len > 0) && (buffer[len-1] != '\\')) { 101 if ((len > 0) && (buffer[len-1] != '\\')) {
102 len += strcpyn(buffer + len, arraysize(buffer) - len, L"\\"); 102 len += strcpyn(buffer + len, arraysize(buffer) - len, L"\\");
103 } 103 }
104 if (len >= arraysize(buffer) - 1) 104 if (len >= arraysize(buffer) - 1)
105 return false; 105 return false;
106 pathname.clear(); 106 pathname.clear();
107 pathname.SetFolder(ToUtf8(buffer)); 107 pathname.SetFolder(ToUtf8(buffer));
108 if (append != NULL) { 108 if (append != nullptr) {
109 RTC_DCHECK(!append->empty()); 109 RTC_DCHECK(!append->empty());
110 pathname.AppendFolder(*append); 110 pathname.AppendFolder(*append);
111 } 111 }
112 return !create || CreateFolder(pathname); 112 return !create || CreateFolder(pathname);
113 } 113 }
114 114
115 std::string Win32Filesystem::TempFilename(const Pathname &dir, 115 std::string Win32Filesystem::TempFilename(const Pathname &dir,
116 const std::string &prefix) { 116 const std::string &prefix) {
117 wchar_t filename[MAX_PATH]; 117 wchar_t filename[MAX_PATH];
118 if (::GetTempFileName(ToUtf16(dir.pathname()).c_str(), 118 if (::GetTempFileName(ToUtf16(dir.pathname()).c_str(),
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after
203 FileTimeToUnixTime(data.ftLastAccessTime, time); 203 FileTimeToUnixTime(data.ftLastAccessTime, time);
204 break; 204 break;
205 default: 205 default:
206 return false; 206 return false;
207 } 207 }
208 return true; 208 return true;
209 } 209 }
210 210
211 bool Win32Filesystem::GetAppPathname(Pathname* path) { 211 bool Win32Filesystem::GetAppPathname(Pathname* path) {
212 TCHAR buffer[MAX_PATH + 1]; 212 TCHAR buffer[MAX_PATH + 1];
213 if (0 == ::GetModuleFileName(NULL, buffer, arraysize(buffer))) 213 if (0 == ::GetModuleFileName(nullptr, buffer, arraysize(buffer)))
214 return false; 214 return false;
215 path->SetPathname(ToUtf8(buffer)); 215 path->SetPathname(ToUtf8(buffer));
216 return true; 216 return true;
217 } 217 }
218 218
219 bool Win32Filesystem::GetAppDataFolder(Pathname* path, bool per_user) { 219 bool Win32Filesystem::GetAppDataFolder(Pathname* path, bool per_user) {
220 RTC_DCHECK(!organization_name_.empty()); 220 RTC_DCHECK(!organization_name_.empty());
221 RTC_DCHECK(!application_name_.empty()); 221 RTC_DCHECK(!application_name_.empty());
222 TCHAR buffer[MAX_PATH + 1]; 222 TCHAR buffer[MAX_PATH + 1];
223 int csidl = per_user ? CSIDL_LOCAL_APPDATA : CSIDL_COMMON_APPDATA; 223 int csidl = per_user ? CSIDL_LOCAL_APPDATA : CSIDL_COMMON_APPDATA;
224 if (!::SHGetSpecialFolderPath(NULL, buffer, csidl, TRUE)) 224 if (!::SHGetSpecialFolderPath(nullptr, buffer, csidl, TRUE))
225 return false; 225 return false;
226 if (!IsCurrentProcessLowIntegrity() && 226 if (!IsCurrentProcessLowIntegrity() &&
227 !::GetLongPathName(buffer, buffer, arraysize(buffer))) 227 !::GetLongPathName(buffer, buffer, arraysize(buffer)))
228 return false; 228 return false;
229 size_t len = strcatn(buffer, arraysize(buffer), __T("\\")); 229 size_t len = strcatn(buffer, arraysize(buffer), __T("\\"));
230 len += strcpyn(buffer + len, arraysize(buffer) - len, 230 len += strcpyn(buffer + len, arraysize(buffer) - len,
231 ToUtf16(organization_name_).c_str()); 231 ToUtf16(organization_name_).c_str());
232 if ((len > 0) && (buffer[len-1] != __T('\\'))) { 232 if ((len > 0) && (buffer[len-1] != __T('\\'))) {
233 len += strcpyn(buffer + len, arraysize(buffer) - len, __T("\\")); 233 len += strcpyn(buffer + len, arraysize(buffer) - len, __T("\\"));
234 } 234 }
(...skipping 16 matching lines...) Expand all
251 return GetTemporaryFolder(*path, true, &filename); 251 return GetTemporaryFolder(*path, true, &filename);
252 } 252 }
253 253
254 bool Win32Filesystem::GetDiskFreeSpace(const Pathname& path, 254 bool Win32Filesystem::GetDiskFreeSpace(const Pathname& path,
255 int64_t* free_bytes) { 255 int64_t* free_bytes) {
256 if (!free_bytes) { 256 if (!free_bytes) {
257 return false; 257 return false;
258 } 258 }
259 char drive[4]; 259 char drive[4];
260 std::wstring drive16; 260 std::wstring drive16;
261 const wchar_t* target_drive = NULL; 261 const wchar_t* target_drive = nullptr;
262 if (path.GetDrive(drive, sizeof(drive))) { 262 if (path.GetDrive(drive, sizeof(drive))) {
263 drive16 = ToUtf16(drive); 263 drive16 = ToUtf16(drive);
264 target_drive = drive16.c_str(); 264 target_drive = drive16.c_str();
265 } else if (path.folder().substr(0, 2) == "\\\\") { 265 } else if (path.folder().substr(0, 2) == "\\\\") {
266 // UNC path, fail. 266 // UNC path, fail.
267 // TODO: Handle UNC paths. 267 // TODO: Handle UNC paths.
268 return false; 268 return false;
269 } else { 269 } else {
270 // The path is probably relative. GetDriveType and GetDiskFreeSpaceEx 270 // The path is probably relative. GetDriveType and GetDiskFreeSpaceEx
271 // use the current drive if NULL is passed as the drive name. 271 // use the current drive if null is passed as the drive name.
272 // TODO: Add method to Pathname to determine if the path is relative. 272 // TODO: Add method to Pathname to determine if the path is relative.
273 // TODO: Add method to Pathname to convert a path to absolute. 273 // TODO: Add method to Pathname to convert a path to absolute.
274 } 274 }
275 UINT drive_type = ::GetDriveType(target_drive); 275 UINT drive_type = ::GetDriveType(target_drive);
276 if ((drive_type == DRIVE_REMOTE) || (drive_type == DRIVE_UNKNOWN)) { 276 if ((drive_type == DRIVE_REMOTE) || (drive_type == DRIVE_UNKNOWN)) {
277 LOG(LS_VERBOSE) << "Remote or unknown drive: " << drive; 277 LOG(LS_VERBOSE) << "Remote or unknown drive: " << drive;
278 return false; 278 return false;
279 } 279 }
280 280
281 int64_t total_number_of_bytes; // receives the number of bytes on disk 281 int64_t total_number_of_bytes; // receives the number of bytes on disk
282 int64_t total_number_of_free_bytes; // receives the free bytes on disk 282 int64_t total_number_of_free_bytes; // receives the free bytes on disk
283 // make sure things won't change in 64 bit machine 283 // make sure things won't change in 64 bit machine
284 // TODO replace with compile time assert 284 // TODO replace with compile time assert
285 RTC_DCHECK(sizeof(ULARGE_INTEGER) == sizeof(uint64_t)); // NOLINT 285 RTC_DCHECK(sizeof(ULARGE_INTEGER) == sizeof(uint64_t)); // NOLINT
286 if (::GetDiskFreeSpaceEx(target_drive, 286 if (::GetDiskFreeSpaceEx(target_drive,
287 (PULARGE_INTEGER)free_bytes, 287 (PULARGE_INTEGER)free_bytes,
288 (PULARGE_INTEGER)&total_number_of_bytes, 288 (PULARGE_INTEGER)&total_number_of_bytes,
289 (PULARGE_INTEGER)&total_number_of_free_bytes)) { 289 (PULARGE_INTEGER)&total_number_of_free_bytes)) {
290 return true; 290 return true;
291 } else { 291 } else {
292 LOG(LS_VERBOSE) << "GetDiskFreeSpaceEx returns error."; 292 LOG(LS_VERBOSE) << "GetDiskFreeSpaceEx returns error.";
293 return false; 293 return false;
294 } 294 }
295 } 295 }
296 296
297 } // namespace rtc 297 } // namespace rtc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698