From 342c513a4ae100354097a9ca99a080eeb7e70c0b Mon Sep 17 00:00:00 2001 From: Junio C Hamano Date: Mon, 21 May 2018 16:54:27 +0200 Subject: argv-array: return the pushed string from argv_push*() MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Such an API change allows us to use an argv_array this way: struct argv_array to_free = ARGV_ARRAY_INIT; const char *msg; if (some condition) { msg = "constant string message"; ... other logic ... } else { msg = argv_array_pushf(&to_free, "format %s", var); } ... use "msg" ... ... do other things ... argv_array_clear(&to_free); Note that argv_array_pushl() and argv_array_pushv() are used to push one or more strings with a single call, so we do not return any one of these strings from these two functions in order to reduce the chance to misuse the API. Signed-off-by: Junio C Hamano Signed-off-by: Martin Ă…gren Signed-off-by: Junio C Hamano --- argv-array.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'argv-array.h') diff --git a/argv-array.h b/argv-array.h index 29056e49a1..715c93b246 100644 --- a/argv-array.h +++ b/argv-array.h @@ -12,9 +12,9 @@ struct argv_array { #define ARGV_ARRAY_INIT { empty_argv, 0, 0 } void argv_array_init(struct argv_array *); -void argv_array_push(struct argv_array *, const char *); +const char *argv_array_push(struct argv_array *, const char *); __attribute__((format (printf,2,3))) -void argv_array_pushf(struct argv_array *, const char *fmt, ...); +const char *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 **); -- cgit v1.2.3