michael@0: // Copyright (c) 2013 The Chromium Authors. All rights reserved. michael@0: // Use of this source code is governed by a BSD-style license that can be michael@0: // found in the LICENSE file. michael@0: michael@0: #ifndef BASE_SCOPED_CLEAR_ERRNO_H_ michael@0: #define BASE_SCOPED_CLEAR_ERRNO_H_ michael@0: michael@0: #include michael@0: michael@0: #include "base/basictypes.h" michael@0: michael@0: namespace base { michael@0: michael@0: // Simple scoper that saves the current value of errno, resets it to 0, and on michael@0: // destruction puts the old value back. michael@0: class ScopedClearErrno { michael@0: public: michael@0: ScopedClearErrno() : old_errno_(errno) { michael@0: errno = 0; michael@0: } michael@0: ~ScopedClearErrno() { michael@0: if (errno == 0) michael@0: errno = old_errno_; michael@0: } michael@0: michael@0: private: michael@0: const int old_errno_; michael@0: michael@0: DISALLOW_COPY_AND_ASSIGN(ScopedClearErrno); michael@0: }; michael@0: michael@0: } // namespace base michael@0: michael@0: #endif // BASE_SCOPED_CLEAR_ERRNO_H_