fix argv copy

This commit is contained in:
Julien Danjou 2008-02-26 17:52:56 +01:00
parent e5038732ca
commit 7a1208ad8a
1 changed files with 15 additions and 15 deletions

View File

@ -216,16 +216,13 @@ main(int argc, char *argv[])
{ {
char buf[1024]; char buf[1024];
const char *confpath = NULL; 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; fd_set rd;
XEvent ev; XEvent ev;
Display * dpy; Display * dpy;
int shape_event, randr_event_base;
int screen;
int i, cmdlen;
event_handler **handler; event_handler **handler;
struct sockaddr_un *addr; struct sockaddr_un *addr;
int opt;
Client *c; Client *c;
static struct option long_options[] = static struct option long_options[] =
{ {
@ -236,6 +233,19 @@ main(int argc, char *argv[])
{NULL, 0, NULL, 0} {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 */ /* check args */
while((opt = getopt_long(argc, argv, "vhkc:", while((opt = getopt_long(argc, argv, "vhkc:",
long_options, NULL)) != -1) long_options, NULL)) != -1)
@ -265,16 +275,6 @@ main(int argc, char *argv[])
if(!(dpy = XOpenDisplay(NULL))) if(!(dpy = XOpenDisplay(NULL)))
eprint("cannot open display\n"); 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); xfd = ConnectionNumber(dpy);
XSetErrorHandler(xerrorstart); XSetErrorHandler(xerrorstart);