class ScopedFindFileHandle {
public:
explicit ScopedFindFileHandle(HANDLE handle) : handle_(handle) {
// Windows is inconsistent about invalid handles, so we always use NULL
if (handle_ == INVALID_HANDLE_VALUE)
handle_ = NULL;
}
~ScopedFindFileHandle() {
if (handle_)
FindClose(handle_);
}
// Use this instead of comparing to INVALID_HANDLE_VALUE to pick up our NULL
// usage for errors.
bool IsValid() const { return handle_ != NULL; }
operator HANDLE() { return handle_; }
private:
HANDLE handle_;
DISALLOW_EVIL_CONSTRUCTORS(ScopedFindFileHandle);
};