aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/vppinfra/format.h3
-rw-r--r--src/vppinfra/unformat.c24
2 files changed, 27 insertions, 0 deletions
diff --git a/src/vppinfra/format.h b/src/vppinfra/format.h
index 935b57f2c4b..7254031a0ea 100644
--- a/src/vppinfra/format.h
+++ b/src/vppinfra/format.h
@@ -304,6 +304,9 @@ unformat_function_t unformat_eof;
/* Parse memory size e.g. 100, 100k, 100m, 100g. */
unformat_function_t unformat_memory_size;
+/* Unformat C string array, takes array length as 2nd argument */
+unformat_function_t unformat_c_string_array;
+
/* Format base 10 e.g. 100, 100K, 100M, 100G */
u8 *format_base10 (u8 *s, va_list *va);
diff --git a/src/vppinfra/unformat.c b/src/vppinfra/unformat.c
index e8e5c28ea8c..a07f4e06df5 100644
--- a/src/vppinfra/unformat.c
+++ b/src/vppinfra/unformat.c
@@ -1086,6 +1086,30 @@ unformat_data_size (unformat_input_t * input, va_list * args)
return 1;
}
+__clib_export uword
+unformat_c_string_array (unformat_input_t *input, va_list *va)
+{
+ char *str = va_arg (*va, char *);
+ u32 array_len = va_arg (*va, u32);
+ uword c, rv = 0;
+ u8 *s = 0;
+
+ if (unformat (input, "%v", &s) == 0)
+ return 0;
+
+ c = vec_len (s);
+
+ if (c > 0 && c < array_len)
+ {
+ clib_memcpy (str, s, c);
+ str[c] = 0;
+ rv = 1;
+ }
+
+ vec_free (s);
+ return rv;
+}
+
#endif /* CLIB_UNIX */