Add a function to prepend a string to the beginning of an argv array - useful when building app_contexts from user input
This commit was SVN r23303.
Этот коммит содержится в:
родитель
c22e6b3613
Коммит
f325ac030a
@ -89,6 +89,40 @@ int opal_argv_append_nosize(char ***argv, const char *arg)
|
||||
return OPAL_SUCCESS;
|
||||
}
|
||||
|
||||
int opal_argv_prepend_nosize(char ***argv, const char *arg)
|
||||
{
|
||||
int argc;
|
||||
int i;
|
||||
|
||||
/* Create new argv. */
|
||||
|
||||
if (NULL == *argv) {
|
||||
*argv = (char**) malloc(2 * sizeof(char *));
|
||||
if (NULL == *argv) {
|
||||
return OPAL_ERR_OUT_OF_RESOURCE;
|
||||
}
|
||||
(*argv)[0] = strdup(arg);
|
||||
(*argv)[1] = NULL;
|
||||
} else {
|
||||
/* count how many entries currently exist */
|
||||
argc = opal_argv_count(*argv);
|
||||
|
||||
*argv = (char**) realloc(*argv, (argc + 2) * sizeof(char *));
|
||||
if (NULL == *argv) {
|
||||
return OPAL_ERR_OUT_OF_RESOURCE;
|
||||
}
|
||||
(*argv)[argc+1] = NULL;
|
||||
|
||||
/* shift all existing elements down 1 */
|
||||
for (i=argc; 0 < i; i--) {
|
||||
(*argv)[i] = (*argv)[i-1];
|
||||
}
|
||||
(*argv)[0] = strdup(arg);
|
||||
}
|
||||
|
||||
return OPAL_SUCCESS;
|
||||
}
|
||||
|
||||
int opal_argv_append_unique_nosize(char ***argv, const char *arg, bool overwrite)
|
||||
{
|
||||
int i;
|
||||
|
@ -85,6 +85,17 @@ OPAL_DECLSPEC int opal_argv_append(int *argc, char ***argv, const char *arg) __
|
||||
*/
|
||||
OPAL_DECLSPEC int opal_argv_append_nosize(char ***argv, const char *arg);
|
||||
|
||||
/**
|
||||
* Insert the provided arg at the beginning of the array
|
||||
*
|
||||
* @param argv Pointer to an argv array
|
||||
* @param str Pointer to the string to prepend
|
||||
*
|
||||
* @retval OPAL_SUCCESS On success
|
||||
* @retval OPAL_ERROR On failure
|
||||
*/
|
||||
OPAL_DECLSPEC int opal_argv_prepend_nosize(char ***argv, const char *arg);
|
||||
|
||||
/**
|
||||
* Append to an argv-style array, but only if the provided argument
|
||||
* doesn't already exist somewhere in the array. Ignore the size of the array.
|
||||
|
Загрузка…
Ссылка в новой задаче
Block a user