src/Makefile.in, src/SDCCutil.c, support/Util/findme.c,
[fw/sdcc] / src / SDCCutil.c
index c0c317bee6930677988f2e64babfec74885ed5aa..d100aa463d54e407c00ad1f9a1504dc66524d440 100644 (file)
@@ -32,6 +32,9 @@
 #include "SDCCmacro.h"
 #include "SDCCutil.h"
 #include "newalloc.h"
+#ifndef _WIN32
+#include "findme.h"
+#endif
 
 /** Given an array of name, value string pairs creates a new hash
     containing all of the pairs.
@@ -143,18 +146,29 @@ getBinPath(const char *prel)
 char *
 getBinPath(const char *prel)
 {
-  char *p;
-  size_t len;
   static char path[PATH_MAX];
-    
-  if ((p = strrchr(prel, DIR_SEPARATOR_CHAR)) == NULL)
-    return NULL;
+  const char *ret_path;
+
+  if (NULL != (ret_path = findProgramPath(prel))) {
+    char *p;
+    size_t len;
 
-  len = min((sizeof path) - 1, p - prel);
-  strncpy(path, prel, len);
-  path[len] = '\0';
+    if (NULL != (p = strrchr(ret_path, DIR_SEPARATOR_CHAR)) &&
+      PATH_MAX > (len = p - ret_path)) {
+      memcpy(path, ret_path, len);
+      path[len] = '\0';
+      free((void *)ret_path);
 
-  return path;
+      return path;
+    }
+    else {
+      free((void *)ret_path);
+
+      return NULL;
+    }
+  }
+  else
+    return NULL;
 }
 #endif