Menu

[0a35e6]: / src / rtlib / win32 / sys_execex.c  Maximize  Restore  History

Download this file

103 lines (88 with data), 3.1 kB

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
#include "../fb.h"
#include "fb_private_console.h"
#include <process.h>
FBCALL int fb_ExecEx( FBSTRING *program, FBSTRING *args, int do_fork )
{
char buffer[MAX_PATH+1], *arguments;
int res = 0, got_program;
size_t len_arguments;
#ifndef HOST_MINGW
size_t len_program;
#endif
got_program = (program != NULL) && (program->data != NULL);
if( !got_program ) {
fb_hStrDelTemp( args );
fb_hStrDelTemp( program );
return -1;
}
fb_hGetShortPath( program->data, buffer, MAX_PATH );
#ifdef HOST_MINGW
if( args==NULL ) {
arguments = "";
} else {
len_arguments = FB_STRSIZE( args );
arguments = alloca( len_arguments + 1 );
DBG_ASSERT( arguments!=NULL );
if( len_arguments )
FB_MEMCPY( arguments, args->data, len_arguments );
arguments[len_arguments] = 0;
}
#else
len_program = strlen( buffer );
len_arguments = ( ( args==NULL ) ? 0 : FB_STRSIZE( args ) );
arguments = alloca( len_program + len_arguments + 2 );
DBG_ASSERT( arguments!=NULL );
FB_MEMCPY( arguments, buffer, len_program );
arguments[len_program] = ' ';
if( len_arguments!=0 )
FB_MEMCPY( arguments + len_program + 1, args->data, len_arguments );
arguments[len_program + len_arguments + 1] = 0;
#endif
FB_STRLOCK();
fb_hStrDelTemp_NoLock( args );
fb_hStrDelTemp_NoLock( program );
FB_STRUNLOCK();
FB_CON_CORRECT_POSITION();
{
#ifdef HOST_MINGW
if( do_fork )
res = _spawnl( _P_WAIT, buffer, buffer, arguments, NULL );
else
res = _execl( buffer, buffer, arguments, NULL );
#else
STARTUPINFO StartupInfo;
PROCESS_INFORMATION ProcessInfo;
memset( &StartupInfo, 0, sizeof(StartupInfo) );
StartupInfo.cb = sizeof(StartupInfo);
if( !CreateProcess( NULL, /* application name - correct! */
arguments, /* command line */
NULL, NULL, /* default security descriptors */
FALSE, /* don't inherit handles */
CREATE_DEFAULT_ERROR_MODE, /* do we really need this? */
NULL, /* default environment */
NULL, /* current directory */
&StartupInfo,
&ProcessInfo ) )
{
res = -1;
} else {
/* Release main thread handle - we're not interested in it */
CloseHandle( ProcessInfo.hThread );
if( do_fork ) {
DWORD dwExitCode;
WaitForSingleObject( ProcessInfo.hProcess,
INFINITE );
if( !GetExitCodeProcess( ProcessInfo.hProcess, &dwExitCode ) ) {
res = -1;
} else {
res = (int) dwExitCode;
}
CloseHandle( ProcessInfo.hProcess );
} else {
res = (int) ProcessInfo.hProcess;
}
}
#endif
}
return res;
}
Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.