more getting windows to build.
[oota-llvm.git] / lib / System / Win32 / Win32.h
index 7ed10471de15fe7bea08fb7079025ebb157634e5..8f505b1a6cdb496ce83428b69440221388aa9f75 100644 (file)
@@ -2,8 +2,8 @@
 //
 //                     The LLVM Compiler Infrastructure
 //
-// This file was developed by Jeff Cohen and is distributed under the
-// University of Illinois Open Source License. See LICENSE.TXT for details.
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
 //
 //===----------------------------------------------------------------------===//
 //
 #include <cassert>
 #include <string>
 
-inline void ThrowError(const std::string& msg) {
+inline bool MakeErrMsg(std::string* ErrMsg, const std::string& prefix) {
+  if (!ErrMsg)
+    return true;
   char *buffer = NULL;
   FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER|FORMAT_MESSAGE_FROM_SYSTEM,
       NULL, GetLastError(), 0, (LPSTR)&buffer, 1, NULL);
-  std::string s(msg);
-  s += buffer;
+  *ErrMsg = prefix + buffer;
   LocalFree(buffer);
-  throw s;
+  return true;
 }
 
-inline void ThrowErrno(const std::string& prefix) {
-    ThrowError(prefix + ": " + strerror(errno));
-}
+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;
+  }
+};