lib/System/Win32/ThreadLocal.inc: Suppress "unused" warning on -Asserts.
[oota-llvm.git] / lib / System / Win32 / Win32.h
index 0180bfabcf072330742a8a239611e305e8dc31ad..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.
 //
 //===----------------------------------------------------------------------===//
 //
@@ -30,11 +30,28 @@ inline bool MakeErrMsg(std::string* ErrMsg, const std::string& prefix) {
   char *buffer = NULL;
   FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER|FORMAT_MESSAGE_FROM_SYSTEM,
       NULL, GetLastError(), 0, (LPSTR)&buffer, 1, NULL);
-  ErrMsg = prefix + buffer;
+  *ErrMsg = prefix + buffer;
   LocalFree(buffer);
   return true;
 }
 
-inline void MakeErrnoMsg(std::string* ErrMsg, const std::string & prefix) {
-  MakeErrorMsg(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;
+  }
+};