Extract command argv building
This simplifies adb_execute_p().
This commit is contained in:
parent
8ed3328055
commit
680d2cc940
1 changed files with 16 additions and 7 deletions
|
@ -111,19 +111,16 @@ show_adb_err_msg(enum sc_process_result err, const char *const argv[]) {
|
||||||
free(buf);
|
free(buf);
|
||||||
}
|
}
|
||||||
|
|
||||||
static sc_pid
|
static const char **
|
||||||
adb_execute_p(const char *serial, const char *const adb_cmd[],
|
adb_create_argv(const char *serial, const char *const adb_cmd[], size_t len) {
|
||||||
size_t len, sc_pipe *pout) {
|
|
||||||
int i;
|
|
||||||
sc_pid pid;
|
|
||||||
|
|
||||||
const char **argv = malloc((len + 4) * sizeof(*argv));
|
const char **argv = malloc((len + 4) * sizeof(*argv));
|
||||||
if (!argv) {
|
if (!argv) {
|
||||||
LOG_OOM();
|
LOG_OOM();
|
||||||
return SC_PROCESS_NONE;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
argv[0] = get_adb_command();
|
argv[0] = get_adb_command();
|
||||||
|
int i;
|
||||||
if (serial) {
|
if (serial) {
|
||||||
argv[1] = "-s";
|
argv[1] = "-s";
|
||||||
argv[2] = serial;
|
argv[2] = serial;
|
||||||
|
@ -134,6 +131,18 @@ adb_execute_p(const char *serial, const char *const adb_cmd[],
|
||||||
|
|
||||||
memcpy(&argv[i], adb_cmd, len * sizeof(const char *));
|
memcpy(&argv[i], adb_cmd, len * sizeof(const char *));
|
||||||
argv[len + i] = NULL;
|
argv[len + i] = NULL;
|
||||||
|
return argv;
|
||||||
|
}
|
||||||
|
|
||||||
|
static sc_pid
|
||||||
|
adb_execute_p(const char *serial, const char *const adb_cmd[], size_t len,
|
||||||
|
sc_pipe *pout) {
|
||||||
|
const char **argv = adb_create_argv(serial, adb_cmd, len);
|
||||||
|
if (!argv) {
|
||||||
|
return SC_PROCESS_NONE;
|
||||||
|
}
|
||||||
|
|
||||||
|
sc_pid pid;
|
||||||
enum sc_process_result r =
|
enum sc_process_result r =
|
||||||
sc_process_execute_p(argv, &pid, NULL, pout, NULL);
|
sc_process_execute_p(argv, &pid, NULL, pout, NULL);
|
||||||
if (r != SC_PROCESS_SUCCESS) {
|
if (r != SC_PROCESS_SUCCESS) {
|
||||||
|
|
Loading…
Reference in a new issue