| 302 | } |
| 303 | |
| 304 | void* exec(const char* const* _argv) |
| 305 | { |
| 306 | #if BX_PLATFORM_LINUX |
| 307 | pid_t pid = fork(); |
| 308 | |
| 309 | if (0 == pid) |
| 310 | { |
| 311 | int result = execvp(_argv[0], const_cast<char *const*>(&_argv[1]) ); |
| 312 | BX_UNUSED(result); |
| 313 | return NULL; |
| 314 | } |
| 315 | |
| 316 | return (void*)uintptr_t(pid); |
| 317 | #elif BX_PLATFORM_WINDOWS |
| 318 | STARTUPINFOA si; |
| 319 | memSet(&si, 0, sizeof(STARTUPINFOA) ); |
| 320 | si.cb = sizeof(STARTUPINFOA); |
| 321 | |
| 322 | PROCESS_INFORMATION pi; |
| 323 | memSet(&pi, 0, sizeof(PROCESS_INFORMATION) ); |
| 324 | |
| 325 | int32_t total = 0; |
| 326 | for (uint32_t ii = 0; NULL != _argv[ii]; ++ii) |
| 327 | { |
| 328 | total += (int32_t)strLen(_argv[ii]) + 1; |
| 329 | } |
| 330 | |
| 331 | char* temp = (char*)BX_STACK_ALLOC(total); |
| 332 | int32_t len = 0; |
| 333 | for(uint32_t ii = 0; NULL != _argv[ii]; ++ii) |
| 334 | { |
| 335 | len += snprintf(&temp[len], uint32_imax(0, total-len) |
| 336 | , "%s " |
| 337 | , _argv[ii] |
| 338 | ); |
| 339 | } |
| 340 | |
| 341 | bool ok = !!CreateProcessA(_argv[0] |
| 342 | , temp |
| 343 | , NULL |
| 344 | , NULL |
| 345 | , false |
| 346 | , 0 |
| 347 | , NULL |
| 348 | , NULL |
| 349 | , &si |
| 350 | , &pi |
| 351 | ); |
| 352 | if (ok) |
| 353 | { |
| 354 | return pi.hProcess; |
| 355 | } |
| 356 | |
| 357 | return NULL; |
| 358 | #else |
| 359 | BX_UNUSED(_argv); |
| 360 | return NULL; |
| 361 | #endif // BX_PLATFORM_LINUX |