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 #if defined(OS_WIN) |
| 8 #include <io.h> |
| 9 #endif |
7 #include <stdio.h> | 10 #include <stdio.h> |
8 | 11 |
9 #include <fstream> | 12 #include <fstream> |
10 | 13 |
11 #include "base/file_path.h" | 14 #include "base/file_path.h" |
12 #include "base/logging.h" | 15 #include "base/logging.h" |
13 #include "base/string_util.h" | 16 #include "base/string_util.h" |
14 #include "unicode/uniset.h" | 17 #include "unicode/uniset.h" |
15 | 18 |
16 #include "base/string_piece.h" | 19 #include "base/string_piece.h" |
(...skipping 252 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
269 *file_size = info.size; | 272 *file_size = info.size; |
270 return true; | 273 return true; |
271 } | 274 } |
272 | 275 |
273 bool CloseFile(FILE* file) { | 276 bool CloseFile(FILE* file) { |
274 if (file == NULL) | 277 if (file == NULL) |
275 return true; | 278 return true; |
276 return fclose(file) == 0; | 279 return fclose(file) == 0; |
277 } | 280 } |
278 | 281 |
| 282 bool TruncateFile(FILE* file) { |
| 283 if (file == NULL) |
| 284 return false; |
| 285 long current_offset = ftell(file); |
| 286 if (current_offset == -1) |
| 287 return false; |
| 288 #if defined(OS_WIN) |
| 289 int fd = _fileno(file); |
| 290 if (_chsize(fd, current_offset) != 0) |
| 291 return false; |
| 292 #else |
| 293 int fd = fileno(file); |
| 294 if (ftruncate(fd, current_offset) != 0) |
| 295 return false; |
| 296 #endif |
| 297 return true; |
| 298 } |
| 299 |
279 bool ContainsPath(const FilePath &parent, const FilePath& child) { | 300 bool ContainsPath(const FilePath &parent, const FilePath& child) { |
280 FilePath abs_parent = FilePath(parent); | 301 FilePath abs_parent = FilePath(parent); |
281 FilePath abs_child = FilePath(child); | 302 FilePath abs_child = FilePath(child); |
282 | 303 |
283 if (!file_util::AbsolutePath(&abs_parent) || | 304 if (!file_util::AbsolutePath(&abs_parent) || |
284 !file_util::AbsolutePath(&abs_child)) | 305 !file_util::AbsolutePath(&abs_child)) |
285 return false; | 306 return false; |
286 | 307 |
287 #if defined(OS_WIN) | 308 #if defined(OS_WIN) |
288 // file_util::AbsolutePath() does not flatten case on Windows, so we must do | 309 // 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(); | 487 FilePath directory = path.DirName(); |
467 // If there is no separator, we will get back kCurrentDirectory. | 488 // If there is no separator, we will get back kCurrentDirectory. |
468 // In this case, clear dir. | 489 // In this case, clear dir. |
469 if (directory == path || directory.value() == FilePath::kCurrentDirectory) | 490 if (directory == path || directory.value() == FilePath::kCurrentDirectory) |
470 dir->clear(); | 491 dir->clear(); |
471 else | 492 else |
472 *dir = directory.ToWStringHack(); | 493 *dir = directory.ToWStringHack(); |
473 } | 494 } |
474 } // namespace | 495 } // namespace |
475 | 496 |
OLD | NEW |