From bc52f6fd0d32e3a4098c106ae41e587187e40117 Mon Sep 17 00:00:00 2001 From: borutr Date: Sat, 12 Apr 2003 16:07:26 +0000 Subject: [PATCH] rewritten getPrefixFromBinPath() git-svn-id: https://sdcc.svn.sourceforge.net/svnroot/sdcc/trunk/sdcc@2511 4a8a32a2-be11-0410-ad9d-d568d2c75423 --- src/SDCCutil.c | 41 ++++++++++++++++++----------------------- src/SDCCutil.h | 9 ++++----- 2 files changed, 22 insertions(+), 28 deletions(-) diff --git a/src/SDCCutil.c b/src/SDCCutil.c index bce624fc..9d77b389 100644 --- a/src/SDCCutil.c +++ b/src/SDCCutil.c @@ -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 diff --git a/src/SDCCutil.h b/src/SDCCutil.h index ad9a1a4c..6ac097d2 100644 --- a/src/SDCCutil.h +++ b/src/SDCCutil.h @@ -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. */ -- 2.39.5