> Can you see what I'm doing wrong?

It used to work in the past, for sure, and was used in some code over here...

Since it was an ad-hoc thing, the behavior might have changed -- I haven't 
checked it lately.

To make the full disclosure, we reassign the entire __argv here from the linear 
memory
array made up from new argv[] and argc (s_Argc is the original "argc" passed to 
main()),
to make all command line to go into argv[0] for the purposes of "ps" output:

    extern char** __argv;
    extern int    __argc;
    char*  cmdline;
    char** x_argv;
    size_t len;
    int    n;
    for (len = 0, n = 0;  n < argc;  ++n)
        len += strlen(argv[n]) + 1;
    if (!(x_argv = (char**) malloc((s_Argc + 1) * sizeof(*x_argv) + len)))
        return 0/*failure*/;
    x_argv[0] = cmdline = (char*) x_argv + (s_Argc + 1) * sizeof(*x_argv);
    memset(x_argv + 1, 0, s_Argc * sizeof(*x_argv));
    for (n = 0;  n < argc;  ++n) {
        if (n)
            *cmdline++ = ' ';
        len = strlen(argv[n]);
        memcpy(cmdline, argv[n], len);
        cmdline += len;
    }
    *cmdline = '\0';
    __argv = x_argv;
    __argc = 1;

HTH,

Anton Lavrentiev
Contractor NIH/NLM/NCBI

-- 
Problem reports:      https://cygwin.com/problems.html
FAQ:                  https://cygwin.com/faq/
Documentation:        https://cygwin.com/docs.html
Unsubscribe info:     https://cygwin.com/ml/#unsubscribe-simple

Reply via email to