aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorCasey Dahlin <sadmac@google.com>2015-11-20 19:09:58 +0000
committerGerrit Code Review <noreply-gerritcodereview@google.com>2015-11-20 19:09:58 +0000
commitdc8d6a70b3aa36309cfc2acf6ec4b0de2b373d7b (patch)
treedc102f83a6bafb58bd8c648e25d4205241ffa5f7
parente03de9b80d4a4498a87e51c5a52e34d38181f1f6 (diff)
parentfa20ed61618eb1b4e6101c22dc250e6c664e3c04 (diff)
downloadplatform_libnativehelper-brillo-m8-release.tar.gz
platform_libnativehelper-brillo-m8-release.tar.bz2
platform_libnativehelper-brillo-m8-release.zip
Merge "Improve ScopedFd API"brillo-m8-releasebrillo-m8-dev
-rw-r--r--include/nativehelper/ScopedFd.h9
1 files changed, 8 insertions, 1 deletions
diff --git a/include/nativehelper/ScopedFd.h b/include/nativehelper/ScopedFd.h
index d14e62b..b144aae 100644
--- a/include/nativehelper/ScopedFd.h
+++ b/include/nativehelper/ScopedFd.h
@@ -23,15 +23,22 @@
// A smart pointer that closes the given fd on going out of scope.
// Use this when the fd is incidental to the purpose of your function,
// but needs to be cleaned up on exit.
-class ScopedFd {
+class ScopedFd final {
public:
explicit ScopedFd(int fd) : fd_(fd) {
}
+ ScopedFd() : ScopedFd(-1) {}
~ScopedFd() {
reset();
}
+ ScopedFd(ScopedFd&& other) : fd_(other.release()) {}
+ ScopedFd& operator = (ScopedFd&& s) {
+ reset(s.release());
+ return *this;
+ }
+
int get() const {
return fd_;
}