mirror of
https://github.com/bkaradzic/bx.git
synced 2026-02-17 20:52:37 +01:00
Added exec for windows.
This commit is contained in:
@@ -6,6 +6,9 @@
|
||||
#ifndef BX_PROCESS_H_HEADER_GUARD
|
||||
#define BX_PROCESS_H_HEADER_GUARD
|
||||
|
||||
#include "string.h"
|
||||
#include "uint32_t.h"
|
||||
|
||||
#if BX_PLATFORM_LINUX
|
||||
# include <unistd.h>
|
||||
#endif // BX_PLATFORM_LINUX
|
||||
@@ -13,7 +16,7 @@
|
||||
namespace bx
|
||||
{
|
||||
///
|
||||
inline void* exec(const char*const _argv[])
|
||||
inline void* exec(const char* const* _argv)
|
||||
{
|
||||
#if BX_PLATFORM_LINUX
|
||||
pid_t pid = fork();
|
||||
@@ -26,6 +29,47 @@ namespace bx
|
||||
}
|
||||
|
||||
return (void*)uintptr_t(pid);
|
||||
#elif BX_PLATFORM_WINDOWS
|
||||
STARTUPINFO si;
|
||||
memset(&si, 0, sizeof(STARTUPINFO) );
|
||||
si.cb = sizeof(STARTUPINFO);
|
||||
|
||||
PROCESS_INFORMATION pi;
|
||||
memset(&pi, 0, sizeof(PROCESS_INFORMATION) );
|
||||
|
||||
int32_t total = 0;
|
||||
for (uint32_t ii = 0; NULL != _argv[ii]; ++ii)
|
||||
{
|
||||
total += (int32_t)strlen(_argv[ii]) + 1;
|
||||
}
|
||||
|
||||
char* temp = (char*)alloca(total);
|
||||
int32_t len = 0;
|
||||
for(uint32_t ii = 0; NULL != _argv[ii]; ++ii)
|
||||
{
|
||||
len += snprintf(&temp[len], bx::uint32_imax(0, total-len)
|
||||
, "%s "
|
||||
, _argv[ii]
|
||||
);
|
||||
}
|
||||
|
||||
bool ok = CreateProcessA(_argv[0]
|
||||
, temp
|
||||
, NULL
|
||||
, NULL
|
||||
, false
|
||||
, 0
|
||||
, NULL
|
||||
, NULL
|
||||
, &si
|
||||
, &pi
|
||||
);
|
||||
if (ok)
|
||||
{
|
||||
return pi.hProcess;
|
||||
}
|
||||
|
||||
return NULL;
|
||||
#else
|
||||
return NULL;
|
||||
#endif // BX_PLATFORM_LINUX
|
||||
|
||||
Reference in New Issue
Block a user