diff options
author | Yu-Ping Wu <yupingso@chromium.org> | 2024-08-05 03:58:56 +0000 |
---|---|---|
committer | Yu-Ping Wu <yupingso@google.com> | 2024-08-14 03:09:20 +0000 |
commit | aff734bc42b4e132abb5de0e44b0464dd4688590 (patch) | |
tree | 5ed1178030ddd3d660cd5d5304fe95dc009432ff /src | |
parent | 0dcdc0347c8d0405c1c6b444d23483dd9bf31d34 (diff) |
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>
Diffstat (limited to 'src')
-rw-r--r-- | src/commonlib/bsd/include/commonlib/bsd/string.h | 2 | ||||
-rw-r--r-- | src/commonlib/bsd/string.c | 23 |
2 files changed, 25 insertions, 0 deletions
diff --git a/src/commonlib/bsd/include/commonlib/bsd/string.h b/src/commonlib/bsd/include/commonlib/bsd/string.h index 8e8b896e7e..5c97c65cae 100644 --- a/src/commonlib/bsd/include/commonlib/bsd/string.h +++ b/src/commonlib/bsd/include/commonlib/bsd/string.h @@ -8,6 +8,8 @@ size_t strlen(const char *src); size_t strnlen(const char *str, size_t maxlen); +char *strcat(char *dst, const char *src); +char *strncat(char *dst, const char *src, size_t n); unsigned int skip_atoi(char **ptr); diff --git a/src/commonlib/bsd/string.c b/src/commonlib/bsd/string.c index a9dce39e8d..16cd4b5e1d 100644 --- a/src/commonlib/bsd/string.c +++ b/src/commonlib/bsd/string.c @@ -23,6 +23,29 @@ size_t strnlen(const char *str, size_t maxlen) return ptr - str - 1; } +char *strcat(char *dst, const char *src) +{ + char *ptr = dst + strlen(dst); + + while (*src) + *ptr++ = *src++; + + *ptr = '\0'; + return dst; +} + +char *strncat(char *dst, const char *src, size_t n) +{ + char *ptr = dst + strlen(dst); + + /* Not using strncpy() because '\0' may not be appended. */ + while (n-- > 0 && *src) + *ptr++ = *src++; + + *ptr = '\0'; + return dst; +} + unsigned int skip_atoi(char **ptr) { unsigned int result = 0; |