diff options
| author | Casey Dahlin <sadmac@google.com> | 2015-11-20 19:09:58 +0000 |
|---|---|---|
| committer | Gerrit Code Review <noreply-gerritcodereview@google.com> | 2015-11-20 19:09:58 +0000 |
| commit | dc8d6a70b3aa36309cfc2acf6ec4b0de2b373d7b (patch) | |
| tree | dc102f83a6bafb58bd8c648e25d4205241ffa5f7 | |
| parent | e03de9b80d4a4498a87e51c5a52e34d38181f1f6 (diff) | |
| parent | fa20ed61618eb1b4e6101c22dc250e6c664e3c04 (diff) | |
| download | platform_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.h | 9 |
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_; } |
