blob: 1a797812fb426189b03a814498dd7019c96607b4 [file] [log] [blame]
Junio C Hamano8fb66e52011-10-05 20:59:511argv-array API
2==============
3
4The argv-array API allows one to dynamically build and store
5NULL-terminated lists. An argv-array maintains the invariant that the
6`argv` member always points to a non-NULL array, and that the array is
7always NULL-terminated at the element pointed to by `argv[argc]`. This
8makes the result suitable for passing to functions expecting to receive
9argv from main(), or the link:api-run-command.html[run-command API].
10
11The link:api-string-list.html[string-list API] is similar, but cannot be
12used for these purposes; instead of storing a straight string pointer,
13it contains an item structure with a `util` field that is not compatible
14with the traditional argv interface.
15
16Each `argv_array` manages its own memory. Any strings pushed into the
17array are duplicated, and all memory is freed by argv_array_clear().
18
19Data Structures
20---------------
21
22`struct argv_array`::
23
24A single array. This should be initialized by assignment from
25`ARGV_ARRAY_INIT`, or by calling `argv_array_init`. The `argv`
26member contains the actual array; the `argc` member contains the
27number of elements in the array, not including the terminating
28NULL.
29
30Functions
31---------
32
33`argv_array_init`::
34Initialize an array. This is no different than assigning from
35`ARGV_ARRAY_INIT`.
36
37`argv_array_push`::
38Push a copy of a string onto the end of the array.
39
Junio C Hamano4d61c4a2012-04-30 01:10:2240`argv_array_pushl`::
41Push a list of strings onto the end of the array. The arguments
42should be a list of `const char *` strings, terminated by a NULL
43argument.
44
Junio C Hamano8fb66e52011-10-05 20:59:5145`argv_array_pushf`::
46Format a string and push it onto the end of the array. This is a
47convenience wrapper combining `strbuf_addf` and `argv_array_push`.
48
Junio C Hamano693e7092012-09-12 22:56:5349`argv_array_pop`::
50Remove the final element from the array. If there are no
51elements in the array, do nothing.
52
Junio C Hamano8fb66e52011-10-05 20:59:5153`argv_array_clear`::
54Free all memory associated with the array and return it to the
55initial, empty state.