rewritten getPrefixFromBinPath()
authorborutr <borutr@4a8a32a2-be11-0410-ad9d-d568d2c75423>
Sat, 12 Apr 2003 16:07:26 +0000 (16:07 +0000)
committerborutr <borutr@4a8a32a2-be11-0410-ad9d-d568d2c75423>
Sat, 12 Apr 2003 16:07:26 +0000 (16:07 +0000)
git-svn-id: https://sdcc.svn.sourceforge.net/svnroot/sdcc/trunk/sdcc@2511 4a8a32a2-be11-0410-ad9d-d568d2c75423

src/SDCCutil.c
src/SDCCutil.h

index bce624fc482104e60254fd3350c728457578620f..9d77b3894e76e25057ce7c820de2ce01781a422a 100644 (file)
@@ -218,39 +218,34 @@ getPathDifference (char *pinto, const char *p1, const char *p2)
   return fixupPath(pinto);
 }
 
+
 /** Given a file with path information in the binary files directory,
-    returns what PREFIX must be to get this path.  Used for discovery
-    of where SDCC is installed.  Returns NULL if the path is
+    returns the directory component. Used for discovery of bin
+    directory of SDCC installation. Returns NULL if the path is
     impossible.
 */
 char *
-getPrefixFromBinPath (const char *prel)
+getBinPath(const char *prel)
 {
-  strncpyz(scratchFileName, prel, PATH_MAX);
-  /* Strip off the /sdcc at the end */
-  *strrchr(scratchFileName, DIR_SEPARATOR_CHAR) = '\0';
-  /* Compute what the difference between the prefix and the bin dir
-     should be. */
-  getPathDifference (buffer, PREFIX, BINDIR);
-
-  /* Verify that the path in has the expected suffix */
-  if (strlen(buffer) > strlen(scratchFileName))
-    {
-      /* Not long enough */
-      return NULL;
-    }
-
-  if (pathEquivalent (buffer, scratchFileName + strlen(scratchFileName) - strlen(buffer)) == FALSE)
-    {
-      /* Doesn't match */
+  char *p;
+  size_t len;
+  static char path[PATH_MAX];
+    
+  if ((p = strrchr(prel, DIR_SEPARATOR_CHAR)) == NULL)
+#ifdef _WIN32
+    /* try *nix dir separator on WIN32 */
+    if ((p = strrchr(prel, UNIX_DIR_SEPARATOR_CHAR)) == NULL)
+#endif
       return NULL;
-    }
 
-  scratchFileName[strlen(scratchFileName) - strlen(buffer)] = '\0';
+  len = min((sizeof path) - 1, p - prel);
+  strncpy(path, prel, len);
+  path[len] = '\0';
 
-  return Safe_strdup (scratchFileName);
+  return path;
 }
 
+
 /** Returns true if the given path exists.
  */
 bool
index ad9a1a4c9e38401ffa555dbf2792f222992d3218..6ac097d2cd018b306b65a18889fa260274329d13 100644 (file)
@@ -57,12 +57,11 @@ char *joinn(char **pplist, int n);
 */
 char *getPathDifference (char *pinto, const char *p1, const char *p2);
 
-/** Given a file with path information in the binary files directory,
-    returns what PREFIX must be to get this path.  Used for discovery
-    of where SDCC is installed.  Returns NULL if the path is
-    impossible.
+/** Given an array of string pointers, returns a string containing all
+    of the strings seperated by spaces.  The returned string is on the
+    heap.  n is the number of strings in the list.
 */
-char *getPrefixFromBinPath (const char *prel);
+char *getBinPath (const char *prel);
 
 /** Returns true if the given path exists.
  */