This snippet is adapted from here.

#define ARG_MAX 2048
int xargc;
char **xargv;


void parse_command_line()
{


    int cnt, trace, argl;
    FILE *args, *config;
    char **argv, *f;
    char cmdline[ARG_MAX];

    xargc = 0;
    argv = (char **) malloc (sizeof (char *) * cnt);
    
    if(args = fopen("/proc/self/cmdline", "r"))
    {
        argl = fread(cmdline, sizeof(char), ARG_MAX, args);
    }
    else
    {
        fprintf(stderr, "debug: couldnt read cmdline, return.\n");
        return;
    }
    fclose (args);


    fprintf (stderr, "debug: cmdline starts with %s (%i bytes total (including delimeters))\n", cmdline, argl);
    

    /* tokenize cmdline and append to **argv */
    for (f = (char *) &cmdline; f < cmdline+argl;)
    {
        fprintf (stderr, "debug: \targv[%i] is %s (%i bytes)\n", cnt, f, strlen (f));
        
        argv = (char **) realloc (argv, sizeof (char *) * (cnt + 1));
        argv[cnt] = (char *) malloc (strlen (f) + 1);
        strcpy (argv[cnt++], f);
        f += strlen (f)+1;
        ++xargc;
    }
    argv[cnt] = NULL;
    xargv = argv;
}

Valid XHTML 1.0 Strict