OLD | NEW |
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 Loading... |
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 Loading... |
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 |
OLD | NEW |