From owner-freebsd-binup Mon Sep 17 19:54:14 2001 Delivered-To: freebsd-binup@freebsd.org Received: from holly.calldei.com (adsl-208-191-154-55.dsl.hstntx.swbell.net [208.191.154.55]) by hub.freebsd.org (Postfix) with ESMTP id 8084737B409 for ; Mon, 17 Sep 2001 19:54:09 -0700 (PDT) Received: (from chris@localhost) by holly.calldei.com (8.11.4/8.9.3) id f8I2rj328246 for freebsd-binup@FreeBSD.ORG; Mon, 17 Sep 2001 21:53:45 -0500 (CDT) (envelope-from chris) Date: Mon, 17 Sep 2001 21:53:45 -0500 From: Chris Costello To: freebsd-binup@FreeBSD.ORG Subject: Re: common/wrappers.c: Updated getArgs(). Message-ID: <20010917215345.D17889@holly.calldei.com> Reply-To: chris@FreeBSD.ORG References: <20010917214616.C17889@holly.calldei.com> Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="Yylu36WmvOXNoKYn" Content-Disposition: inline User-Agent: Mutt/1.2.5i In-Reply-To: <20010917214616.C17889@holly.calldei.com>; from chris@FreeBSD.ORG on Mon, Sep 17, 2001 at 09:46:16PM -0500 Sender: owner-freebsd-binup@FreeBSD.ORG Precedence: bulk List-ID: List-Archive: (Web Archive) List-Help: (List Instructions) List-Subscribe: List-Unsubscribe: X-Loop: FreeBSD.ORG --Yylu36WmvOXNoKYn Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Er, that's an out-of-date diff with a few pieces of useless/ugly cruft (where the code incremented the number of allocated pointers by three, rather than one). A more thought-out patch is attached. -- +-------------------+-----------------------+ | Chris Costello | Old mail has arrived. | | chris@FreeBSD.org | | +-------------------+-----------------------+ --Yylu36WmvOXNoKYn Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename="wrappers.c.diff" --- wrappers.c.orig Mon Sep 17 12:36:26 2001 +++ wrappers.c Mon Sep 17 21:51:39 2001 @@ -42,31 +42,24 @@ * Will return an array with 'arg1', 'arg2', 'arg3', and n will contain '3' */ +#define ALLOC_INCREMENT 1 + char ** -getArgs(char *command, int *n) { - /* XXX evil constant */ -#define MAXARGS 10 - char **args = Malloc(sizeof(char *) * MAXARGS); - int num=0,i; - if (command == NULL) { - *n=num; - return NULL; +getArgs(char *s, int *args) +{ + char **ret; + char *c; + int n, nalloc; + + ret = (char **)malloc((nalloc = ALLOC_INCREMENT) * sizeof(char *)); + + for (c = strtok(s, " \t\n"), n = 0; c; c = strtok(NULL, " \t\n"), n++) { + if (n == nalloc) + ret = realloc(ret, (nalloc += ALLOC_INCREMENT)); + ret[n] = c; } - /* Skip leading whitespace */ - for (i=0;i