template <typename Closer>

class unique_fd_impl

Defined at line 61 of file ../../third_party/android/platform/system/libbase/include/android-base/unique_fd.h

Container for a file descriptor that automatically closes the descriptor as

it goes out of scope.

unique_fd ufd(open("/some/path", "r"));

if (ufd.get() == -1) return error;

// Do something useful, possibly including 'return'.

return 0; // Descriptor is closed for you.

See also the Pipe()/Socketpair()/Fdopen()/Fdopendir() functions in this file

that provide interoperability with the libc functions with the same (but

lowercase) names.

unique_fd is also known as ScopedFd/ScopedFD/scoped_fd; mentioned here to help

you find this class if you're searching for one of those names.

unique_fd itself is a specialization of unique_fd_impl with a default closer.

Public Methods

void unique_fd_impl<Closer> ()

Defined at line 63 of file ../../third_party/android/platform/system/libbase/include/android-base/unique_fd.h

void unique_fd_impl<Closer> (int fd)

Defined at line 65 of file ../../third_party/android/platform/system/libbase/include/android-base/unique_fd.h

void ~unique_fd_impl<Closer> ()

Defined at line 66 of file ../../third_party/android/platform/system/libbase/include/android-base/unique_fd.h

void unique_fd_impl<Closer> (const unique_fd_impl<Closer> & )

Defined at line 68 of file ../../third_party/android/platform/system/libbase/include/android-base/unique_fd.h

void operator= (const unique_fd_impl<Closer> & )

Defined at line 69 of file ../../third_party/android/platform/system/libbase/include/android-base/unique_fd.h

void unique_fd_impl<Closer> (unique_fd_impl<Closer> && other)

Defined at line 70 of file ../../third_party/android/platform/system/libbase/include/android-base/unique_fd.h

unique_fd_impl<Closer> & operator= (unique_fd_impl<Closer> && s)

Defined at line 71 of file ../../third_party/android/platform/system/libbase/include/android-base/unique_fd.h

void reset (int new_value)

Defined at line 78 of file ../../third_party/android/platform/system/libbase/include/android-base/unique_fd.h

int get ()

Defined at line 80 of file ../../third_party/android/platform/system/libbase/include/android-base/unique_fd.h

int operator int ()

unique_fd's operator int is dangerous, but we have way too much code that

depends on it, so make this opt-in at first.

Defined at line 85 of file ../../third_party/android/platform/system/libbase/include/android-base/unique_fd.h

bool operator>= (int rhs)

Defined at line 88 of file ../../third_party/android/platform/system/libbase/include/android-base/unique_fd.h

bool operator< (int rhs)

Defined at line 89 of file ../../third_party/android/platform/system/libbase/include/android-base/unique_fd.h

bool operator== (int rhs)

Defined at line 90 of file ../../third_party/android/platform/system/libbase/include/android-base/unique_fd.h

bool operator!= (int rhs)

Defined at line 91 of file ../../third_party/android/platform/system/libbase/include/android-base/unique_fd.h

bool operator== (const unique_fd_impl<Closer> & rhs)

Defined at line 92 of file ../../third_party/android/platform/system/libbase/include/android-base/unique_fd.h

bool operator!= (const unique_fd_impl<Closer> & rhs)

Defined at line 93 of file ../../third_party/android/platform/system/libbase/include/android-base/unique_fd.h

bool operator! ()

Catch bogus error checks (i.e.: "!fd" instead of "fd != -1").

Defined at line 96 of file ../../third_party/android/platform/system/libbase/include/android-base/unique_fd.h

bool ok ()

Defined at line 98 of file ../../third_party/android/platform/system/libbase/include/android-base/unique_fd.h

int release ()

Defined at line 100 of file ../../third_party/android/platform/system/libbase/include/android-base/unique_fd.h