Skip to content

Commit

Permalink
argv-array: implement argv_array_pushv()
Browse files Browse the repository at this point in the history
When we have a null-terminated array, it would be useful to convert it
or append it to an argv_array for further manipulation.

Implement argv_array_pushv() which will push a null-terminated array of
strings on to an argv_array.

Signed-off-by: Paul Tan <pyokagan@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
  • Loading branch information
Paul Tan authored and Junio C Hamano committed Jun 15, 2015
1 parent ffad85c commit 85b3432
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 0 deletions.
3 changes: 3 additions & 0 deletions Documentation/technical/api-argv-array.txt
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,9 @@ Functions
Format a string and push it onto the end of the array. This is a
convenience wrapper combining `strbuf_addf` and `argv_array_push`.

`argv_array_pushv`::
Push a null-terminated array of strings onto the end of the array.

`argv_array_pop`::
Remove the final element from the array. If there are no
elements in the array, do nothing.
Expand Down
6 changes: 6 additions & 0 deletions argv-array.c
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,12 @@ void argv_array_pushl(struct argv_array *array, ...)
va_end(ap);
}

void argv_array_pushv(struct argv_array *array, const char **argv)
{
for (; *argv; argv++)
argv_array_push(array, *argv);
}

void argv_array_pop(struct argv_array *array)
{
if (!array->argc)
Expand Down
1 change: 1 addition & 0 deletions argv-array.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ __attribute__((format (printf,2,3)))
void argv_array_pushf(struct argv_array *, const char *fmt, ...);
LAST_ARG_MUST_BE_NULL
void argv_array_pushl(struct argv_array *, ...);
void argv_array_pushv(struct argv_array *, const char **);
void argv_array_pop(struct argv_array *);
void argv_array_clear(struct argv_array *);

Expand Down

0 comments on commit 85b3432

Please sign in to comment.