Factorize Windows command building
Extract command line building to a separate method.
This commit is contained in:
parent
b882322f73
commit
c20245630e
1 changed files with 14 additions and 7 deletions
|
@ -4,20 +4,27 @@
|
||||||
#include "log.h"
|
#include "log.h"
|
||||||
#include "str_util.h"
|
#include "str_util.h"
|
||||||
|
|
||||||
|
static int build_cmd(char *cmd, size_t len, const char *const argv[]) {
|
||||||
|
// Windows command-line parsing is WTF:
|
||||||
|
// <http://daviddeley.com/autohotkey/parameters/parameters.htm#WINPASS>
|
||||||
|
// only make it work for this very specific program
|
||||||
|
// (don't handle escaping nor quotes)
|
||||||
|
size_t ret = xstrjoin(cmd, argv, ' ', len);
|
||||||
|
if (ret >= len) {
|
||||||
|
LOGE("Command too long (%" PRIsizet " chars)", len - 1);
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
enum process_result cmd_execute(const char *path, const char *const argv[], HANDLE *handle) {
|
enum process_result cmd_execute(const char *path, const char *const argv[], HANDLE *handle) {
|
||||||
STARTUPINFO si;
|
STARTUPINFO si;
|
||||||
PROCESS_INFORMATION pi;
|
PROCESS_INFORMATION pi;
|
||||||
memset(&si, 0, sizeof(si));
|
memset(&si, 0, sizeof(si));
|
||||||
si.cb = sizeof(si);
|
si.cb = sizeof(si);
|
||||||
|
|
||||||
// Windows command-line parsing is WTF:
|
|
||||||
// <http://daviddeley.com/autohotkey/parameters/parameters.htm#WINPASS>
|
|
||||||
// only make it work for this very specific program
|
|
||||||
// (don't handle escaping nor quotes)
|
|
||||||
char cmd[256];
|
char cmd[256];
|
||||||
size_t ret = xstrjoin(cmd, argv, ' ', sizeof(cmd));
|
if (build_cmd(cmd, sizeof(cmd), argv)) {
|
||||||
if (ret >= sizeof(cmd)) {
|
|
||||||
LOGE("Command too long (%" PRIsizet " chars)", sizeof(cmd) - 1);
|
|
||||||
*handle = NULL;
|
*handle = NULL;
|
||||||
return PROCESS_ERROR_GENERIC;
|
return PROCESS_ERROR_GENERIC;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue