security/sandbox/chromium/base/scoped_clear_errno.h

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/security/sandbox/chromium/base/scoped_clear_errno.h	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,34 @@
     1.4 +// Copyright (c) 2013 The Chromium Authors. All rights reserved.
     1.5 +// Use of this source code is governed by a BSD-style license that can be
     1.6 +// found in the LICENSE file.
     1.7 +
     1.8 +#ifndef BASE_SCOPED_CLEAR_ERRNO_H_
     1.9 +#define BASE_SCOPED_CLEAR_ERRNO_H_
    1.10 +
    1.11 +#include <errno.h>
    1.12 +
    1.13 +#include "base/basictypes.h"
    1.14 +
    1.15 +namespace base {
    1.16 +
    1.17 +// Simple scoper that saves the current value of errno, resets it to 0, and on
    1.18 +// destruction puts the old value back.
    1.19 +class ScopedClearErrno {
    1.20 + public:
    1.21 +  ScopedClearErrno() : old_errno_(errno) {
    1.22 +    errno = 0;
    1.23 +  }
    1.24 +  ~ScopedClearErrno() {
    1.25 +    if (errno == 0)
    1.26 +      errno = old_errno_;
    1.27 +  }
    1.28 +
    1.29 + private:
    1.30 +  const int old_errno_;
    1.31 +
    1.32 +  DISALLOW_COPY_AND_ASSIGN(ScopedClearErrno);
    1.33 +};
    1.34 +
    1.35 +}  // namespace base
    1.36 +
    1.37 +#endif  // BASE_SCOPED_CLEAR_ERRNO_H_

mercurial