From 9204355b4d2a7dbde41dff262f223a6b7ac674b2 Mon Sep 17 00:00:00 2001 From: Thomas Heijligen Date: Tue, 29 Jan 2019 12:48:01 +0100 Subject: string: move strdup() & strconcat() to lib/string.c Move functions not available in PRE_RAM into seperate file. Makes it easier to share code between rom and ramstage. Change-Id: I0b9833fbf6742d110ee4bfc00cd650f219aebb2c Signed-off-by: Thomas Heijligen Reviewed-on: https://review.coreboot.org/c/31141 Tested-by: build bot (Jenkins) Reviewed-by: Julius Werner --- src/include/string.h | 22 ++-------------------- src/lib/Makefile.inc | 1 + src/lib/string.c | 21 +++++++++++++++++++++ 3 files changed, 24 insertions(+), 20 deletions(-) create mode 100644 src/lib/string.c (limited to 'src') diff --git a/src/include/string.h b/src/include/string.h index 2f6b5f1b68..4a2f5e9ee6 100644 --- a/src/include/string.h +++ b/src/include/string.h @@ -23,6 +23,8 @@ void *memchr(const void *s, int c, size_t n); int snprintf(char *buf, size_t size, const char *fmt, ...); int vsnprintf(char *buf, size_t size, const char *fmt, va_list args); #endif +char *strdup(const char *s); +char *strconcat(const char *s1, const char *s2); // simple string functions @@ -51,26 +53,6 @@ static inline char *strchr(const char *s, int c) return 0; } -#if !defined(__PRE_RAM__) -static inline char *strdup(const char *s) -{ - size_t sz = strlen(s) + 1; - char *d = malloc(sz); - memcpy(d, s, sz); - return d; -} - -static inline char *strconcat(const char *s1, const char *s2) -{ - size_t sz_1 = strlen(s1); - size_t sz_2 = strlen(s2); - char *d = malloc(sz_1 + sz_2 + 1); - memcpy(d, s1, sz_1); - memcpy(d + sz_1, s2, sz_2 + 1); - return d; -} -#endif - /** * Find a character in a string. * diff --git a/src/lib/Makefile.inc b/src/lib/Makefile.inc index 2fd4e4ca0c..68431f9ce5 100644 --- a/src/lib/Makefile.inc +++ b/src/lib/Makefile.inc @@ -118,6 +118,7 @@ ramstage-y += bootmem.c ramstage-y += fmap.c ramstage-y += memchr.c ramstage-y += memcmp.c +ramstage-y += string.c ramstage-y += malloc.c smm-$(CONFIG_SMM_TSEG) += malloc.c ramstage-y += dimm_info_util.c diff --git a/src/lib/string.c b/src/lib/string.c new file mode 100644 index 0000000000..df2fd80849 --- /dev/null +++ b/src/lib/string.c @@ -0,0 +1,21 @@ +#include +#include +#include + +char *strdup(const char *s) +{ + size_t sz = strlen(s) + 1; + char *d = malloc(sz); + memcpy(d, s, sz); + return d; +} + +char *strconcat(const char *s1, const char *s2) +{ + size_t sz_1 = strlen(s1); + size_t sz_2 = strlen(s2); + char *d = malloc(sz_1 + sz_2 + 1); + memcpy(d, s1, sz_1); + memcpy(d + sz_1, s2, sz_2 + 1); + return d; +} -- cgit v1.2.3