LLVM API Documentation
00001 //===- Win32/Win32.h - Common Win32 Include File ----------------*- C++ -*-===// 00002 // 00003 // The LLVM Compiler Infrastructure 00004 // 00005 // This file was developed by Jeff Cohen and is distributed under the 00006 // University of Illinois Open Source License. See LICENSE.TXT for details. 00007 // 00008 //===----------------------------------------------------------------------===// 00009 // 00010 // This file defines things specific to Win32 implementations. 00011 // 00012 //===----------------------------------------------------------------------===// 00013 00014 //===----------------------------------------------------------------------===// 00015 //=== WARNING: Implementation here must contain only generic Win32 code that 00016 //=== is guaranteed to work on *all* Win32 variants. 00017 //===----------------------------------------------------------------------===// 00018 00019 // Require at least Windows 2000 API. 00020 #define _WIN32_WINNT 0x0500 00021 00022 #include "llvm/Config/config.h" // Get autoconf configuration settings 00023 #include "windows.h" 00024 #include <cassert> 00025 #include <string> 00026 00027 inline bool GetError(const std::string &Prefix, std::string *Dest) { 00028 if (Dest == 0) return true; 00029 char *buffer = NULL; 00030 FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER|FORMAT_MESSAGE_FROM_SYSTEM, 00031 NULL, GetLastError(), 0, (LPSTR)&buffer, 1, NULL); 00032 *Dest = Prefix + buffer; 00033 LocalFree(buffer); 00034 return true; 00035 } 00036 00037 inline void ThrowError(const std::string& msg) { 00038 char *buffer = NULL; 00039 FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER|FORMAT_MESSAGE_FROM_SYSTEM, 00040 NULL, GetLastError(), 0, (LPSTR)&buffer, 1, NULL); 00041 std::string s(msg); 00042 s += buffer; 00043 LocalFree(buffer); 00044 throw s; 00045 } 00046 00047 inline void ThrowErrno(const std::string& prefix) { 00048 ThrowError(prefix + ": " + strerror(errno)); 00049 }