1 /* (C) 1998 Red Hat Software, Inc. -- Licensing details are in the COPYING
2 file accompanying popt source distributions, available from
3 ftp://ftp.redhat.com/pub/code/popt */
7 #define POPT_ARGV_ARRAY_GROW_DELTA 5
9 int poptDupArgv(int argc
, const char **argv
,
10 int * argcPtr
, const char *** argvPtr
)
12 size_t nb
= (argc
+ 1) * sizeof(*argv
);
17 for (i
= 0; i
< argc
; i
++) {
19 return POPT_ERROR_NOARG
;
20 nb
+= strlen(argv
[i
]) + 1;
25 dst
+= (argc
+ 1) * sizeof(*argv
);
27 for (i
= 0; i
< argc
; i
++) {
29 dst
+= strlen(strcpy(dst
, argv
[i
])) + 1;
38 int poptParseArgvString(const char * s
, int * argcPtr
, const char *** argvPtr
)
42 int argvAlloced
= POPT_ARGV_ARRAY_GROW_DELTA
;
43 const char ** argv
= malloc(sizeof(*argv
) * argvAlloced
);
45 int buflen
= strlen(s
) + 1;
46 char *buf0
= calloc(buflen
, 1);
51 for (src
= s
; *src
; src
++) {
60 return POPT_ERROR_BADQUOTE
;
62 if (*src
!= quote
) *buf
++ = '\\';
65 } else if (isspace(*src
)) {
68 if (argc
== argvAlloced
) {
69 argvAlloced
+= POPT_ARGV_ARRAY_GROW_DELTA
;
70 argv
= realloc(argv
, sizeof(*argv
) * argvAlloced
);
74 } else switch (*src
) {
84 return POPT_ERROR_BADQUOTE
;
93 if (strlen(argv
[argc
])) {
97 (void) poptDupArgv(argc
, argv
, argcPtr
, argvPtr
);