Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(214)

Side by Side Diff: base/file_util.h

Issue 183953004: POSIX: CHECK() that file_util::ScopedFD fulfills promise. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « no previous file | base/file_util_unittest.cc » ('j') | base/file_util_unittest.cc » ('J')
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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 // This file contains utility functions for dealing with the local 5 // This file contains utility functions for dealing with the local
6 // filesystem. 6 // filesystem.
7 7
8 #ifndef BASE_FILE_UTIL_H_ 8 #ifndef BASE_FILE_UTIL_H_
9 #define BASE_FILE_UTIL_H_ 9 #define BASE_FILE_UTIL_H_
10 10
(...skipping 398 matching lines...) Expand 10 before | Expand all | Expand 10 after
409 }; 409 };
410 410
411 // Automatically closes |FILE*|s. 411 // Automatically closes |FILE*|s.
412 typedef scoped_ptr<FILE, ScopedFILEClose> ScopedFILE; 412 typedef scoped_ptr<FILE, ScopedFILEClose> ScopedFILE;
413 413
414 #if defined(OS_POSIX) 414 #if defined(OS_POSIX)
415 // Functor for |ScopedFD| (below). 415 // Functor for |ScopedFD| (below).
416 struct ScopedFDClose { 416 struct ScopedFDClose {
417 inline void operator()(int* x) const { 417 inline void operator()(int* x) const {
418 if (x && *x >= 0) { 418 if (x && *x >= 0) {
419 if (IGNORE_EINTR(close(*x)) < 0) 419 // There are security implications to not closing a file descriptor
willchan no longer on Chromium 2014/02/28 01:48:48 If it's not private and doesn't take forever to ex
jln (very slow on Chromium) 2014/02/28 02:01:21 Done. We often have schemes such as: 1. open priv
420 DPLOG(ERROR) << "close"; 420 // properly. It's important to crash here.
421 PCHECK(0 == IGNORE_EINTR(close(*x)));
421 } 422 }
422 } 423 }
423 }; 424 };
424 425
425 // Automatically closes FDs (note: doesn't store the FD). 426 // Automatically closes FDs (note: doesn't store the FD).
426 // TODO(viettrungluu): This is a very odd API, since (unlike |FILE*|s, you'll 427 // TODO(viettrungluu): This is a very odd API, since (unlike |FILE*|s, you'll
427 // need to store the FD separately and keep its memory alive). This should 428 // need to store the FD separately and keep its memory alive). This should
428 // probably be called |ScopedFDCloser| or something like that. 429 // probably be called |ScopedFDCloser| or something like that.
429 typedef scoped_ptr<int, ScopedFDClose> ScopedFD; 430 typedef scoped_ptr<int, ScopedFDClose> ScopedFD;
431 // Let new users use ScopedFDCloser already, while ScopedFD is replaced.
432 typedef ScopedFD ScopedFDCloser;
430 #endif // OS_POSIX 433 #endif // OS_POSIX
431 434
432 #if defined(OS_LINUX) 435 #if defined(OS_LINUX)
433 // Broad categories of file systems as returned by statfs() on Linux. 436 // Broad categories of file systems as returned by statfs() on Linux.
434 enum FileSystemType { 437 enum FileSystemType {
435 FILE_SYSTEM_UNKNOWN, // statfs failed. 438 FILE_SYSTEM_UNKNOWN, // statfs failed.
436 FILE_SYSTEM_0, // statfs.f_type == 0 means unknown, may indicate AFS. 439 FILE_SYSTEM_0, // statfs.f_type == 0 means unknown, may indicate AFS.
437 FILE_SYSTEM_ORDINARY, // on-disk filesystem like ext2 440 FILE_SYSTEM_ORDINARY, // on-disk filesystem like ext2
438 FILE_SYSTEM_NFS, 441 FILE_SYSTEM_NFS,
439 FILE_SYSTEM_SMB, 442 FILE_SYSTEM_SMB,
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
473 // This function simulates Move(), but unlike Move() it works across volumes. 476 // This function simulates Move(), but unlike Move() it works across volumes.
474 // This function is not transactional. 477 // This function is not transactional.
475 BASE_EXPORT bool CopyAndDeleteDirectory(const FilePath& from_path, 478 BASE_EXPORT bool CopyAndDeleteDirectory(const FilePath& from_path,
476 const FilePath& to_path); 479 const FilePath& to_path);
477 #endif // defined(OS_WIN) 480 #endif // defined(OS_WIN)
478 481
479 } // namespace internal 482 } // namespace internal
480 } // namespace base 483 } // namespace base
481 484
482 #endif // BASE_FILE_UTIL_H_ 485 #endif // BASE_FILE_UTIL_H_
OLDNEW
« no previous file with comments | « no previous file | base/file_util_unittest.cc » ('j') | base/file_util_unittest.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698