|
1 /* |
|
2 * Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies). |
|
3 * All rights reserved. |
|
4 * This component and the accompanying materials are made available |
|
5 * under the terms of "Eclipse Public License v1.0" |
|
6 * which accompanies this distribution, and is available |
|
7 * at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
8 * |
|
9 * Initial Contributors: |
|
10 * Nokia Corporation - initial contribution. |
|
11 * |
|
12 * Contributors: |
|
13 * |
|
14 * Description: |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 #include "glibbackend.h" |
|
20 #include <e32std.h> |
|
21 #include <string.h> |
|
22 #include <stdlib.h> |
|
23 |
|
24 extern "C" EXPORT_C char *getProgPath(char *progName) |
|
25 { |
|
26 TText16 iName16[KMaxFileName]; |
|
27 char *progPath; |
|
28 int pathLength; |
|
29 RProcess iProcess; |
|
30 char replacePath[KMaxFileName]; |
|
31 |
|
32 /* replace / with // */ |
|
33 strcpy(replacePath,progName); |
|
34 char *temp = strchr(replacePath,'/'); |
|
35 while (temp) |
|
36 { |
|
37 *temp = '\\'; |
|
38 temp = strchr(replacePath,'/'); |
|
39 } // end while |
|
40 |
|
41 //convert narrow chars to wide chars |
|
42 mbstowcs((wchar_t *)iName16, replacePath, strlen(replacePath)+1); |
|
43 |
|
44 //create TDesC to pass to RProcess.Create() |
|
45 TBuf16<KMaxFileName> iCmdName16(iName16); |
|
46 _LIT(KArg,""); |
|
47 |
|
48 // Check if Create if successful. If not successful |
|
49 // the executable by that name does not exits. Hence, |
|
50 // return NULL. |
|
51 if(iProcess.Create(iCmdName16,KArg)) |
|
52 progPath = NULL; |
|
53 else |
|
54 { |
|
55 // If successful, convert from TDesC to narrow chars and |
|
56 // return. |
|
57 TFileName fileName = iProcess.FileName(); |
|
58 iProcess.Close(); |
|
59 |
|
60 pathLength = fileName.Length(); |
|
61 |
|
62 progPath = (char *)malloc(pathLength + 1); |
|
63 |
|
64 if(progPath == NULL) |
|
65 return NULL; |
|
66 |
|
67 for(int i=0;i < pathLength;i++) |
|
68 { |
|
69 progPath[i] = fileName[i]; |
|
70 } // end for |
|
71 |
|
72 progPath[pathLength] = '\0'; |
|
73 |
|
74 } // end if |
|
75 return progPath; |
|
76 } |
|
77 |