gshell: Mention handling of empty argv arrays in the documentation

It is not possible for `g_shell_parse_argv()` to return an empty `argv`
array. Make that clear in the documentation and add some assertions to
encode it explicitly in the code.

Signed-off-by: Philip Withnall <pwithnall@endlessos.org>
This commit is contained in:
Philip Withnall 2022-01-31 14:49:50 +00:00
parent 11654811ef
commit 18fc711355

View File

@ -646,6 +646,11 @@ tokenize_command_line (const gchar *command_line,
*
* Possible errors are those from the %G_SHELL_ERROR domain.
*
* In particular, if @command_line is an empty string (or a string containing
* only whitespace), %G_SHELL_ERROR_EMPTY_STRING will be returned. Its
* guaranteed that @argvp will be a non-empty array if this function returns
* successfully.
*
* Free the returned vector with g_strfreev().
*
* Returns: %TRUE on success, %FALSE if error set
@ -703,6 +708,9 @@ g_shell_parse_argv (const gchar *command_line,
g_slist_free_full (tokens, g_free);
g_assert (argc > 0);
g_assert (argv != NULL && argv[0] != NULL);
if (argcp)
*argcp = argc;