2004-09-15 05:48:11 +00:00
|
|
|
//===- Win32/Win32.h - Common Win32 Include File ----------------*- C++ -*-===//
|
2005-04-21 22:55:34 +00:00
|
|
|
//
|
2004-09-15 05:48:11 +00:00
|
|
|
// The LLVM Compiler Infrastructure
|
|
|
|
//
|
2007-12-29 20:36:04 +00:00
|
|
|
// This file is distributed under the University of Illinois Open Source
|
|
|
|
// License. See LICENSE.TXT for details.
|
2005-04-21 22:55:34 +00:00
|
|
|
//
|
2004-09-15 05:48:11 +00:00
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
//
|
2005-07-13 02:15:18 +00:00
|
|
|
// This file defines things specific to Win32 implementations.
|
2004-09-15 05:48:11 +00:00
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
//===----------------------------------------------------------------------===//
|
2005-07-13 02:15:18 +00:00
|
|
|
//=== WARNING: Implementation here must contain only generic Win32 code that
|
|
|
|
//=== is guaranteed to work on *all* Win32 variants.
|
2004-09-15 05:48:11 +00:00
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
2011-02-09 04:18:30 +00:00
|
|
|
// mingw-w64 tends to define it as 0x0502 in its headers.
|
|
|
|
#undef _WIN32_WINNT
|
|
|
|
|
2005-07-13 02:15:18 +00:00
|
|
|
// Require at least Windows 2000 API.
|
|
|
|
#define _WIN32_WINNT 0x0500
|
2010-11-09 15:11:19 +00:00
|
|
|
#define _WIN32_IE 0x0500 // MinGW at it again.
|
2010-11-09 15:11:07 +00:00
|
|
|
#define WIN32_LEAN_AND_MEAN
|
2005-07-13 02:15:18 +00:00
|
|
|
|
2010-11-09 15:10:29 +00:00
|
|
|
#include "llvm/Config/config.h" // Get build system configuration settings
|
2011-02-04 12:53:04 +00:00
|
|
|
#include <windows.h>
|
|
|
|
#include <shlobj.h>
|
2004-09-15 05:48:11 +00:00
|
|
|
#include <cassert>
|
|
|
|
#include <string>
|
|
|
|
|
2006-08-23 07:30:48 +00:00
|
|
|
inline bool MakeErrMsg(std::string* ErrMsg, const std::string& prefix) {
|
2006-08-21 06:02:44 +00:00
|
|
|
if (!ErrMsg)
|
2006-08-23 07:30:48 +00:00
|
|
|
return true;
|
2006-08-21 06:02:44 +00:00
|
|
|
char *buffer = NULL;
|
|
|
|
FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER|FORMAT_MESSAGE_FROM_SYSTEM,
|
|
|
|
NULL, GetLastError(), 0, (LPSTR)&buffer, 1, NULL);
|
2006-09-01 20:35:17 +00:00
|
|
|
*ErrMsg = prefix + buffer;
|
2006-08-21 06:02:44 +00:00
|
|
|
LocalFree(buffer);
|
2006-08-23 07:30:48 +00:00
|
|
|
return true;
|
2006-08-21 06:02:44 +00:00
|
|
|
}
|
2007-03-05 05:22:08 +00:00
|
|
|
|
|
|
|
class AutoHandle {
|
|
|
|
HANDLE handle;
|
|
|
|
|
|
|
|
public:
|
|
|
|
AutoHandle(HANDLE h) : handle(h) {}
|
|
|
|
|
|
|
|
~AutoHandle() {
|
|
|
|
if (handle)
|
|
|
|
CloseHandle(handle);
|
|
|
|
}
|
|
|
|
|
|
|
|
operator HANDLE() {
|
|
|
|
return handle;
|
|
|
|
}
|
|
|
|
|
|
|
|
AutoHandle &operator=(HANDLE h) {
|
|
|
|
handle = h;
|
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
};
|
2010-12-06 04:28:13 +00:00
|
|
|
|
2010-12-06 06:02:07 +00:00
|
|
|
template <class HandleType, uintptr_t InvalidHandle,
|
2010-12-06 04:28:13 +00:00
|
|
|
class DeleterType, DeleterType D>
|
|
|
|
class ScopedHandle {
|
|
|
|
HandleType Handle;
|
|
|
|
|
|
|
|
public:
|
|
|
|
ScopedHandle() : Handle(InvalidHandle) {}
|
|
|
|
ScopedHandle(HandleType handle) : Handle(handle) {}
|
|
|
|
|
|
|
|
~ScopedHandle() {
|
2010-12-06 06:02:07 +00:00
|
|
|
if (Handle != HandleType(InvalidHandle))
|
2010-12-06 04:28:13 +00:00
|
|
|
D(Handle);
|
|
|
|
}
|
|
|
|
|
|
|
|
HandleType take() {
|
|
|
|
HandleType temp = Handle;
|
2010-12-06 06:02:07 +00:00
|
|
|
Handle = HandleType(InvalidHandle);
|
2010-12-06 04:28:13 +00:00
|
|
|
return temp;
|
|
|
|
}
|
|
|
|
|
|
|
|
operator HandleType() const { return Handle; }
|
|
|
|
|
|
|
|
ScopedHandle &operator=(HandleType handle) {
|
|
|
|
Handle = handle;
|
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
|
|
|
|
typedef void (*unspecified_bool_type)();
|
|
|
|
static void unspecified_bool_true() {}
|
|
|
|
|
|
|
|
// True if Handle is valid.
|
|
|
|
operator unspecified_bool_type() const {
|
2010-12-06 06:02:07 +00:00
|
|
|
return Handle == HandleType(InvalidHandle) ? 0 : unspecified_bool_true;
|
2010-12-06 04:28:13 +00:00
|
|
|
}
|
|
|
|
|
2010-12-06 04:28:42 +00:00
|
|
|
bool operator!() const {
|
2010-12-06 06:02:07 +00:00
|
|
|
return Handle == HandleType(InvalidHandle);
|
2010-12-06 04:28:42 +00:00
|
|
|
}
|
2010-12-06 04:28:13 +00:00
|
|
|
};
|
2010-12-06 04:28:42 +00:00
|
|
|
|
2010-12-06 06:02:07 +00:00
|
|
|
typedef ScopedHandle<HANDLE, uintptr_t(-1),
|
2010-12-06 04:28:42 +00:00
|
|
|
BOOL (WINAPI*)(HANDLE), ::FindClose>
|
|
|
|
ScopedFindHandle;
|
2010-12-09 17:37:18 +00:00
|
|
|
|
|
|
|
namespace llvm {
|
|
|
|
template <class T>
|
|
|
|
class SmallVectorImpl;
|
|
|
|
|
|
|
|
template <class T>
|
|
|
|
typename SmallVectorImpl<T>::const_pointer
|
|
|
|
c_str(SmallVectorImpl<T> &str) {
|
|
|
|
str.push_back(0);
|
|
|
|
str.pop_back();
|
|
|
|
return str.data();
|
|
|
|
}
|
|
|
|
} // end namespace llvm.
|