X-Git-Url: https://git.gag.com/?a=blobdiff_plain;f=src%2FSDCCutil.c;h=134bc2834d2ddf90a43089b4a25e4f874869cd37;hb=df77c7f551357424c7ef05f90fde805117876648;hp=9d77b3894e76e25057ce7c820de2ce01781a422a;hpb=bc52f6fd0d32e3a4098c106ae41e587187e40117;p=fw%2Fsdcc diff --git a/src/SDCCutil.c b/src/SDCCutil.c index 9d77b389..134bc283 100644 --- a/src/SDCCutil.c +++ b/src/SDCCutil.c @@ -22,11 +22,15 @@ what you give them. Help stamp out software-hoarding! -------------------------------------------------------------------------*/ -#include "common.h" +#ifdef _WIN32 +#include +#include +#endif +#include +#include "SDCCglobl.h" #include "SDCCmacro.h" #include "SDCCutil.h" #include "newalloc.h" -#include /** Given an array of name, value string pairs creates a new hash containing all of the pairs. @@ -133,22 +137,6 @@ pathCharsEquivalent(char c1, char c2) #endif } -static bool -pathEquivalent(const char *p1, const char *p2) -{ - while (*p1 != '\0' && *p2 != '\0') - { - if (pathCharsEquivalent (*p1, *p2) == FALSE) - { - break; - } - p1++; - p2++; - } - - return *p1 == *p2; -} - static char pathCharTransform(char c) { @@ -224,6 +212,32 @@ getPathDifference (char *pinto, const char *p1, const char *p2) directory of SDCC installation. Returns NULL if the path is impossible. */ +#ifdef _WIN32 +char * +getBinPath(const char *prel) +{ + char *p; + size_t len; + static char path[PATH_MAX]; + + /* try DOS and *nix dir separator on WIN32 */ + if (NULL != (p = strrchr(prel, DIR_SEPARATOR_CHAR)) || + NULL != (p = strrchr(prel, UNIX_DIR_SEPARATOR_CHAR))) { + len = min((sizeof path) - 1, p - prel); + strncpy(path, prel, len); + path[len] = '\0'; + return path; + } + /* not enough info in prel; do it with module name */ + else if (0 != GetModuleFileName(NULL, path, sizeof path) != 0 && + NULL != (p = strrchr(path, DIR_SEPARATOR_CHAR))) { + *p = '\0'; + return path; + } + else + return NULL; +} +#else char * getBinPath(const char *prel) { @@ -232,11 +246,7 @@ getBinPath(const char *prel) 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; + return NULL; len = min((sizeof path) - 1, p - prel); strncpy(path, prel, len); @@ -244,7 +254,7 @@ getBinPath(const char *prel) return path; } - +#endif /** Returns true if the given path exists. */