diff -r 000000000000 -r e4d67989cc36 glib/glibbackend/src/getProgPath.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/glib/glibbackend/src/getProgPath.cpp Tue Feb 02 02:01:42 2010 +0200 @@ -0,0 +1,77 @@ +/* +* Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies). +* All rights reserved. +* This component and the accompanying materials are made available +* under the terms of "Eclipse Public License v1.0" +* which accompanies this distribution, and is available +* at the URL "http://www.eclipse.org/legal/epl-v10.html". +* +* Initial Contributors: +* Nokia Corporation - initial contribution. +* +* Contributors: +* +* Description: +* +*/ + + +#include "glibbackend.h" +#include +#include +#include + +extern "C" EXPORT_C char *getProgPath(char *progName) +{ + TText16 iName16[KMaxFileName]; + char *progPath; + int pathLength; + RProcess iProcess; + char replacePath[KMaxFileName]; + + /* replace / with // */ + strcpy(replacePath,progName); + char *temp = strchr(replacePath,'/'); + while (temp) + { + *temp = '\\'; + temp = strchr(replacePath,'/'); + } // end while + + //convert narrow chars to wide chars + mbstowcs((wchar_t *)iName16, replacePath, strlen(replacePath)+1); + + //create TDesC to pass to RProcess.Create() + TBuf16 iCmdName16(iName16); + _LIT(KArg,""); + + // Check if Create if successful. If not successful + // the executable by that name does not exits. Hence, + // return NULL. + if(iProcess.Create(iCmdName16,KArg)) + progPath = NULL; + else + { + // If successful, convert from TDesC to narrow chars and + // return. + TFileName fileName = iProcess.FileName(); + iProcess.Close(); + + pathLength = fileName.Length(); + + progPath = (char *)malloc(pathLength + 1); + + if(progPath == NULL) + return NULL; + + for(int i=0;i < pathLength;i++) + { + progPath[i] = fileName[i]; + } // end for + + progPath[pathLength] = '\0'; + + } // end if + return progPath; +} +