summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
author Josh Gao <jmgao@google.com> 2018-08-30 15:22:33 -0700
committer Josh Gao <jmgao@google.com> 2018-08-30 18:25:30 -0700
commit34f83807383de4ef3d41cd6e34d52e08c05e783c (patch)
treebfd2abf6747ff33e623fa7693428742c39a49eb3
parentafeec9fbaaed320536e924d5842d8058d0d75511 (diff)
Clean up FdFile constructors.
Add default values, and switch to delegating constructors where possible. Bug: http://b/113558485 Test: treehugger Change-Id: I7bbc65b7824ae512116223d04dcc182780f13be3
-rw-r--r--libartbase/base/unix_file/fd_file.cc10
-rw-r--r--libartbase/base/unix_file/fd_file.h8
2 files changed, 6 insertions, 12 deletions
diff --git a/libartbase/base/unix_file/fd_file.cc b/libartbase/base/unix_file/fd_file.cc
index 2166cc78a0..9d5c70d688 100644
--- a/libartbase/base/unix_file/fd_file.cc
+++ b/libartbase/base/unix_file/fd_file.cc
@@ -36,13 +36,8 @@
namespace unix_file {
-FdFile::FdFile()
- : guard_state_(GuardState::kClosed), fd_(-1), read_only_mode_(false) {}
-
FdFile::FdFile(int fd, bool check_usage)
- : guard_state_(check_usage ? GuardState::kBase : GuardState::kNoCheck),
- fd_(fd),
- read_only_mode_(false) {}
+ : FdFile(fd, std::string(), check_usage) {}
FdFile::FdFile(int fd, const std::string& path, bool check_usage)
: FdFile(fd, path, check_usage, false) {}
@@ -55,8 +50,7 @@ FdFile::FdFile(int fd, const std::string& path, bool check_usage,
read_only_mode_(read_only_mode) {}
FdFile::FdFile(const std::string& path, int flags, mode_t mode,
- bool check_usage)
- : fd_(-1) {
+ bool check_usage) {
Open(path, flags, mode);
if (!check_usage || !IsOpened()) {
guard_state_ = GuardState::kNoCheck;
diff --git a/libartbase/base/unix_file/fd_file.h b/libartbase/base/unix_file/fd_file.h
index c365ff7e80..54d84c4db3 100644
--- a/libartbase/base/unix_file/fd_file.h
+++ b/libartbase/base/unix_file/fd_file.h
@@ -34,7 +34,7 @@ static constexpr bool kCheckSafeUsage = true;
// Not thread safe.
class FdFile : public RandomAccessFile {
public:
- FdFile();
+ FdFile() = default;
// Creates an FdFile using the given file descriptor.
// Takes ownership of the file descriptor.
FdFile(int fd, bool checkUsage);
@@ -164,7 +164,7 @@ class FdFile : public RandomAccessFile {
}
}
- GuardState guard_state_;
+ GuardState guard_state_ = GuardState::kClosed;
// Opens file 'file_path' using 'flags' and 'mode'.
bool Open(const std::string& file_path, int flags);
@@ -176,9 +176,9 @@ class FdFile : public RandomAccessFile {
void Destroy(); // For ~FdFile and operator=(&&).
- int fd_;
+ int fd_ = -1;
std::string file_path_;
- bool read_only_mode_;
+ bool read_only_mode_ = false;
DISALLOW_COPY_AND_ASSIGN(FdFile);
};