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 258 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
269 *file_size = info.size; | 269 *file_size = info.size; |
270 return true; | 270 return true; |
271 } | 271 } |
272 | 272 |
273 bool CloseFile(FILE* file) { | 273 bool CloseFile(FILE* file) { |
274 if (file == NULL) | 274 if (file == NULL) |
275 return true; | 275 return true; |
276 return fclose(file) == 0; | 276 return fclose(file) == 0; |
277 } | 277 } |
278 | 278 |
279 bool ContainsPath(const FilePath &parent, const FilePath& child) { | |
280 FilePath abs_parent = FilePath(parent); | |
281 FilePath abs_child = FilePath(child); | |
282 | |
283 if (!file_util::AbsolutePath(&abs_parent) || | |
284 !file_util::AbsolutePath(&abs_child)) | |
285 return false; | |
286 | |
287 #if defined(OS_WIN) | |
288 // file_util::AbsolutePath() does not flatten case on Windows, so we must do | |
289 // a case-insensitive compare. | |
290 if (!StartsWith(abs_child.value(), abs_parent.value(), false)) | |
291 #else | |
Erik does not do reviews
2009/01/12 17:14:05
#else if defined(OS_POSIX)
| |
292 if (!StartsWithASCII(abs_child.value(), abs_parent.value(), true)) | |
Erik does not do reviews
2009/01/12 17:14:05
Put a comment / TODO / bug in here to reference th
| |
293 #endif | |
294 return false; | |
295 | |
296 // file_util::AbsolutePath() normalizes '/' to '\' on Windows, so we only need | |
297 // to check kSeparators[0]. | |
298 if (abs_child.value().length() <= abs_parent.value().length() || | |
299 abs_child.value()[abs_parent.value().length()] != | |
300 FilePath::kSeparators[0]) | |
301 return false; | |
302 | |
303 return true; | |
304 } | |
305 | |
279 /////////////////////////////////////////////// | 306 /////////////////////////////////////////////// |
280 // MemoryMappedFile | 307 // MemoryMappedFile |
281 | 308 |
282 MemoryMappedFile::~MemoryMappedFile() { | 309 MemoryMappedFile::~MemoryMappedFile() { |
283 CloseHandles(); | 310 CloseHandles(); |
284 } | 311 } |
285 | 312 |
286 bool MemoryMappedFile::Initialize(const FilePath& file_name) { | 313 bool MemoryMappedFile::Initialize(const FilePath& file_name) { |
287 if (IsValid()) | 314 if (IsValid()) |
288 return false; | 315 return false; |
(...skipping 150 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
439 FilePath directory = path.DirName(); | 466 FilePath directory = path.DirName(); |
440 // If there is no separator, we will get back kCurrentDirectory. | 467 // If there is no separator, we will get back kCurrentDirectory. |
441 // In this case, clear dir. | 468 // In this case, clear dir. |
442 if (directory == path || directory.value() == FilePath::kCurrentDirectory) | 469 if (directory == path || directory.value() == FilePath::kCurrentDirectory) |
443 dir->clear(); | 470 dir->clear(); |
444 else | 471 else |
445 *dir = directory.ToWStringHack(); | 472 *dir = directory.ToWStringHack(); |
446 } | 473 } |
447 } // namespace | 474 } // namespace |
448 | 475 |
OLD | NEW |