[M85 Dev][EFL] Fix crashes at webview launch
[platform/framework/web/chromium-efl.git] / base / scoped_clear_last_error.h
1 // Copyright 2018 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.
4
5 #ifndef BASE_SCOPED_CLEAR_LAST_ERROR_H_
6 #define BASE_SCOPED_CLEAR_LAST_ERROR_H_
7
8 #include <errno.h>
9
10 #include "base/base_export.h"
11 #include "base/macros.h"
12 #include "build/build_config.h"
13
14 namespace base {
15
16 // ScopedClearLastError stores and resets the value of thread local error codes
17 // (errno, GetLastError()), and restores them in the destructor. This is useful
18 // to avoid side effects on these values in instrumentation functions that
19 // interact with the OS.
20
21 // Common implementation of ScopedClearLastError for all platforms. Use
22 // ScopedClearLastError instead.
23 class BASE_EXPORT ScopedClearLastErrorBase {
24  public:
25   ScopedClearLastErrorBase() : last_errno_(errno) { errno = 0; }
26   ~ScopedClearLastErrorBase() { errno = last_errno_; }
27
28  private:
29   const int last_errno_;
30
31   DISALLOW_COPY_AND_ASSIGN(ScopedClearLastErrorBase);
32 };
33
34 #if defined(OS_WIN)
35
36 // Windows specific implementation of ScopedClearLastError.
37 class BASE_EXPORT ScopedClearLastError : public ScopedClearLastErrorBase {
38  public:
39   ScopedClearLastError();
40   ~ScopedClearLastError();
41
42  private:
43   const unsigned long last_system_error_;
44
45   DISALLOW_COPY_AND_ASSIGN(ScopedClearLastError);
46 };
47
48 #elif defined(OS_POSIX) || defined(OS_FUCHSIA)
49
50 using ScopedClearLastError = ScopedClearLastErrorBase;
51
52 #endif  // defined(OS_WIN)
53
54 }  // namespace base
55
56 #endif  // BASE_SCOPED_CLEAR_LAST_ERROR_H_