commonlib/bsd: Add strcat() and strncat() functions

An upcoming vboot feature [1] will need strcat() to be defined in
string.h. Therefore, add strcat() and strncat() to commonlib/bsd. Remove
those functions from libpayload.

[1] https://chromium-review.googlesource.com/c/chromiumos/platform/vboot_reference/+/5650810

Change-Id: If02fce0eafb4f6fa01d8bab17d87a32360f4ac83
Signed-off-by: Yu-Ping Wu <yupingso@chromium.org>
Reviewed-on: https://review.coreboot.org/c/coreboot/+/83765
Tested-by: build bot (Jenkins) <no-reply@coreboot.org>
Reviewed-by: Julius Werner <jwerner@chromium.org>
This commit is contained in:
Yu-Ping Wu
2024-08-05 03:58:56 +00:00
committed by Yu-Ping Wu
parent 0dcdc0347c
commit aff734bc42
5 changed files with 99 additions and 42 deletions

View File

@ -152,46 +152,6 @@ char *strcpy(char *d, const char *s)
return strncpy(d, s, strlen(s) + 1);
}
/**
* Concatenates two strings
*
* @param d The destination string.
* @param s The source string.
* @return A pointer to the destination string.
*/
char *strcat(char *d, const char *s)
{
char *p = d + strlen(d);
size_t sl = strlen(s);
for (size_t i = 0; i < sl; i++)
p[i] = s[i];
p[sl] = '\0';
return d;
}
/**
* Concatenates two strings with a maximum length.
*
* @param d The destination string.
* @param s The source string.
* @param n Not more than n characters from s will be appended to d.
* @return A pointer to the destination string.
*/
char *strncat(char *d, const char *s, size_t n)
{
char *p = d + strlen(d);
size_t sl = strlen(s);
size_t max = n > sl ? sl : n;
for (size_t i = 0; i < max; i++)
p[i] = s[i];
p[max] = '\0';
return d;
}
/**
* Concatenates two strings with a maximum length.
*