Update contrib.
2 * Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies).
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".
9 * Initial Contributors:
10 * Nokia Corporation - initial contribution.
29 #include "glibbackend.h"
31 #define MAX_COMMAND_LINE_LENGTH 256
36 EXPORT_C int spawnv(int mode,const char * path,const char **argv)
38 TText16 iPath16[KMaxFileName];
39 char replacePath[KMaxFileName];
41 /* replace / with // */
42 strcpy(replacePath,path);
43 char *temp = strchr(replacePath,'/');
47 temp = strchr(replacePath,'/');
50 // convert narrow char to wide char
51 if(mbstowcs((wchar_t *)iPath16, replacePath, strlen(replacePath)+1) == (size_t)(-1))
56 TBuf16<KMaxFileName> iCmdName16;
58 iCmdName16.FillZ(KMaxFileName);
60 iCmdName16.Copy(iPath16);
72 TBuf16<MAX_COMMAND_LINE_LENGTH> iArgv16;
74 iArgv16.FillZ(MAX_COMMAND_LINE_LENGTH);
78 for(i = 0; i < iVal ; i++)
80 TText16 temp[MAX_COMMAND_LINE_LENGTH];
82 if(mbstowcs((wchar_t *)temp, argv[i], strlen(argv[i])+1) == (size_t)(-1))
87 TPtrC16 iTemp(temp,strlen(argv[i]));
89 iArgv16.Append(iTemp);
97 TRequestStatus iStatus;
98 TInt iRetVal = iProcess.Create(iCmdName16,iArgv16);
100 if(iRetVal != KErrNone)
104 case KErrNotFound : errno = ENOENT;
106 case KErrNoMemory : errno = ENOMEM ;
108 case KErrNotSupported : errno = ENOEXEC;
110 case KErrBadName : errno = ENAMETOOLONG;
120 iProcess.Logon(iStatus);
122 User::WaitForRequest(iStatus);
124 return iStatus.Int();
129 return iProcess.Id();
133 EXPORT_C int spawnvp(int mode,const char * path,const char **argv)
135 return spawnv(mode,path,argv);
139 static int ValidateHandle(HANDLE handle)
142 if( iProcess.Open(handle) < 0)
145 THandleInfo handleinfo;
146 iProcess.HandleInfo(&handleinfo);
148 if(handleinfo.iNumOpenInProcess ==0 && handleinfo.iNumOpenInThread == 0 &&
149 handleinfo.iNumProcesses == 0 && handleinfo.iNumThreads == 0)
155 EXPORT_C BOOL CloseHandle(HANDLE handle)
158 if( iProcess.Open(handle) < 0)
161 if(ValidateHandle(handle))
167 EXPORT_C HANDLE GetCurrentProcess()
169 return RProcess().Id();
172 BOOL DuplicateHandle(HANDLE hSourceProcessHandle,HANDLE hSourceHandle,HANDLE hTargetProcessHandle,LPHANDLE lpTargetHandle,DWORD dwDesiredAccess,BOOL bInheritHandle,DWORD dwOptions)
177 EXPORT_C int spawnve(int mode,const char * path,const char **argv,const char **envp)
179 return spawnv(mode,path,argv);
182 EXPORT_C int spawnvpe(int mode,const char * path,const char **argv,const char **envp)
184 return spawnv(mode,path,argv);
188 } /* close extern "C"*/