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 TruncateFile(FILE* file) { |
| 280 if (file == NULL) |
| 281 return false; |
| 282 long current_offset = ftell(file); |
| 283 if (current_offset == -1) |
| 284 return false; |
| 285 #if defined(OS_WIN) |
| 286 int fd = _fileno(file); |
| 287 if (_chsize(fd, current_offset) != 0) |
| 288 return false; |
| 289 #else |
| 290 int fd = fileno(file); |
| 291 if (ftruncate(fd, current_offset) != 0) |
| 292 return false; |
| 293 #endif |
| 294 return true; |
| 295 } |
| 296 |
279 bool ContainsPath(const FilePath &parent, const FilePath& child) { | 297 bool ContainsPath(const FilePath &parent, const FilePath& child) { |
280 FilePath abs_parent = FilePath(parent); | 298 FilePath abs_parent = FilePath(parent); |
281 FilePath abs_child = FilePath(child); | 299 FilePath abs_child = FilePath(child); |
282 | 300 |
283 if (!file_util::AbsolutePath(&abs_parent) || | 301 if (!file_util::AbsolutePath(&abs_parent) || |
284 !file_util::AbsolutePath(&abs_child)) | 302 !file_util::AbsolutePath(&abs_child)) |
285 return false; | 303 return false; |
286 | 304 |
287 #if defined(OS_WIN) | 305 #if defined(OS_WIN) |
288 // file_util::AbsolutePath() does not flatten case on Windows, so we must do | 306 // file_util::AbsolutePath() does not flatten case on Windows, so we must do |
(...skipping 177 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
466 FilePath directory = path.DirName(); | 484 FilePath directory = path.DirName(); |
467 // If there is no separator, we will get back kCurrentDirectory. | 485 // If there is no separator, we will get back kCurrentDirectory. |
468 // In this case, clear dir. | 486 // In this case, clear dir. |
469 if (directory == path || directory.value() == FilePath::kCurrentDirectory) | 487 if (directory == path || directory.value() == FilePath::kCurrentDirectory) |
470 dir->clear(); | 488 dir->clear(); |
471 else | 489 else |
472 *dir = directory.ToWStringHack(); | 490 *dir = directory.ToWStringHack(); |
473 } | 491 } |
474 } // namespace | 492 } // namespace |
475 | 493 |
OLD | NEW |