From: Frank Osterfeld Date: Wed, 29 Apr 2009 16:03:32 +0000 (+0200) Subject: _dbus_get_install_root assumes that dbus-daemon is in a bin/ subdirectory. That's... X-Git-Tag: dbus-1.3.1~191 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=01d2b26bede512bb7c4610e50f81961effce390c;p=platform%2Fupstream%2Fdbus.git _dbus_get_install_root assumes that dbus-daemon is in a bin/ subdirectory. That's not a common directory structure on windows, so weaken the assumption: $somepath/bin/dbus-daemon.exe -> $somepath $somepath/dbus-daemon.exe, where somepath doesn't end in /bin/: -> $somepath i.e., use dbus-daemon.exe's directory as root if that directory is not a "bin" directory (cherry picked from commit 2d2055b2fa7f92c144e9a182a9a091ebe5215d7d) --- diff --git a/dbus/dbus-sysdeps-win.c b/dbus/dbus-sysdeps-win.c index f7d4856..d42d837 100644 --- a/dbus/dbus-sysdeps-win.c +++ b/dbus/dbus-sysdeps-win.c @@ -3242,26 +3242,33 @@ _dbus_get_is_errno_eagain_or_ewouldblock (void) * @returns #FALSE on failure */ dbus_bool_t -_dbus_get_install_root(char *s, int len) -{ - char *p = NULL; - int ret = GetModuleFileName(NULL,s,len); - if ( ret == 0 - || ret == len && GetLastError() == ERROR_INSUFFICIENT_BUFFER) - { - *s = '\0'; - return FALSE; - } - else if ((p = strstr(s,"\\bin\\"))) - { - *(p+1)= '\0'; - return TRUE; +_dbus_get_install_root(char *prefix, int len) +{ + //To find the prefix, we cut the filename and also \bin\ if present + char* p = 0; + int i; + DWORD pathLength; + int lastSlash; + SetLastError( 0 ); + pathLength = GetModuleFileName(NULL, prefix, len); + if ( pathLength == 0 || GetLastError() != 0 ) { + *prefix = '\0'; + return FALSE; } - else - { - *s = '\0'; - return FALSE; + lastSlash = -1; + for (i = 0; i < pathLength; ++i) + if (prefix[i] == '\\') + lastSlash = i; + if (lastSlash == -1) { + *prefix = '\0'; + return FALSE; } + //cut off binary name + prefix[lastSlash+1] = 0; + //cut possible "\\bin" + if (lastSlash > 3 && strncmp(prefix + lastSlash - 4, "\\bin", 4) == 0) + prefix[lastSlash-3] = 0; + return TRUE; } /**