OLD | NEW |
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 <stdio.h> | 7 #include <stdio.h> |
8 | 8 |
9 #include <fstream> | 9 #include <fstream> |
10 | 10 |
(...skipping 257 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
268 *file_size = info.size; | 268 *file_size = info.size; |
269 return true; | 269 return true; |
270 } | 270 } |
271 | 271 |
272 bool CloseFile(FILE* file) { | 272 bool CloseFile(FILE* file) { |
273 if (file == NULL) | 273 if (file == NULL) |
274 return true; | 274 return true; |
275 return fclose(file) == 0; | 275 return fclose(file) == 0; |
276 } | 276 } |
277 | 277 |
| 278 /////////////////////////////////////////////// |
| 279 // MemoryMappedFile |
| 280 |
| 281 MemoryMappedFile::~MemoryMappedFile() { |
| 282 CloseHandles(); |
| 283 } |
| 284 |
| 285 bool MemoryMappedFile::Initialize(const FilePath& file_name) { |
| 286 if (IsValid()) |
| 287 return false; |
| 288 |
| 289 if (!MapFileToMemory(file_name)) { |
| 290 CloseHandles(); |
| 291 return false; |
| 292 } |
| 293 |
| 294 return true; |
| 295 } |
| 296 |
| 297 bool MemoryMappedFile::IsValid() { |
| 298 return data_ != NULL; |
| 299 } |
| 300 |
278 // Deprecated functions ---------------------------------------------------- | 301 // Deprecated functions ---------------------------------------------------- |
279 | 302 |
280 bool AbsolutePath(std::wstring* path_str) { | 303 bool AbsolutePath(std::wstring* path_str) { |
281 FilePath path(FilePath::FromWStringHack(*path_str)); | 304 FilePath path(FilePath::FromWStringHack(*path_str)); |
282 if (!AbsolutePath(&path)) | 305 if (!AbsolutePath(&path)) |
283 return false; | 306 return false; |
284 *path_str = path.ToWStringHack(); | 307 *path_str = path.ToWStringHack(); |
285 return true; | 308 return true; |
286 } | 309 } |
287 void AppendToPath(std::wstring* path, const std::wstring& new_ending) { | 310 void AppendToPath(std::wstring* path, const std::wstring& new_ending) { |
(...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
390 FilePath directory = path.DirName(); | 413 FilePath directory = path.DirName(); |
391 // If there is no separator, we will get back kCurrentDirectory. | 414 // If there is no separator, we will get back kCurrentDirectory. |
392 // In this case, clear dir. | 415 // In this case, clear dir. |
393 if (directory == path || directory.value() == FilePath::kCurrentDirectory) | 416 if (directory == path || directory.value() == FilePath::kCurrentDirectory) |
394 dir->clear(); | 417 dir->clear(); |
395 else | 418 else |
396 *dir = directory.ToWStringHack(); | 419 *dir = directory.ToWStringHack(); |
397 } | 420 } |
398 } // namespace | 421 } // namespace |
399 | 422 |
OLD | NEW |