From fb0fe9b2e9edf4306f4dfa109ec507e326f9fb76 Mon Sep 17 00:00:00 2001 From: borutr Date: Sun, 11 May 2003 13:09:00 +0000 Subject: [PATCH] WIN32 version of getBinPath() calls GetModuleFileName() to determine the path of bin directory, so that PATH is the only env. variable, which has to be set git-svn-id: https://sdcc.svn.sourceforge.net/svnroot/sdcc/trunk/sdcc@2607 4a8a32a2-be11-0410-ad9d-d568d2c75423 --- src/SDCCutil.c | 41 +++++++++++++++++++++++++++++++++-------- 1 file changed, 33 insertions(+), 8 deletions(-) diff --git a/src/SDCCutil.c b/src/SDCCutil.c index 3cd6a0c8..62f15924 100644 --- a/src/SDCCutil.c +++ b/src/SDCCutil.c @@ -22,11 +22,14 @@ what you give them. Help stamp out software-hoarding! -------------------------------------------------------------------------*/ -#include "common.h" +#ifdef _WIN32 +#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. @@ -208,6 +211,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) { @@ -216,11 +245,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); @@ -228,7 +253,7 @@ getBinPath(const char *prel) return path; } - +#endif /** Returns true if the given path exists. */ -- 2.30.2