From cca32fa9d1a5be17edf096ea7533177a6e1c6de3 Mon Sep 17 00:00:00 2001
From: Nehal J Wani <nehaljw.kkd1@gmail.com>
Date: Sun, 3 Dec 2017 18:01:56 +0000
Subject: [PATCH] Make load_lib() CONDA_PREFIX aware

---
 lib/Cryptodome/Util/_raw_api.py | 13 ++++++++++++-
 1 file changed, 12 insertions(+), 1 deletion(-)

diff --git a/lib/Cryptodome/Util/_raw_api.py b/lib/Cryptodome/Util/_raw_api.py
index 9b3bad8..412839f 100644
--- a/lib/Cryptodome/Util/_raw_api.py
+++ b/lib/Cryptodome/Util/_raw_api.py
@@ -28,6 +28,7 @@
 # POSSIBILITY OF SUCH DAMAGE.
 # ===================================================================
 
+import os
 import abc
 import sys
 from Cryptodome.Util.py3compat import byte_string
@@ -164,7 +165,17 @@ except ImportError:
         import platform
         bits, linkage = platform.architecture()
         if "." not in name and not linkage.startswith("Win"):
-            full_name = find_library(name)
+            _name = name
+            if 'lib' not in _name:
+                _name = 'lib' + _name
+            if sys.platform == 'darwin':
+                _name += '.dylib'
+            elif sys.platform.startswith('linux'):
+                _name += '.so'
+            full_name = os.path.join(os.environ['CONDA_PREFIX'], 'lib', _name)
+            # If not found in $CONDA_PREFIX/lib, find it via ctypes.util
+            if not os.path.isfile(full_name):
+                full_name = find_library(name)
             if full_name is None:
                 raise OSError("Cannot load library '%s'" % name)
             name = full_name
-- 
2.19.1

