security/sandbox/chromium/base/scoped_clear_errno.h

Wed, 31 Dec 2014 06:55:50 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:55:50 +0100
changeset 2
7e26c7da4463
permissions
-rw-r--r--

Added tag UPSTREAM_283F7C6 for changeset ca08bd8f51b2

     1 // Copyright (c) 2013 The Chromium Authors. All rights reserved.
     2 // Use of this source code is governed by a BSD-style license that can be
     3 // found in the LICENSE file.
     5 #ifndef BASE_SCOPED_CLEAR_ERRNO_H_
     6 #define BASE_SCOPED_CLEAR_ERRNO_H_
     8 #include <errno.h>
    10 #include "base/basictypes.h"
    12 namespace base {
    14 // Simple scoper that saves the current value of errno, resets it to 0, and on
    15 // destruction puts the old value back.
    16 class ScopedClearErrno {
    17  public:
    18   ScopedClearErrno() : old_errno_(errno) {
    19     errno = 0;
    20   }
    21   ~ScopedClearErrno() {
    22     if (errno == 0)
    23       errno = old_errno_;
    24   }
    26  private:
    27   const int old_errno_;
    29   DISALLOW_COPY_AND_ASSIGN(ScopedClearErrno);
    30 };
    32 }  // namespace base
    34 #endif  // BASE_SCOPED_CLEAR_ERRNO_H_

mercurial