Am Samstag, 17. November 2007 12:44 schrieb Martin Preuss: > > Oder als weitere Alternative kann man anstelle > > GetModuleFileName(NULL), welches den Pfad des *executables* zurückgibt, > > auch eher die Kombination > > handle=GetModuleHandle("gwenhywfar") > > GetModuleFileName(handle, p) > > nehmen. Dann wäre man eben nicht darauf angewiesen, wo das aufrufende > > executable liegt (denn das könnte ja entschieden haben, lieber außerhalb > > des gwen-prefixes zu sein). Stattdessen geht es hier um den Pfad zur > > gwenhywfar-DLL, und die ist für ihre share- und locale- und > > plugin-Directories natürlich der bessere Ausgangspunkt. > > [...] > > Ich glaube nicht, dass das praktikabel ist: Das wuerde ja nur fuer Gwen > funktionieren, aber die anderen Projekte - aqbanking und libchipcard - > machen ja auch von addRelPath gebrauch, und die muessten dann ja ihr > eigenes Argument fur GetModuleHandle() verwenden koennen... > > Ich finde die andere Idee, "lib" oder "bin" abzuschneiden, sicherer.
Das Abschneiden finde ich also auch gut und das würde für meine (und gnucash) Zwecke hier ausreichen. Patch unten - ist das okay? Christian --- src/base/pathmanager.c | 19 +++++++++++++++++++ 1 files changed, 19 insertions(+), 0 deletions(-) diff --git a/src/base/pathmanager.c b/src/base/pathmanager.c index 1b9bab5..067ea87 100644 --- a/src/base/pathmanager.c +++ b/src/base/pathmanager.c @@ -227,6 +227,7 @@ int GWEN_PathManager_AddRelPath(const char *callingLib, char *p; GWEN_BUFFER *buf; + /* Get the absolute path to the executable, including its name */ rv=GetModuleFileName(NULL, cwd, sizeof(cwd)-1); if (rv==0) { DBG_ERROR(GWEN_LOGDOMAIN, @@ -235,10 +236,28 @@ int GWEN_PathManager_AddRelPath(const char *callingLib, return GWEN_ERROR_IO; } + /* Find the last DIRSEP and set it to NULL so that we now have the + bindir. */ p=strrchr(cwd, '\\'); if (p) { *p=0; } + + /* Find again the last DIRSEP to check whether the path ends in + "bin" or "lib". */ + p=strrchr(cwd, '\\'); + if (p) { + /* DIRSEP was found and p points to it. p+1 points either to the + rest of the string or the '\0' byte, so we can use it + here. */ + if ((strcmp(p+1, "bin") == 0) || (strcmp(p+1, "lib") == 0)) { + /* The path ends in "bin" or "lib", hence we strip that suffix + so that we now only have the prefix. */ + *p=0; + } + } + + /* And append the given subdirectory to that prefix. */ buf=GWEN_Buffer_new(0, 256, 0, 1); GWEN_Buffer_AppendString(buf, cwd); if (*pathValue!=DIRSEP_C) -- 1.5.3.4.206.g58ba4 ------------------------------------------------------------------------- This SF.net email is sponsored by: Microsoft Defy all challenges. Microsoft(R) Visual Studio 2005. http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/ _______________________________________________ Aqbanking-devel mailing list Aqbanking-devel@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/aqbanking-devel