From 63924059e2cdc4cb711f663fee043275962793a7 Mon Sep 17 00:00:00 2001 From: Doug MacEachern Date: Tue, 3 Aug 2004 03:25:17 +0000 Subject: [PATCH] rid lousy getarg parser in favor of CommandLineToArgvW --- src/os/win32/peb.c | 8 +++-- src/os/win32/sigar_os.h | 3 ++ src/os/win32/win32_sigar.c | 67 +------------------------------------- 3 files changed, 10 insertions(+), 68 deletions(-) diff --git a/src/os/win32/peb.c b/src/os/win32/peb.c index 25bb7135..29844890 100644 --- a/src/os/win32/peb.c +++ b/src/os/win32/peb.c @@ -80,13 +80,17 @@ int sigar_proc_exe_peb_get(sigar_t *sigar, HANDLE proc, return SIGAR_OK; } -static int sigar_parse_proc_args(sigar_t *sigar, WCHAR *buf, - sigar_proc_args_t *procargs) +int sigar_parse_proc_args(sigar_t *sigar, WCHAR *buf, + sigar_proc_args_t *procargs) { char arg[SIGAR_CMDLINE_MAX]; LPWSTR *args; int num, i; + if (!buf) { + buf = GetCommandLine(); + } + sigar_proc_args_create(procargs); args = CommandLineToArgvW(buf, &num); diff --git a/src/os/win32/sigar_os.h b/src/os/win32/sigar_os.h index d3623654..23c3b4ff 100644 --- a/src/os/win32/sigar_os.h +++ b/src/os/win32/sigar_os.h @@ -127,6 +127,9 @@ int sigar_proc_exe_peb_get(sigar_t *sigar, HANDLE proc, int sigar_proc_args_peb_get(sigar_t *sigar, HANDLE proc, sigar_proc_args_t *procargs); +int sigar_parse_proc_args(sigar_t *sigar, WCHAR *buf, + sigar_proc_args_t *procargs); + unsigned int sigar_cpu_count(sigar_t *sigar); int sigar_cpu_info_get(sigar_t *sigar, sigar_cpu_info_t *info); diff --git a/src/os/win32/win32_sigar.c b/src/os/win32/win32_sigar.c index 3713df22..93393813 100644 --- a/src/os/win32/win32_sigar.c +++ b/src/os/win32/win32_sigar.c @@ -760,55 +760,6 @@ static int get_proc_info(sigar_t *sigar, sigar_pid_t pid) return -1; /*XXX*/ } -static char *getarg(char **line) -{ - char *str = *line, *end; - char *res; - int len; - - while (*str && isspace(*str)) { - ++str; - } - - if (!*str) { - *line = str; - return NULL; - } - - if (*str == '"') { - end = str + 1; - - while (*end && (*end != '"')) { - ++end; - } - - len = end - str - 1; - res = malloc(len+1); - memcpy(res, str+1, len); - res[len] = '\0'; - end++; - } - else { - end = str; - while (*end && !isspace(*end)) { - ++end; - } - - len = end - str; - res = malloc(len+1); - memcpy(res, str, len); - res[len] = '\0'; - } - - while (*end && isspace(*end)) { - ++end; - } - - *line = end; - - return res; -} - static int sigar_remote_proc_args_get(sigar_t *sigar, sigar_pid_t pid, sigar_proc_args_t *procargs) { @@ -827,27 +778,11 @@ static int sigar_remote_proc_args_get(sigar_t *sigar, sigar_pid_t pid, return status; } -static int sigar_local_proc_args_get(sigar_t *sigar, sigar_pid_t pid, - sigar_proc_args_t *procargs) -{ - LPTSTR cmdline = GetCommandLine(); - char *arg, *ptr = cmdline; - - sigar_proc_args_create(procargs); - - while (*ptr && (arg = getarg(&ptr))) { - SIGAR_PROC_ARGS_GROW(procargs); - procargs->data[procargs->number++] = arg; - } - - return SIGAR_OK; -} - SIGAR_DECLARE(int) sigar_proc_args_get(sigar_t *sigar, sigar_pid_t pid, sigar_proc_args_t *procargs) { if (pid == sigar->pid) { - return sigar_local_proc_args_get(sigar, pid, procargs); + return sigar_parse_proc_args(sigar, NULL, procargs); } else { return sigar_remote_proc_args_get(sigar, pid, procargs);