HV: replace merge_cmdline api with strncat_s

Add a standard string api strncat_s() to replace merge_cmdline() to make code
more readable.

Another change is that the multiboot cmdline will be appended to the end of
configured SOS bootargs instead of the beginning, this would enable a feature
that some kernel cmdline paramter items could be overriden by multiboot cmdline
since the later one would win if same parameters configured in kernel cmdline.

Tracked-On: #4885

Signed-off-by: Victor Sun <victor.sun@intel.com>
Reviewed-by: Yonghua Huang <yonghua.huang@intel.com>
Reviewed-by: Yin Fengwei <fengwei.yin@intel.com>
Acked-by: Eddie Dong <eddie.dong@intel.com>
This commit is contained in:
Victor Sun
2020-05-28 23:18:47 +08:00
committed by wenlingz
parent bad12039c6
commit 47d20f37e1
4 changed files with 73 additions and 69 deletions

View File

@@ -262,3 +262,44 @@ char *strstr_s(const char *str1, size_t maxlen1, const char *str2, size_t maxlen
return (char *)pret;
}
/*
* strncat_s
*
* description:
* append src string to the end of dest string
*
* input:
* dest pointer to the string to be appended.
*
* dmax maximum length of dest buffer including the NULL char.
*
* src pointer to the string that to be concatenated to string dest.
*
* slen maximum characters to append.
*
* return value:
* 0 for success, -1 for failure.
*/
int32_t strncat_s(char *dest, size_t dmax, const char *src, size_t slen)
{
int32_t ret = -1;
size_t len_d, len_s;
char *d = dest, *start;
len_d = strnlen_s(dest, dmax);
len_s = strnlen_s(src, slen);
start = dest + len_d;
if ((dest != NULL) && (src != NULL) && (dmax > (len_d + len_s))
&& ((dest > (src + len_s)) || (src > (dest + len_d)))) {
(void)memcpy_s(start, (dmax - len_d), src, len_s);
*(start + len_s) = '\0';
ret = 0;
} else {
if (dest != NULL) {
*d = '\0'; /* set dest[0] to NULL char on runtime-constraint violation */
}
}
return ret;
}