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

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

Issue 2718663005: Replace NULL with nullptr or null in webrtc/base/. (Closed)
Patch Set: Fixing Windows and formatting issues. Created 3 years, 9 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
« no previous file with comments | « webrtc/base/unixfilesystem.h ('k') | webrtc/base/virtualsocket_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
56 // elsewhere; other places should use GetApp{Data,Temp}Folder() in 56 // elsewhere; other places should use GetApp{Data,Temp}Folder() in
57 // this file. Don't copy/paste. I mean it. 57 // this file. Don't copy/paste. I mean it.
58 char* AppleDataDirectory(); 58 char* AppleDataDirectory();
59 char* AppleTempDirectory(); 59 char* AppleTempDirectory();
60 void AppleAppName(rtc::Pathname* path); 60 void AppleAppName(rtc::Pathname* path);
61 #endif 61 #endif
62 62
63 namespace rtc { 63 namespace rtc {
64 64
65 #if !defined(WEBRTC_ANDROID) && !defined(WEBRTC_MAC) 65 #if !defined(WEBRTC_ANDROID) && !defined(WEBRTC_MAC)
66 char* UnixFilesystem::app_temp_path_ = NULL; 66 char* UnixFilesystem::app_temp_path_ = nullptr;
67 #else 67 #else
68 char* UnixFilesystem::provided_app_data_folder_ = NULL; 68 char* UnixFilesystem::provided_app_data_folder_ = nullptr;
69 char* UnixFilesystem::provided_app_temp_folder_ = NULL; 69 char* UnixFilesystem::provided_app_temp_folder_ = nullptr;
70 70
71 void UnixFilesystem::SetAppDataFolder(const std::string& folder) { 71 void UnixFilesystem::SetAppDataFolder(const std::string& folder) {
72 delete [] provided_app_data_folder_; 72 delete [] provided_app_data_folder_;
73 provided_app_data_folder_ = CopyString(folder); 73 provided_app_data_folder_ = CopyString(folder);
74 } 74 }
75 75
76 void UnixFilesystem::SetAppTempFolder(const std::string& folder) { 76 void UnixFilesystem::SetAppTempFolder(const std::string& folder) {
77 delete [] provided_app_temp_folder_; 77 delete [] provided_app_temp_folder_;
78 provided_app_temp_folder_ = CopyString(folder); 78 provided_app_temp_folder_ = CopyString(folder);
79 } 79 }
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
119 return (0 == ::mkdir(pathname.c_str(), mode)); 119 return (0 == ::mkdir(pathname.c_str(), mode));
120 } 120 }
121 121
122 bool UnixFilesystem::CreateFolder(const Pathname &path) { 122 bool UnixFilesystem::CreateFolder(const Pathname &path) {
123 return CreateFolder(path, 0755); 123 return CreateFolder(path, 0755);
124 } 124 }
125 125
126 FileStream *UnixFilesystem::OpenFile(const Pathname &filename, 126 FileStream *UnixFilesystem::OpenFile(const Pathname &filename,
127 const std::string &mode) { 127 const std::string &mode) {
128 FileStream *fs = new FileStream(); 128 FileStream *fs = new FileStream();
129 if (fs && !fs->Open(filename.pathname().c_str(), mode.c_str(), NULL)) { 129 if (fs && !fs->Open(filename.pathname().c_str(), mode.c_str(), nullptr)) {
130 delete fs; 130 delete fs;
131 fs = NULL; 131 fs = nullptr;
132 } 132 }
133 return fs; 133 return fs;
134 } 134 }
135 135
136 bool UnixFilesystem::DeleteFile(const Pathname &filename) { 136 bool UnixFilesystem::DeleteFile(const Pathname &filename) {
137 LOG(LS_INFO) << "Deleting file:" << filename.pathname(); 137 LOG(LS_INFO) << "Deleting file:" << filename.pathname();
138 138
139 if (!IsFile(filename)) { 139 if (!IsFile(filename)) {
140 RTC_DCHECK(IsFile(filename)); 140 RTC_DCHECK(IsFile(filename));
141 return false; 141 return false;
142 } 142 }
143 return ::unlink(filename.pathname().c_str()) == 0; 143 return ::unlink(filename.pathname().c_str()) == 0;
144 } 144 }
145 145
146 bool UnixFilesystem::DeleteEmptyFolder(const Pathname &folder) { 146 bool UnixFilesystem::DeleteEmptyFolder(const Pathname &folder) {
147 LOG(LS_INFO) << "Deleting folder" << folder.pathname(); 147 LOG(LS_INFO) << "Deleting folder" << folder.pathname();
148 148
149 if (!IsFolder(folder)) { 149 if (!IsFolder(folder)) {
150 RTC_DCHECK(IsFolder(folder)); 150 RTC_DCHECK(IsFolder(folder));
151 return false; 151 return false;
152 } 152 }
153 std::string no_slash(folder.pathname(), 0, folder.pathname().length()-1); 153 std::string no_slash(folder.pathname(), 0, folder.pathname().length()-1);
154 return ::rmdir(no_slash.c_str()) == 0; 154 return ::rmdir(no_slash.c_str()) == 0;
155 } 155 }
156 156
157 bool UnixFilesystem::GetTemporaryFolder(Pathname &pathname, bool create, 157 bool UnixFilesystem::GetTemporaryFolder(Pathname &pathname, bool create,
158 const std::string *append) { 158 const std::string *append) {
159 #if defined(WEBRTC_ANDROID) || defined(WEBRTC_MAC) 159 #if defined(WEBRTC_ANDROID) || defined(WEBRTC_MAC)
160 RTC_DCHECK(provided_app_temp_folder_ != NULL); 160 RTC_DCHECK(provided_app_temp_folder_ != nullptr);
161 pathname.SetPathname(provided_app_temp_folder_, ""); 161 pathname.SetPathname(provided_app_temp_folder_, "");
162 #else 162 #else
163 if (const char* tmpdir = getenv("TMPDIR")) { 163 if (const char* tmpdir = getenv("TMPDIR")) {
164 pathname.SetPathname(tmpdir, ""); 164 pathname.SetPathname(tmpdir, "");
165 } else if (const char* tmp = getenv("TMP")) { 165 } else if (const char* tmp = getenv("TMP")) {
166 pathname.SetPathname(tmp, ""); 166 pathname.SetPathname(tmp, "");
167 } else { 167 } else {
168 #ifdef P_tmpdir 168 #ifdef P_tmpdir
169 pathname.SetPathname(P_tmpdir, ""); 169 pathname.SetPathname(P_tmpdir, "");
170 #else // !P_tmpdir 170 #else // !P_tmpdir
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after
231 StreamInterface *source = OpenFile(old_path, "rb"); 231 StreamInterface *source = OpenFile(old_path, "rb");
232 if (!source) 232 if (!source)
233 return false; 233 return false;
234 234
235 StreamInterface *dest = OpenFile(new_path, "wb"); 235 StreamInterface *dest = OpenFile(new_path, "wb");
236 if (!dest) { 236 if (!dest) {
237 delete source; 237 delete source;
238 return false; 238 return false;
239 } 239 }
240 240
241 while (source->Read(buf, sizeof(buf), &len, NULL) == SR_SUCCESS) 241 while (source->Read(buf, sizeof(buf), &len, nullptr) == SR_SUCCESS)
242 dest->Write(buf, len, NULL, NULL); 242 dest->Write(buf, len, nullptr, nullptr);
243 243
244 delete source; 244 delete source;
245 delete dest; 245 delete dest;
246 return true; 246 return true;
247 } 247 }
248 248
249 bool UnixFilesystem::IsTemporaryPath(const Pathname& pathname) { 249 bool UnixFilesystem::IsTemporaryPath(const Pathname& pathname) {
250 #if defined(WEBRTC_ANDROID) || defined(WEBRTC_MAC) 250 #if defined(WEBRTC_ANDROID) || defined(WEBRTC_MAC)
251 RTC_DCHECK(provided_app_temp_folder_ != NULL); 251 RTC_DCHECK(provided_app_temp_folder_ != nullptr);
252 #endif 252 #endif
253 253
254 const char* const kTempPrefixes[] = { 254 const char* const kTempPrefixes[] = {
255 #if defined(WEBRTC_ANDROID) || defined(WEBRTC_MAC) 255 #if defined(WEBRTC_ANDROID) || defined(WEBRTC_MAC)
256 provided_app_temp_folder_, 256 provided_app_temp_folder_,
257 #if defined(WEBRTC_MAC) && !defined(WEBRTC_IOS) 257 #if defined(WEBRTC_MAC) && !defined(WEBRTC_IOS)
258 "/private/tmp/", "/private/var/tmp/", "/private/var/folders/", 258 "/private/tmp/", "/private/var/tmp/", "/private/var/folders/",
259 #endif // WEBRTC_MAC && !defined(WEBRTC_IOS) 259 #endif // WEBRTC_MAC && !defined(WEBRTC_IOS)
260 #else 260 #else
261 "/tmp/", "/var/tmp/", 261 "/tmp/", "/var/tmp/",
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
308 *time = st.st_atime; 308 *time = st.st_atime;
309 break; 309 break;
310 default: 310 default:
311 return false; 311 return false;
312 } 312 }
313 return true; 313 return true;
314 } 314 }
315 315
316 bool UnixFilesystem::GetAppTempFolder(Pathname* path) { 316 bool UnixFilesystem::GetAppTempFolder(Pathname* path) {
317 #if defined(WEBRTC_ANDROID) || defined(WEBRTC_MAC) 317 #if defined(WEBRTC_ANDROID) || defined(WEBRTC_MAC)
318 RTC_DCHECK(provided_app_temp_folder_ != NULL); 318 RTC_DCHECK(provided_app_temp_folder_ != nullptr);
319 path->SetPathname(provided_app_temp_folder_); 319 path->SetPathname(provided_app_temp_folder_);
320 return true; 320 return true;
321 #else 321 #else
322 RTC_DCHECK(!application_name_.empty()); 322 RTC_DCHECK(!application_name_.empty());
323 // TODO: Consider whether we are worried about thread safety. 323 // TODO: Consider whether we are worried about thread safety.
324 if (app_temp_path_ != NULL && strlen(app_temp_path_) > 0) { 324 if (app_temp_path_ != nullptr && strlen(app_temp_path_) > 0) {
325 path->SetPathname(app_temp_path_); 325 path->SetPathname(app_temp_path_);
326 return true; 326 return true;
327 } 327 }
328 328
329 // Create a random directory as /tmp/<appname>-<pid>-<timestamp> 329 // Create a random directory as /tmp/<appname>-<pid>-<timestamp>
330 char buffer[128]; 330 char buffer[128];
331 sprintfn(buffer, arraysize(buffer), "-%d-%d", 331 sprintfn(buffer, arraysize(buffer), "-%d-%d",
332 static_cast<int>(getpid()), 332 static_cast<int>(getpid()),
333 static_cast<int>(time(0))); 333 static_cast<int>(time(0)));
334 std::string folder(application_name_); 334 std::string folder(application_name_);
335 folder.append(buffer); 335 folder.append(buffer);
336 if (!GetTemporaryFolder(*path, true, &folder)) 336 if (!GetTemporaryFolder(*path, true, &folder))
337 return false; 337 return false;
338 338
339 delete [] app_temp_path_; 339 delete [] app_temp_path_;
340 app_temp_path_ = CopyString(path->pathname()); 340 app_temp_path_ = CopyString(path->pathname());
341 // TODO: atexit(DeleteFolderAndContents(app_temp_path_)); 341 // TODO: atexit(DeleteFolderAndContents(app_temp_path_));
342 return true; 342 return true;
343 #endif 343 #endif
344 } 344 }
345 345
346 char* UnixFilesystem::CopyString(const std::string& str) { 346 char* UnixFilesystem::CopyString(const std::string& str) {
347 size_t size = str.length() + 1; 347 size_t size = str.length() + 1;
348 348
349 char* buf = new char[size]; 349 char* buf = new char[size];
350 if (!buf) { 350 if (!buf) {
351 return NULL; 351 return nullptr;
352 } 352 }
353 353
354 strcpyn(buf, size, str.c_str()); 354 strcpyn(buf, size, str.c_str());
355 return buf; 355 return buf;
356 } 356 }
357 357
358 } // namespace rtc 358 } // namespace rtc
359 359
360 #if defined(__native_client__) 360 #if defined(__native_client__)
361 extern "C" int __attribute__((weak)) 361 extern "C" int __attribute__((weak))
362 link(const char* oldpath, const char* newpath) { 362 link(const char* oldpath, const char* newpath) {
363 errno = EACCES; 363 errno = EACCES;
364 return -1; 364 return -1;
365 } 365 }
366 #endif 366 #endif
OLDNEW
« no previous file with comments | « webrtc/base/unixfilesystem.h ('k') | webrtc/base/virtualsocket_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698