From 7a1208ad8a30210a5dc9d8e8011af455b1771174 Mon Sep 17 00:00:00 2001 From: Julien Danjou Date: Tue, 26 Feb 2008 17:52:56 +0100 Subject: [PATCH] fix argv copy --- awesome.c | 30 +++++++++++++++--------------- 1 file changed, 15 insertions(+), 15 deletions(-) diff --git a/awesome.c b/awesome.c index 755646f59..0aadb16f6 100644 --- a/awesome.c +++ b/awesome.c @@ -216,16 +216,13 @@ main(int argc, char *argv[]) { char buf[1024]; const char *confpath = NULL; - int r, xfd, e_dummy, csfd; + int r, xfd, e_dummy, csfd, shape_event, randr_event_base, i, screen, opt; + ssize_t cmdlen = 1; fd_set rd; XEvent ev; Display * dpy; - int shape_event, randr_event_base; - int screen; - int i, cmdlen; event_handler **handler; struct sockaddr_un *addr; - int opt; Client *c; static struct option long_options[] = { @@ -236,6 +233,19 @@ main(int argc, char *argv[]) {NULL, 0, NULL, 0} }; + /* save argv */ + for(i = 0; i < argc; i++) + cmdlen += a_strlen(argv[i]) + 1; + + globalconf.argv = p_new(char, cmdlen); + a_strcpy(globalconf.argv, cmdlen, argv[0]); + + for(i = 1; i < argc; i++) + { + a_strcat(globalconf.argv, cmdlen, " "); + a_strcat(globalconf.argv, cmdlen, argv[i]); + } + /* check args */ while((opt = getopt_long(argc, argv, "vhkc:", long_options, NULL)) != -1) @@ -265,16 +275,6 @@ main(int argc, char *argv[]) if(!(dpy = XOpenDisplay(NULL))) eprint("cannot open display\n"); - for(cmdlen = 0, i = 0; i < argc; i++) - cmdlen += a_strlen(argv[i] + 1); - globalconf.argv = p_new(char, cmdlen); - a_strcpy(globalconf.argv, cmdlen, argv[0]); - for(i = 1; i < argc; i++) - { - a_strcat(globalconf.argv, cmdlen, " "); - a_strcat(globalconf.argv, cmdlen, argv[i]); - } - xfd = ConnectionNumber(dpy); XSetErrorHandler(xerrorstart);