Using the helper API for random number generation.
authorAaron Ballman <aaron@aaronballman.com>
Tue, 11 Feb 2014 03:40:14 +0000 (03:40 +0000)
committerAaron Ballman <aaron@aaronballman.com>
Tue, 11 Feb 2014 03:40:14 +0000 (03:40 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@201125 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Support/Path.cpp
lib/Support/Unix/Path.inc
lib/Support/Windows/Path.inc

index c2b3f1863eab3369bbca5c9b8da0cf8c722e90bd..1872af55ed6b9b40a8202c810707fdef50f2f691 100644 (file)
@@ -15,6 +15,7 @@
 #include "llvm/Support/Endian.h"
 #include "llvm/Support/ErrorHandling.h"
 #include "llvm/Support/FileSystem.h"
+#include "llvm/Support/Process.h"
 #include <cctype>
 #include <cstdio>
 #include <cstring>
index d0b63b5ba5c5805c4de091cfd9f9cb552d08d05a..cda976fdeee38408d96e2831b6eb458add10e5c7 100644 (file)
@@ -17,7 +17,6 @@
 //===----------------------------------------------------------------------===//
 
 #include "Unix.h"
-#include "llvm/Support/Process.h"
 #include <limits.h>
 #include <stdio.h>
 #if HAVE_SYS_STAT_H
index 5a41e49e2561133782a82435dd133cbbbb9e82d6..a431fa048063e69c94eade0890a5f30585ad748e 100644 (file)
@@ -112,25 +112,13 @@ static error_code createUniqueEntity(const Twine &model, int &result_fd,
   // needed if the randomly chosen path already exists.
   SmallVector<wchar_t, 128> random_path_utf16;
 
-  // Get a Crypto Provider for CryptGenRandom.
-  HCRYPTPROV HCPC;
-  if (!::CryptAcquireContextW(&HCPC,
-                              NULL,
-                              NULL,
-                              PROV_RSA_FULL,
-                              CRYPT_VERIFYCONTEXT))
-    return windows_error(::GetLastError());
-  ScopedCryptContext CryptoProvider(HCPC);
-
 retry_random_path:
   random_path_utf16.set_size(0);
   for (SmallVectorImpl<wchar_t>::const_iterator i = model_utf16.begin(),
                                                 e = model_utf16.end();
                                                 i != e; ++i) {
     if (*i == L'%') {
-      BYTE val = 0;
-      if (!::CryptGenRandom(CryptoProvider, 1, &val))
-          return windows_error(::GetLastError());
+      unsigned val = sys::Process::GetRandomNumber();
       random_path_utf16.push_back(L"0123456789abcdef"[val & 15]);
     }
     else