From b635d2a2ac90614a225657020c945c214346fa92 Mon Sep 17 00:00:00 2001 From: Andrew Niefer Date: Wed, 14 Feb 2007 20:23:35 +0000 Subject: bug 173103 --- .../library/eclipseCommon.c | 25 +++++++++++++--------- 1 file changed, 15 insertions(+), 10 deletions(-) (limited to 'bundles/org.eclipse.equinox.executable/library/eclipseCommon.c') diff --git a/bundles/org.eclipse.equinox.executable/library/eclipseCommon.c b/bundles/org.eclipse.equinox.executable/library/eclipseCommon.c index 5458912e8..f0d27d9c8 100644 --- a/bundles/org.eclipse.equinox.executable/library/eclipseCommon.c +++ b/bundles/org.eclipse.equinox.executable/library/eclipseCommon.c @@ -22,6 +22,7 @@ #include #include #endif +#include #include #include @@ -254,19 +255,23 @@ _TCHAR* findFile( _TCHAR* path, _TCHAR* prefix) int count; #endif + path = _tcsdup(path); + pathLength = _tcslen(path); + + /* strip dirSeparators off the end */ + while (path[pathLength - 1] == dirSeparator) { + path[--pathLength] = 0; + } + /* does path exist? */ - if( _tstat(path, &stats) != 0 ) + if( _tstat(path, &stats) != 0 ) { + free(path); return NULL; - - pathLength = _tcslen(path); + } #ifdef _WIN32 fileName = malloc( (_tcslen(path) + 1 + _tcslen(prefix) + 3) * sizeof(_TCHAR)); - fileName = _tcscpy(fileName, path); - fileName[pathLength] = dirSeparator; - fileName[pathLength + 1] = 0; - _tcscat(fileName, prefix); - _tcscat(fileName, _T_ECLIPSE("_*")); + _stprintf(fileName, _T_ECLIPSE("%s%c%s_*"), path, dirSeparator, prefix); prefix = fileName; handle = FindFirstFile(prefix, &data); @@ -299,7 +304,7 @@ _TCHAR* findFile( _TCHAR* path, _TCHAR* prefix) result[pathLength + 1] = 0; _tcscat(result, candidate); free(candidate); - return result; } - return NULL; + free(path); + return result; } -- cgit v1.2.3