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

Side by Side Diff: base/file_util_win.cc

Issue 83001: ImportantFileWriter (Closed)
Patch Set: share more code Created 11 years, 8 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 | « base/file_util_posix.cc ('k') | chrome/browser/bookmarks/bookmark_utils.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 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "base/file_util.h" 5 #include "base/file_util.h"
6 6
7 #include <windows.h> 7 #include <windows.h>
8 #include <shellapi.h> 8 #include <shellapi.h>
9 #include <shlobj.h> 9 #include <shlobj.h>
10 #include <time.h> 10 #include <time.h>
(...skipping 428 matching lines...) Expand 10 before | Expand all | Expand 10 after
439 return false; 439 return false;
440 440
441 if (CreateTemporaryFileNameInDir(temp_path, &temp_file)) { 441 if (CreateTemporaryFileNameInDir(temp_path, &temp_file)) {
442 *path = FilePath(temp_file); 442 *path = FilePath(temp_file);
443 return true; 443 return true;
444 } 444 }
445 445
446 return false; 446 return false;
447 } 447 }
448 448
449 FILE* CreateAndOpenTemporaryShmemFile(FilePath* path) {
450 return CreateAndOpenTemporaryFile(path);
451 }
452
449 // On POSIX we have semantics to create and open a temporary file 453 // On POSIX we have semantics to create and open a temporary file
450 // atomically. 454 // atomically.
451 // TODO(jrg): is there equivalent call to use on Windows instead of 455 // TODO(jrg): is there equivalent call to use on Windows instead of
452 // going 2-step? 456 // going 2-step?
453 FILE* CreateAndOpenTemporaryFile(FilePath* path) { 457 FILE* CreateAndOpenTemporaryFileInDir(const FilePath& dir, FilePath* path) {
454 458 std::wstring wstring_path;
455 if (!CreateTemporaryFileName(path)) { 459 if (!CreateTemporaryFileNameInDir(dir.value(), &wstring_path)) {
456 return NULL; 460 return NULL;
457 } 461 }
458 return OpenFile(*path, "w+"); 462 *path = FilePath(wstring_path);
459 } 463 // Open file in binary mode, to avoid problems with fwrite. On Windows
460 464 // it replaces \n's with \r\n's, which may surprise you.
461 FILE* CreateAndOpenTemporaryShmemFile(FilePath* path) { 465 // Reference: http://msdn.microsoft.com/en-us/library/h9t88zwz(VS.71).aspx
462 return CreateAndOpenTemporaryFile(path); 466 return OpenFile(*path, "wb+");
463 } 467 }
464 468
465 bool CreateTemporaryFileNameInDir(const std::wstring& dir, 469 bool CreateTemporaryFileNameInDir(const std::wstring& dir,
466 std::wstring* temp_file) { 470 std::wstring* temp_file) {
467 wchar_t temp_name[MAX_PATH + 1]; 471 wchar_t temp_name[MAX_PATH + 1];
468 472
469 if (!GetTempFileName(dir.c_str(), L"", 0, temp_name)) 473 if (!GetTempFileName(dir.c_str(), L"", 0, temp_name))
470 return false; // fail! 474 return false; // fail!
471 475
472 DWORD path_len = GetLongPathName(temp_name, temp_name, MAX_PATH); 476 DWORD path_len = GetLongPathName(temp_name, temp_name, MAX_PATH);
(...skipping 331 matching lines...) Expand 10 before | Expand all | Expand 10 after
804 void PathComponents(const std::wstring& path, 808 void PathComponents(const std::wstring& path,
805 std::vector<std::wstring>* components) { 809 std::vector<std::wstring>* components) {
806 PathComponents(FilePath(path), components); 810 PathComponents(FilePath(path), components);
807 } 811 }
808 void ReplaceExtension(std::wstring* file_name, const std::wstring& extension) { 812 void ReplaceExtension(std::wstring* file_name, const std::wstring& extension) {
809 FilePath path(*file_name); 813 FilePath path(*file_name);
810 ReplaceExtension(&path, extension); 814 ReplaceExtension(&path, extension);
811 file_name->assign(path.value()); 815 file_name->assign(path.value());
812 } 816 }
813 } // namespace file_util 817 } // namespace file_util
OLDNEW
« no previous file with comments | « base/file_util_posix.cc ('k') | chrome/browser/bookmarks/bookmark_utils.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698