return result;
}
-char *nullvec2str(char *const vec[])
+/* This function is supposed to accept same data as passed to execve
+ * (argv and envp), which can be arrays of strings as well as NULL
+ * pointer.
+ */
+char* concatenate(char *const vec[])
{
- char command[PATH_MAX] = {0, };
+ size_t length = 0;
+ for (char *const *p = vec; p && *p; p++)
+ length += strlen(*p) + 1;
+
+ if (length == 0)
+ return strdup("");
+
+ char *str = (char *)malloc(length);
+ if (!str)
+ return NULL;
- for (char *const *p = vec; *p; ++p) {
- strncat(command, *p, sizeof(command)-1);
- strncat(command, " ", sizeof(command)-1);
+ char *destp = str;
+ char *const *vecp = vec;
+ while (*vecp) {
+ destp = stpcpy(destp, *(vecp++));
+ if (*vecp)
+ destp = stpcpy(destp, " ");
}
- command[sizeof(command)-1] = 0;
- return strdup(command);
+
+ return str;
}
+
/**
* @}
*/