aboutsummaryrefslogtreecommitdiff
path: root/include/vsprintf.h
diff options
context:
space:
mode:
authorSimon Glass2023-01-17 10:47:14 -0700
committerTom Rini2023-01-23 18:11:39 -0500
commit3e96ed44e8c5b63bd0cef1e263e7991ac16c21e3 (patch)
treeed9bae7e827fd7b3db39fe675b1c3c541e61e4ba /include/vsprintf.h
parenta0fb9de60d2fe64107ebadc85e73000e84a963ea (diff)
lib: Add a function to split a string into substrings
Some environment variables provide a space-separated list of strings. It is easier to process these when they are broken out into an array of strings. Add a utility function to handle this. Signed-off-by: Simon Glass <sjg@chromium.org>
Diffstat (limited to 'include/vsprintf.h')
-rw-r--r--include/vsprintf.h24
1 files changed, 24 insertions, 0 deletions
diff --git a/include/vsprintf.h b/include/vsprintf.h
index e006af200fd..ed8a060ee17 100644
--- a/include/vsprintf.h
+++ b/include/vsprintf.h
@@ -329,6 +329,30 @@ char *strmhz(char *buf, unsigned long hz);
void str_to_upper(const char *in, char *out, size_t len);
/**
+ * str_to_list() - Convert a string to a list of string pointers
+ *
+ * Splits a string containing space-delimited substrings into a number of
+ * separate strings, e.g. "this is" becomes {"this", "is", NULL}. If @instr is
+ * empty then this returns just {NULL}. The string should have only a single
+ * space between items, with no leading or trailing spaces.
+ *
+ * @instr: String to process (this is alloced by this function)
+ * Returns: List of string pointers, terminated by NULL. Each entry points to
+ * a string. If @instr is empty, the list consists just of a single NULL entry.
+ * Note that the first entry points to the alloced string.
+ * Returns NULL if out of memory
+ */
+const char **str_to_list(const char *instr);
+
+/**
+ * str_free_list() - Free a string list
+ *
+ * @ptr: String list to free, as created by str_to_list(). This can also be
+ * NULL, in which case the function does nothing
+ */
+void str_free_list(const char **ptr);
+
+/**
* vsscanf - Unformat a buffer into a list of arguments
* @inp: input buffer
* @fmt0: format of buffer