From: Jeff Garzik Date: Thu, 24 Dec 1998 20:31:34 +0000 (+0000) Subject: poptParseArgvString cleanups... X-Git-Tag: GNOME_COMMON_1_2_1~205 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=372db513aef0d814012697cdeec47561dbf25ae6;p=platform%2Fupstream%2Fgnome-common.git poptParseArgvString cleanups... x Added array grow increment constant. Remove unnecessary 'dst' init. Remove unnecessary strcpy(). Make arg 's' and var 'src' const-correct. svn path=/trunk/; revision=543 --- diff --git a/support/ChangeLog b/support/ChangeLog index bf06924..bd1b2ee 100644 --- a/support/ChangeLog +++ b/support/ChangeLog @@ -1,3 +1,11 @@ +1998-12-24 Jeff Garzik + + * poptparse.[ch]: poptParseArgvString cleanups... + Added array grow increment constant. + Remove unnecessary 'dst' init. + Remove unnecessary strcpy(). + Make arg 's' and var 'src' const-correct. + 1998-12-21 Matt Wilson * poptparse.c: fix pointer assignment diff --git a/support/popt-gnome.h b/support/popt-gnome.h index 069cab1..6dc2765 100644 --- a/support/popt-gnome.h +++ b/support/popt-gnome.h @@ -104,7 +104,7 @@ int poptReadConfigFile(poptContext con, char * fn); int poptReadDefaultConfig(poptContext con, int useEnv); /* argv should be freed -- this allows ', ", and \ quoting, but ' is treated the same as " and both may include \ quotes */ -int poptParseArgvString(char * s, int * argcPtr, char *** argvPtr); +int poptParseArgvString(const char * s, int * argcPtr, char *** argvPtr); const char * poptStrerror(const int error); void poptSetExecPath(poptContext con, const char * path, int allowAbsolute); void poptPrintHelp(poptContext con, FILE * f, int flags); diff --git a/support/poptparse.c b/support/poptparse.c index 2e9bc73..b4e1434 100644 --- a/support/poptparse.c +++ b/support/poptparse.c @@ -15,23 +15,25 @@ #include "popt-gnome.h" -int poptParseArgvString(char * s, int * argcPtr, char *** argvPtr) { - char * buf = strcpy(alloca(strlen(s) + 1), s); - char * bufStart = buf; - char * src, * dst; +static const int poptArgvArrayGrowDelta = 5; + +int poptParseArgvString(const char * s, int * argcPtr, char *** argvPtr) { + char * buf, * bufStart, * dst; + const char * src; char quote = '\0'; - int argvAlloced = 5; + int argvAlloced = poptArgvArrayGrowDelta; char ** argv = malloc(sizeof(*argv) * argvAlloced); char ** argv2; int argc = 0; - int i; + int i, buflen; + + buflen = strlen(s) + 1; + bufStart = buf = alloca(buflen); + memset(buf, '\0', buflen); src = s; - dst = buf; argv[argc] = buf; - memset(buf, '\0', strlen(s) + 1); - while (*src) { if (quote == *src) { quote = '\0'; @@ -49,7 +51,7 @@ int poptParseArgvString(char * s, int * argcPtr, char *** argvPtr) { if (*argv[argc]) { buf++, argc++; if (argc == argvAlloced) { - argvAlloced += 5; + argvAlloced += poptArgvArrayGrowDelta; argv = realloc(argv, sizeof(*argv) * argvAlloced); } argv[argc] = buf;