Silence -Wunused-variable in release builds.
[llvm/stm8.git] / lib / Support / Windows / Windows.h
blob4a1553b599d7530d726fee9e7a8f88d3e56f096c
1 //===- Win32/Win32.h - Common Win32 Include File ----------------*- C++ -*-===//
2 //
3 // The LLVM Compiler Infrastructure
4 //
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9 //
10 // This file defines things specific to Win32 implementations.
12 //===----------------------------------------------------------------------===//
14 //===----------------------------------------------------------------------===//
15 //=== WARNING: Implementation here must contain only generic Win32 code that
16 //=== is guaranteed to work on *all* Win32 variants.
17 //===----------------------------------------------------------------------===//
19 // mingw-w64 tends to define it as 0x0502 in its headers.
20 #undef _WIN32_WINNT
22 // Require at least Windows 2000 API.
23 #define _WIN32_WINNT 0x0500
24 #define _WIN32_IE 0x0500 // MinGW at it again.
25 #define WIN32_LEAN_AND_MEAN
27 #include "llvm/Config/config.h" // Get build system configuration settings
28 #include <windows.h>
29 #include <shlobj.h>
30 #include <cassert>
31 #include <string>
33 inline bool MakeErrMsg(std::string* ErrMsg, const std::string& prefix) {
34 if (!ErrMsg)
35 return true;
36 char *buffer = NULL;
37 FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER|FORMAT_MESSAGE_FROM_SYSTEM,
38 NULL, GetLastError(), 0, (LPSTR)&buffer, 1, NULL);
39 *ErrMsg = prefix + buffer;
40 LocalFree(buffer);
41 return true;
44 class AutoHandle {
45 HANDLE handle;
47 public:
48 AutoHandle(HANDLE h) : handle(h) {}
50 ~AutoHandle() {
51 if (handle)
52 CloseHandle(handle);
55 operator HANDLE() {
56 return handle;
59 AutoHandle &operator=(HANDLE h) {
60 handle = h;
61 return *this;
65 template <class HandleType, uintptr_t InvalidHandle,
66 class DeleterType, DeleterType D>
67 class ScopedHandle {
68 HandleType Handle;
70 public:
71 ScopedHandle() : Handle(InvalidHandle) {}
72 ScopedHandle(HandleType handle) : Handle(handle) {}
74 ~ScopedHandle() {
75 if (Handle != HandleType(InvalidHandle))
76 D(Handle);
79 HandleType take() {
80 HandleType temp = Handle;
81 Handle = HandleType(InvalidHandle);
82 return temp;
85 operator HandleType() const { return Handle; }
87 ScopedHandle &operator=(HandleType handle) {
88 Handle = handle;
89 return *this;
92 typedef void (*unspecified_bool_type)();
93 static void unspecified_bool_true() {}
95 // True if Handle is valid.
96 operator unspecified_bool_type() const {
97 return Handle == HandleType(InvalidHandle) ? 0 : unspecified_bool_true;
100 bool operator!() const {
101 return Handle == HandleType(InvalidHandle);
105 typedef ScopedHandle<HANDLE, uintptr_t(-1),
106 BOOL (WINAPI*)(HANDLE), ::FindClose>
107 ScopedFindHandle;
109 namespace llvm {
110 template <class T>
111 class SmallVectorImpl;
113 template <class T>
114 typename SmallVectorImpl<T>::const_pointer
115 c_str(SmallVectorImpl<T> &str) {
116 str.push_back(0);
117 str.pop_back();
118 return str.data();
120 } // end namespace llvm.