boot: Add strcpy8/16
This commit is contained in:
@@ -98,3 +98,26 @@ int strcasecmp8(const char *s1, const char *s2) {
|
||||
int strcasecmp16(const char16_t *s1, const char16_t *s2) {
|
||||
return strncasecmp16(s1, s2, SIZE_MAX);
|
||||
}
|
||||
|
||||
#define DEFINE_STRCPY(type, name) \
|
||||
type *name(type * restrict dest, const type * restrict src) { \
|
||||
assert(dest); \
|
||||
type *ret = dest; \
|
||||
\
|
||||
if (!src) { \
|
||||
*dest = '\0'; \
|
||||
return ret; \
|
||||
} \
|
||||
\
|
||||
while (*src) { \
|
||||
*dest = *src; \
|
||||
dest++; \
|
||||
src++; \
|
||||
} \
|
||||
\
|
||||
*dest = '\0'; \
|
||||
return ret; \
|
||||
}
|
||||
|
||||
DEFINE_STRCPY(char, strcpy8);
|
||||
DEFINE_STRCPY(char16_t, strcpy16);
|
||||
|
||||
@@ -57,3 +57,6 @@ static inline bool strcaseeq8(const char *s1, const char *s2) {
|
||||
static inline bool strcaseeq16(const char16_t *s1, const char16_t *s2) {
|
||||
return strcasecmp16(s1, s2) == 0;
|
||||
}
|
||||
|
||||
char *strcpy8(char * restrict dest, const char * restrict src);
|
||||
char16_t *strcpy16(char16_t * restrict dest, const char16_t * restrict src);
|
||||
|
||||
@@ -174,4 +174,30 @@ TEST(strncasecmp16) {
|
||||
assert_se(strncasecmp16((char16_t[]){ UINT16_MAX }, (char16_t[]){ 0 }, 1) > 0);
|
||||
}
|
||||
|
||||
TEST(strcpy8) {
|
||||
char buf[128];
|
||||
|
||||
assert_se(strcpy8(buf, "123") == buf);
|
||||
assert_se(streq8(buf, "123"));
|
||||
assert_se(strcpy8(buf, "") == buf);
|
||||
assert_se(streq8(buf, ""));
|
||||
assert_se(strcpy8(buf, "A") == buf);
|
||||
assert_se(streq8(buf, "A"));
|
||||
assert_se(strcpy8(buf, NULL) == buf);
|
||||
assert_se(streq8(buf, ""));
|
||||
}
|
||||
|
||||
TEST(strcpy16) {
|
||||
char16_t buf[128];
|
||||
|
||||
assert_se(strcpy16(buf, u"123") == buf);
|
||||
assert_se(streq16(buf, u"123"));
|
||||
assert_se(strcpy16(buf, u"") == buf);
|
||||
assert_se(streq16(buf, u""));
|
||||
assert_se(strcpy16(buf, u"A") == buf);
|
||||
assert_se(streq16(buf, u"A"));
|
||||
assert_se(strcpy16(buf, NULL) == buf);
|
||||
assert_se(streq16(buf, u""));
|
||||
}
|
||||
|
||||
DEFINE_TEST_MAIN(LOG_INFO);
|
||||
|
||||
Reference in New Issue
Block a user