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

Side by Side Diff: base/file_util.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.h ('k') | base/file_util_posix.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-2009 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2006-2009 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 #if defined(OS_WIN) 7 #if defined(OS_WIN)
8 #include <io.h> 8 #include <io.h>
9 #endif 9 #endif
10 #include <stdio.h> 10 #include <stdio.h>
(...skipping 170 matching lines...) Expand 10 before | Expand all | Expand 10 after
181 char buf[1 << 16]; 181 char buf[1 << 16];
182 size_t len; 182 size_t len;
183 while ((len = fread(buf, 1, sizeof(buf), file)) > 0) { 183 while ((len = fread(buf, 1, sizeof(buf), file)) > 0) {
184 contents->append(buf, len); 184 contents->append(buf, len);
185 } 185 }
186 CloseFile(file); 186 CloseFile(file);
187 187
188 return true; 188 return true;
189 } 189 }
190 190
191 FILE* CreateAndOpenTemporaryFile(FilePath* path) {
192 FilePath directory;
193 if (!GetTempDir(&directory))
194 return false;
195
196 return CreateAndOpenTemporaryFileInDir(directory, path);
197 }
198
191 bool GetFileSize(const FilePath& file_path, int64* file_size) { 199 bool GetFileSize(const FilePath& file_path, int64* file_size) {
192 FileInfo info; 200 FileInfo info;
193 if (!GetFileInfo(file_path, &info)) 201 if (!GetFileInfo(file_path, &info))
194 return false; 202 return false;
195 *file_size = info.size; 203 *file_size = info.size;
196 return true; 204 return true;
197 } 205 }
198 206
199 bool CloseFile(FILE* file) { 207 bool CloseFile(FILE* file) {
200 if (file == NULL) 208 if (file == NULL)
(...skipping 211 matching lines...) Expand 10 before | Expand all | Expand 10 after
412 // In this case, clear dir. 420 // In this case, clear dir.
413 if (directory == path || directory.value() == FilePath::kCurrentDirectory) 421 if (directory == path || directory.value() == FilePath::kCurrentDirectory)
414 dir->clear(); 422 dir->clear();
415 else 423 else
416 *dir = directory.ToWStringHack(); 424 *dir = directory.ToWStringHack();
417 } 425 }
418 int WriteFile(const std::wstring& filename, const char* data, int size) { 426 int WriteFile(const std::wstring& filename, const char* data, int size) {
419 return WriteFile(FilePath::FromWStringHack(filename), data, size); 427 return WriteFile(FilePath::FromWStringHack(filename), data, size);
420 } 428 }
421 } // namespace 429 } // namespace
OLDNEW
« no previous file with comments | « base/file_util.h ('k') | base/file_util_posix.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698